inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

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

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

해결된 질문

102

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

 

화이팅!

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

0

14

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