머신러닝
명목형 변수를 이진형 변수로 바꾸기
낑깡H
2022. 10. 23. 16:30
# 가변수 생성
dummy_p = np.repeat(0,nCar)
dummy_d = np.repeat(0,nCar)
dummy_c = np.repeat(0,nCar)
# 연료타입에 대한 위치 인덱스를 저장
p_idx = np.array(corolla.Fuel_Type == "Petrol")
d_idx = np.array(corolla.Fuel_Type == "Diesel")
c_idx = np.array(corolla.Fuel_Type == "CNG")
'''
1. corolla.Fuel_Type == "CNG"
2. np.array(corolla.Fuel_Type == "CNG")
3. c_idx = np.array(corolla.Fuel_Type == "CNG")
순으로 하면 실수 줄임 '''
# 인덱스 슬라이싱 후 (binary = 1) 대입
dummy_p[p_idx] = 1 # Petrol
dummy_d[d_idx] = 1 # Diesel
dummy_c[c_idx] = 1 # CNG
이후 기존 명목 변수 삭제, 새로운 변수 추가 등 추가 작업