inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

피처 엔지니어링

라벨 인코딩에서 오류가 납니다..

해결된 질문

112

보리과자

작성한 질문수 4

0

마지막 강의 영상 <정리>부분에서

 

데이터 불러오기

X_train = pd.read_csv("https://raw.githubusercontent.com/lovedlim/inf/main/p2/data_atype/X_train.csv")

y_train = pd.read_csv("https://raw.githubusercontent.com/lovedlim/inf/main/p2/data_atype/y_train.csv")

X_test = pd.read_csv("https://raw.githubusercontent.com/lovedlim/inf/main/p2/data_atype/X_test.csv")


데이터 분리

n_train = X_train.select_dtypes(exclude='object').copy()

n_test = X_test.select_dtypes(exclude='object').copy()

c_train = X_train.select_dtypes(include='object').copy()

c_test = X_test.select_dtypes(include='object').copy()


수치형 민맥스 스케일

cols = ['age', 'fnlwgt', 'education.num', 'capital.gain', 'capital.loss', 'hours.per.week']

 

from sklearn.preprocessing import MinMaxScaler

scaler = MinMaxScaler()

 

n_train[cols] = scaler.fit_transform(n_train[cols])

n_test[cols] = scaler.transform(n_test[cols])


라벨인코딩

cols = ['workclass', 'education', 'marital.status', 'occupation', 'relationship', 'race', 'sex', 'native.country']

 

from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()

 

for col in cols:

le = LabelEncoder()

c_train[col] = le.fit_transform(c_train[col])

c_test[col] = le.transform(c_test[col])

 

이 부분에서 이러한 에러가 납니다..

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\anaconda3\lib\site-packages\sklearn\preprocessing\_label.py in _encode(values, uniques, encode, check_unknown)
    112         try:
--> 113             res = _encode_python(values, uniques, encode)
    114         except TypeError:

~\anaconda3\lib\site-packages\sklearn\preprocessing\_label.py in _encode_python(values, uniques, encode)
     60     if uniques is None:
---> 61         uniques = sorted(set(values))
     62         uniques = np.array(uniques, dtype=values.dtype)

TypeError: '<' not supported between instances of 'str' and 'float'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-95-295cc9604042> in <module>
      7 for col in cols:
      8     le = LabelEncoder()
----> 9     c_train[col] = le.fit_transform(c_train[col])
     10     c_test[col] = le.transform(c_test[col])

~\anaconda3\lib\site-packages\sklearn\preprocessing\_label.py in fit_transform(self, y)
    254         """
    255         y = column_or_1d(y, warn=True)
--> 256         self.classes_, y = _encode(y, encode=True)
    257         return y
    258 

~\anaconda3\lib\site-packages\sklearn\preprocessing\_label.py in _encode(values, uniques, encode, check_unknown)
    115             types = sorted(t.__qualname__
    116                            for t in set(type(v) for v in values))
--> 117             raise TypeError("Encoders require their input to be uniformly "
    118                             f"strings or numbers. Got {types}")
    119         return res

TypeError: Encoders require their input to be uniformly strings or numbers. Got ['float', 'str']


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

답변 1

0

퇴근후딴짓

이전시간 작업 전처리가 되지 않은 상태여서 인것 같습니다.

예를 들면, 결측치 처리가 되지 않은 것 같아요

 

제가 공유한 노트북 보면 "데이터 전처리 (이전시간 작업)"

이 있어요 이부분 실행후 작업해주세요 🙂

수강기간 연장문의

0

3

1

작업형 2 질문

0

18

2

강의 연장 관련하여 문의드립니다.

0

20

1

섹션7 자료 다운로드

0

22

2

작업형 1 연습문제 Section12

0

21

2

수강기간 연장 문의

0

31

1

안녕하세요, 혹시 수강기간 연장이 가능할까요?

0

30

2

판다스 강의자료는 어디서 받을 수 있나요?

0

31

2

작업형2 모의고사3 자료 업데이트 요청

0

36

4

수강 연장가능여부 문의드립니다!

0

41

2

수강기간 연장 문의드립니다!

0

37

2

최빈값

0

39

2

수강 가이드라인

0

35

2

수강 연장 가능 여부 문의

0

57

2

강의 구매했는데 교재 필수일까요

0

47

2

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

0

41

2

수강기간 연장이 가능한지 양해를 구하며 문의를 드립니다.

0

43

2

작업형2 모의문제2에서 drop이랑 인코딩

0

53

3

인코딩을 다 꼭 해봐야하는지

0

51

2

안녕하세요? 강사님 질문있습니다.(인코딩관련)

0

62

2

이진분류에서 양성 클래스가 0일 때 평가 방법

0

46

2

원핫인코딩 전 train과 test 병합여부

0

53

2

수강기간 연장

0

72

2

29강 작업2형의 이상치 처리

0

70

2