inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

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

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

해결된 질문

107

bobby1994

작성한 질문수 14

0

8회 기출유형 (작업형2) 문제 관련해서 저장할때 오류가 떠서 문의드립니다.

 

import pandas as pd
train = pd.read_csv("https://raw.githubusercontent.com/lovedlim/inf/refs/heads/main/p4/8_2/churn_train.csv")
test = pd.read_csv("https://raw.githubusercontent.com/lovedlim/inf/refs/heads/main/p4/8_2/churn_test.csv")
train.shape, test.shape

cols = train.select_dtypes(include='object').columns
cols
from sklearn.preprocessing import LabelEncoder
for col in cols:
  le = LabelEncoder()
  train[col]=le.fit_transform(train[col])
  test[col]=le.transform(test[col])

from sklearn.model_selection import train_test_split
X_tr,X_val,y_tr,y_val = train_test_split (train,target,test_size=0.2,random_state=2022)
X_tr.shape,X_val.shape,y_tr.shape,y_val.shape

from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor(random_state=2022)
model.fit(X_tr,y_tr)
pred = model.predict(X_val)

from sklearn.metrics import mean_absolute_error
mae = mean_absolute_error(y_val,pred)
print(mae)

pred = model.predict(test)
submit = pd.DataFrame({'pred':pred})

제일 마지막 pred = model.predict(test) 과정에서

ValueError                                Traceback (most recent call last)
<ipython-input-82-67795a42191c> in <cell line: 0>()
----> 1 pred = model.predict(test)
      2 submit = pd.DataFrame({'pred':pred})


5 frames


/usr/local/lib/python3.11/dist-packages/pandas/core/generic.py in __array__(self, dtype, copy)
   2151     ) -> np.ndarray:
   2152         values = self._values
-> 2153         arr = np.asarray(values, dtype=dtype)
   2154         if (
   2155             astype_is_view(values.dtype, arr.dtype)

ValueError: could not convert string to float: 'CUST0769'

이런 오류가 뜨길래 검색해보니 object 형태의 컬럼이 있다고 오류가 뜹니다ㅠ

전처리 과정에서 Label인코딩을 하였고, 데이터 형태 int로 바뀐것까지 확인하였는데,

확인 부탁드리겠습니다ㅠㅠ

선생님 강의에서 customer_ID를 삭제(drop)하였는데, 그걸 저는 따로 진행을 안했는데, 혹시 그것 때문인지 문의드립니다!

추가로 customer_ID를 삭제 안하고 진행해도 괜찮은지도 알려주시면 감사하겠습니다~!^^

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

답변 1

0

퇴근후딴짓

customer_ID가 숫자면 삭제하지 않고 진행해도 괜찮습니다.

다만 customer_ID가 문자면 삭제 또는 인코딩 중 선택을 해야 하는데

모두가 종류가 다른 유니크한 값이면 보통 삭제를 합니다 🙂

그리고 삭제 또는 인코딩할 때는 train과 test 반드시 함께 적용해요!

 

화이팅!

뒤로가기 버튼 같은 것이 있나요?

0

22

1

강의 연장 문의

0

22

1

출력값 질문

0

28

2

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

0

28

1

실기시험 제출관련

0

159

2

6.20 작업형 2 과적합

0

165

3

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

0

51

2

로지스틱회귀, 회귀

0

51

2

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

0

58

1

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

0

65

2

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

0

65

1

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

0

51

2

3번문제 등분산 가정

0

49

2

작업형3 target 형 변환 질문

0

37

2

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

0

39

3

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

0

60

2

제2유형 질문입니다.

0

48

2

C()

0

44

2

작업형 2에서 strafity 적용 유무

0

52

2

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

0

61

1

ols

0

44

2

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

0

40

2

2유형 작성관련 질문

0

41

2

2유형 object컬럼 개수 다르면

0

48

2