inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

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

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

해결된 질문

126

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 반드시 함께 적용해요!

 

화이팅!

작업형2에서 데이터 분포를 확인하는 이유

0

18

2

10회 기출 작업형 2 문제

0

18

1

코딩팡 프로 인증

0

22

1

이번 강의 학습노트

0

18

2

캐글 질문

0

17

2

코딩팡 pro 관련

0

20

1

9번질문입니다.

0

22

2

시험에 대해서

0

21

2

12회 작업형 2

0

25

2

copy()

0

26

2

딴짓코치 이용

0

21

1

수강 관련 문의 드립니다.

0

63

4

자치구 상점 수 합(12회)

0

29

1

불균형데이터 처리 전후 비교

0

34

2

레이블인코딩/원핫

0

44

2

인코딩

0

43

2

작업형 2 작업

0

42

2

ttest_rel() 관련 질문

0

51

2

작업형2. 인코딩에 대해 질문드립니다.

0

39

2

작업형3 2-3

0

47

1

코딩팡 2호선 전처리 종합 28번 중고 카메라 매입가 문제 최적화 질문드립니다.

0

40

1

8회 작업형2

0

39

2

작업형2 모의문제2 updated 2026.10

0

54

3

단순선형 회귀분석 신뢰구간,예측구간 관련질문

0

48

2