inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

피처 엔지니어링

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

해결된 질문

72

보리과자

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

28

1

강의 연장 문의

0

32

1

출력값 질문

0

31

2

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

0

29

1

실기시험 제출관련

0

160

2

6.20 작업형 2 과적합

0

169

3

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

0

54

2

로지스틱회귀, 회귀

0

52

2

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

0

59

1

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

0

66

2

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

0

66

1

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

0

52

2

3번문제 등분산 가정

0

50

2

작업형3 target 형 변환 질문

0

38

2

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

0

40

3

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

0

62

2

제2유형 질문입니다.

0

49

2

C()

0

44

2

작업형 2에서 strafity 적용 유무

0

53

2

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

0

63

1

ols

0

44

2

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

0

41

2

2유형 작성관련 질문

0

42

2

2유형 object컬럼 개수 다르면

0

49

2