예시문제 작업형2 test 데이터 예측시 발생하는 오류
해결된 질문
727
작성자 없음
작성한 질문수 0
0
안녕하세요! 복습하는 도중에 이런 에러가 발생되어 질문드립니다 ㅠㅠ
import pandas as pd
X_train = pd.read_csv('X_train.csv',encoding="euc-kr")
y_train = pd.read_csv('y_train.csv')
X_test = pd.read_csv('X_test.csv',encoding="euc-kr")
print(X_train.shape,y_train.shape)
# X_train.head()
# y_train.head()
# X_train.info() #X_train 환불금액 결측치, 오브젝트 두개
# y_train.info()
X_train = X_train.fillna(0)
X_train.isnull().sum()
X_train = X_train.drop(['cust_id'],axis=1)
cust_id = X_test.pop('cust_id')
#라벨인코딩
from sklearn.preprocessing import LabelEncoder
cols = X_train.select_dtypes( include = 'object').columns
cols
for col in cols :
le = LabelEncoder()
X_train[col] = le.fit_transform(X_train[col])
X_test[col] = le.transform(X_test[col])
X_train.head()
#검증데이터 분리
from sklearn.model_selection import train_test_split
X_tr, X_val, y_tr, y_val = train_test_split(X_train,
y_train['gender'],
test_size = 0.2,
random_state = 2022)
X_tr.shape, X_val.shape, y_tr.shape, y_val.shape
#모델링 - 랜덤포레스트
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import roc_auc_score
model = RandomForestClassifier(random_state=2022)
model.fit(X_tr,y_tr)
pred = model.predict_proba(X_val)
roc_auc_score(y_val,pred[:,1])
pred = model.predict_proba(X_test) <------------------이 과정에서 발생되는 오류입니다
pred
ValueError: Input X contains NaN. RandomForestClassifier does not accept missing values encoded as NaN natively.
라는 에러가 발생합니다 ㅠㅠ
코드를 검토해봐도 이상은 없는거같은데.. 뭐가문제일까요? ㅠㅠ
예측값 결과 소수점 차이
0
5
1
기출 문제와 실전챌린지 연습문제 무엇부터 푸는게 나은가요?
0
7
0
전처리 train() test([ ])
0
10
2
작업형 1 배경지식 질문
0
13
2
옳게 풀은건지 질문드립니다!
0
11
1
roc_auc_score
0
17
1
추가질문 합니다
0
12
1
시험환경 구름
0
13
1
2유형 질문드려요
0
10
1
RandomForest vs lgb
0
20
1
전처리 관련질문
0
16
2
작업형3 기출
0
14
1
유형2에서 데이터분할 생략 가능여부
0
25
2
9회 기출 유형3 질문
0
15
1
lgb 기초편
0
11
1
괄호 사용
0
17
1
작업형 2 데이터 전처리 질문
0
20
1
11회 기출 유형 작업형1 문제 3-1
0
16
0
예시문제 작업형2 (ver2023) 질문입니다
0
17
1
Data type에 따른 처리
0
18
2
데이터 전처리 관련
0
17
2
시험에서 문제 불러오기
0
18
2
2번문제 출력값 질문
0
24
2
pd.get_dummies()가 bool로 반환
0
19
2





