6회 작업형2 라벨인코딩
455
작성자 없음
학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
질문과 관련된 영상 위치를 알려주면 더 빠르게 답변할 수 있어요
먼저 유사한 질문이 있었는지 검색해보세요
원핫인코딩 말고 라벨인코딩으로 하면 에러가 뜨던데..
라벨인코딩으로는 작업코드가 어떻게 되나요?
타겟데이터 pop하고 검증데이터 분리 전에 라벨인코딩 진행했는데 이런 에러가 뜹니다,,
# print(train.shape, test.shape)
# train = pd.get_dummies(train) # 전체를 넣으면 train에서 object값만 인코딩하고 수치형 데이터는 그대로 둚
# test = pd.get_dummies(test)
# print(train.shape, test.shape)
cols = train.select_dtypes(include='object').columns
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
for col in cols:
train['col'] = le.fit_transform(train['col'])
test['col'] = le.transform(test['col'])---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3801 try:
-> 3802 return self._engine.get_loc(casted_key)
3803 except KeyError as err:
4 frames
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'col'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3802 return self._engine.get_loc(casted_key)
3803 except KeyError as err:
-> 3804 raise KeyError(key) from err
3805 except TypeError:
3806 # If we have a listlike key, _check_indexing_error will raise
KeyError: 'col'
답변 1
0
col은 컬럼명이 아니라 변수 입니다.
train['col'] = le.fit_transform(train['col'])
test['col'] = le.transform(test['col'])
다음과 같이 사용하셔야 해요!
train[col] = le.fit_transform(train[col])
test[col] = le.transform(test[col])
작업형2 모의문제2에서 drop이랑 인코딩
0
17
1
인코딩을 다 꼭 해봐야하는지
0
24
2
안녕하세요? 강사님 질문있습니다.(인코딩관련)
0
55
2
이진분류에서 양성 클래스가 0일 때 평가 방법
0
45
2
원핫인코딩 전 train과 test 병합여부
0
49
2
수강기간 연장
0
60
2
29강 작업2형의 이상치 처리
0
64
2
수강기간 연장 문의드립니다!
0
64
2
9월에 실기출제기준 개정내역에 신설된부분
0
55
1
작업형2 모의문제2 결과값 관련 문의드립니다.
0
66
2
12회차 시험 실패 후 13회 도전 예정입니다.
0
54
1
random_state 값
0
71
2
강의 연장 문의 드립니다.
0
65
2
강의 연장 문의
0
60
2
오징어게임
0
67
1
object 컬럼이 여러 개인 경우 인코딩 전처리 방법
1
49
2
데이터 전처리 순서 관련
0
63
2
작업형2 모의문제 데이터 불러오기
0
62
2
강의 연장 부탁드립니다!
0
67
2
수강기간 연장 문의드립니다!
0
64
2
2회 기출유형(작업형1) Warning
0
77
2
describe()
0
61
2
수강기간 연장 문의
0
86
2
빅데이터분석기사 실기 인코딩
0
74
2





