해결된 질문
작성
·
232
답변 1
0
id가 숫자라면 포함해도 되고 제거해도 됩니다. 포함하더라도 모든 id값이 다르므로 변수(피처)의 중요도를 모델이 낮게 생각해요
2. 검증데이터를 분리할 때
타겟을 제외한 데이터 train.drop('output', axis=1)
타겟 데이터 train['output']
를 넣어주면 됩니다.
X_tr, X_val, y_tr, y_val = train_test_split(train.drop('output', axis=1), train['output'])
코드가 길어서 복잡해 보인다면 아래와 같이 작성할 수도 있어요
X = train.drop('output', axis=1)
y = train['output']
X_tr, X_val, y_tr, y_val = train_test_split(X, y)
X_train = X_train.drop('id',axis = 1)
y_train_id = y_train.pop('id')
from sklearn.model_selection import train_test_split
X_tr,X_val,y_tr,y_val = train_test_split(X_train,y_train,test_size = 0.2,random_state=2022)
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier()
model.fit(X_tr,y_tr)
pred = model.predict(X_val)
이렇게 코드를 적었는데 다음과 같은 오류가 떴습니다
<ipython-input-18-22d814881781>:3: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples,), for example using ravel().
어떤 부분을 수정해야 하는지 알 수 있을까요? ㅠㅠㅠ
X_tr,X_val,y_tr,y_val = train_test_split(X_train,y_train,test_size = 0.2,random_state=2022)
y_train['타겟 컬럼'] 타겟 컬럼을 지정해주세요:)
답변 감사합니다!! 그럼 훈련값, 타켓값 모두 id가 포함되어 있어도 상관없는건가요!!?