예시문제 작업형2 test 데이터 예측시 발생하는 오류
해결된 질문
758
작성자 없음
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.
라는 에러가 발생합니다 ㅠㅠ
코드를 검토해봐도 이상은 없는거같은데.. 뭐가문제일까요? ㅠㅠ
60. 예시문제 작업형2(ver. 2025) 문의
0
2
1
코딩팡, 시험실제환경 질문
0
18
1
섹션4 질문입니다
0
22
2
[작업형2] 레이블인코딩
0
26
2
[작업형2] train,test 범주 종류, 레이블인코딩 기준
0
20
1
2유형 train 전체 데이터 재학습
0
22
2
책 내용 질문
0
23
2
기출11 작업형3
0
20
2
최종 학습 계획
0
30
2
올려주신 기출 & 출제방식 질문입니다!
0
30
2
작업형 2 최종 제출, 시험 풀이 순서
0
35
1
10회 기출유형 (작업형3) 질문있습니다
0
25
2
빅이시 작업형2 추천1번문제.
0
24
2
굳이 원핫인코딩을 해야되나요?
0
27
2
작업형3 tukey와 Bonferroni
0
26
2
1,3유형 답 소수점 자리수
0
27
1
라이브러리 호출 관련 질문
0
29
1
불균형데이터 처리 관련 문의
0
34
2
작업형2 test데이터 관련 질문입니다.
0
33
2
마지막 단계 생성한 csv 파일 확인
0
27
2
시계열 공부 고민 질문입니다
0
33
1
12회 작업형1 1-1
0
29
1
남은시간 공부 조언을 구하고싶습니다..!
0
37
2
train, test 데이터 object 칼럼 전처리(인코딩) 시 문의
0
35
2





