inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)

6회 기출유형 (작업형2)

6회 작업형2 라벨인코딩

해결된 질문

436

작성자 없음

작성한 질문수 0

0

원핫인코딩 말고 라벨인코딩으로 하면 에러가 뜨던데..

 

라벨인코딩으로는 작업코드가 어떻게 되나요?

타겟데이터 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'

python 머신러닝 빅데이터 pandas 빅데이터분석기사

답변 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])

출력값 질문

0

11

1

수업노트가 어디에 있나요?

0

21

1

실기시험 제출관련

0

153

2

6.20 작업형 2 과적합

0

158

3

코딩팡 장업형2 베이스 라인 인코딩 종류 질문

0

49

2

로지스틱회귀, 회귀

0

48

2

회귀 문제를 풀때 질문입니다.

0

55

1

불균형 처리 후 성능이 더 낮아졌다면,

0

61

2

실기 체험 제2유형 에러 문의

0

61

1

LIGHTGBM 으로 하면 pred값이 소수점 6자리까지 나오는게 맞나요

0

50

2

3번문제 등분산 가정

0

48

2

작업형3 target 형 변환 질문

0

35

2

[작업형1] 연습문제 섹션1 ~ 10 의 section4

0

36

3

원핫인코딩과 레이블 인코딩에서 concat

0

59

2

제2유형 질문입니다.

0

46

2

C()

0

44

2

작업형 2에서 strafity 적용 유무

0

52

2

수강 기간 연장 가능 여부 문의드립니다.

0

61

1

ols

0

43

2

2유형 작성관련 질문(일반 심화)

0

39

2

2유형 작성관련 질문

0

41

2

2유형 object컬럼 개수 다르면

0

48

2

코딩팡질문이요ㅠㅠ

0

45

2

관찰값과 기대값의 개념이 헷갈립니다.

0

25

2