인프런 커뮤니티 질문&답변
섹션4. 이직 여부 예측 질문
작성
·
31
0
코딩이 실행이 안되는 이유가 궁금합니다.
import pandas as pd
train = pd.read_csv("https://raw.githubusercontent.com/lovedlim/inf/refs/heads/main/p2/hr_train.csv")
test = pd.read_csv("https://raw.githubusercontent.com/lovedlim/inf/refs/heads/main/p2/hr_test.csv")
target=train.pop('target')
train=train.fillna('X')
test=test.fillna('X')
df=pd.concat([train,test],axis=0)
df=pd.get_dummies(df)
train=train.iloc[:len(train)].copy()
test=test.iloc[len(train):].copy()
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=0)
from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(random_state=0)
rf.fit(X_tr, y_tr)
pred = rf.predict_proba(X_val)
pred = rf.predict_proba(test)답변 1
0
퇴근후딴짓
지식공유자
데이터를 분리하고 합치고 할 때 사이즈는 문제가 없는지
점검하면서 코딩해주세요!
모두 입력하고나서 에러가 나면 입문자는 생각보니 찾는 것이 쉽지 않거든요
데이터를 df로 합칠 쳤는데
다시 나눌때는 df를 사용하는 것이 아니라 train으로 test로 나누는 이상한 코드가 되어있습니다.
train=df.iloc[:len(train)].copy()
test=df.iloc[len(train):].copy()





