inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

피처 엔지니어링

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

해결된 질문

65

보리과자

작성한 질문수 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

퇴근후딴짓

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

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

 

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

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

1유형 강의 다 나간 후 어떻게 할까요?

0

15

1

점수차가 많이 나는데 따로 하신게 있으신가요?

0

10

1

작업형1 모의문제 4번에 3)문제 질문

0

21

2

이상치 전처리 작업

0

25

2

평가결과값 문의

0

29

2

시계열 데이터 날짜와 시간 format

0

35

2

평가지표 F1 스코어 질문드립니다.

0

27

2

작업형 2 기출7회분에서

0

38

2

작업형2 모의문제1 (30강)

0

34

2

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

0

42

2

수강 계획과 관련해 문의 드립니다.

0

30

2

작업형1 - 연습문제 16~39 풀이는 몇강을 보면 되나요?

0

50

2

작업형 1 -연습문제 4-6

0

38

2

작업형 1 유형 부분

0

42

2

작업형 1 (삭제예정, 구 버전)

0

51

2

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

0

38

2

2유형 레이블 인코딩 VS 원핫 인코딩

0

37

3

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

0

44

2

인덱스 슬라이싱

0

37

2

질문 드립니다.

0

50

2

강의 내용 관련 질문드립니다~

0

46

2

수강 연장 문의

0

63

2

강의자료 일괄 다운로드

0

62

2

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

0

48

2