ValueError: Number of labels=712 does not match number of samples=713
653
작성한 질문수 1
안녕하세요. 타이타닉 부분 공부하고 있는데요.
교차검증 관련해서 이런 에러가 나네요.
코드는 그대로 작성한거 같은데요.
from sklearn.model_selection import KFold
def exec_kfold(clf, folds=5):
kfold = KFold(n_splits=folds)
scores = []
for iter_count, (train_index, test_index) in enumerate(kfold.split(X_titanic_df)):
X_train, X_test = X_titanic_df.values[train_index], X_titanic_df.values[test_index]
Y_train, y_test = y_titanic_df.values[train_index], y_titanic_df.values[test_index]
clf.fit(X_train, y_train)
predictions = clf.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
scores.append(accuracy)
print("교차 검증 {0} 정확도: {1:.4f}".format(iter_count, accuracy))
mean_score = np.mean(scores)
print("평균 정확도: {0:.4f}".format(mean_score))
exec_kfold(dt_clf, folds=5)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-26-299d8b191409> in <module> 17 mean_score = np.mean(scores) 18 print("평균 정확도: {0:.4f}".format(mean_score)) ---> 19 exec_kfold(dt_clf, folds=5) <ipython-input-26-299d8b191409> in exec_kfold(clf, folds) 9 Y_train, y_test = y_titanic_df.values[train_index], y_titanic_df.values[test_index] 10 ---> 11 clf.fit(X_train, y_train) 12 predictions = clf.predict(X_test) 13 accuracy = accuracy_score(y_test, predictions) ~/opt/anaconda3/lib/python3.7/site-packages/sklearn/tree/_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted) 875 sample_weight=sample_weight, 876 check_input=check_input, --> 877 X_idx_sorted=X_idx_sorted) 878 return self 879 ~/opt/anaconda3/lib/python3.7/site-packages/sklearn/tree/_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted) 263 if len(y) != n_samples: 264 raise ValueError("Number of labels=%d does not match " --> 265 "number of samples=%d" % (len(y), n_samples)) 266 if not 0 <= self.min_weight_fraction_leaf <= 0.5: 267 raise ValueError("min_weight_fraction_leaf must in [0, 0.5]") ValueError: Number of labels=712 does not match number of samples=713
답변 1
0
안녕하십니까,
오류 내용으로만 봐서는 학습용 feature(sample) 데이터는 713개 인데, target(label) 데이터는 712개로 짝이 안맞는 다는 내용입니다. 뭔가 중간에 데이터 가공이 된 상태로 메모리에 올라간것 같습니다.
커널을 재 기동 한 후 타이타닉 데이터를 재 로드 한 후에 수행을 다시 해보시기 바랍니다.
감사합니다.
안녕하세요 열심히 수강중인 학생입니다
0
63
2
정수 인덱싱
0
68
2
넘파이 오류
0
85
2
11강 numpy의 axis 축 질문 드립니다.
0
85
2
Kaggle 에서 Santander customer satisfaction data 를 다운로드 되지가 않습니다.
0
79
2
Feature importances 를 보여주는 barplot 이 그래프로 안보여져요.
0
70
2
타이타닉 csv 파일이 주피터 화면에 보이지 않습니다.
0
75
2
타이타닉 csv 파일이 주피터 화면에 보이지 않습니다.
0
64
2
5강 강의 오류가 있어요.
0
84
1
실무에서 LTV 관련 모델 선택 질문입니다!
0
72
2
14강 강의 듣는중에 궁금한게 있어서 질문합니다~
0
69
3
파이썬 다운그레이 후 사이킷런 재설치
0
117
2
좋은 강의 감사합니다.
0
72
2
scoring 함수 음수값
0
67
2
6번 강의에 사이킷런, 파이썬, 아나콘다 각각 버전 일치 안 시키고 진행해도 강의 따라가 지나요?
0
100
2
분류 평가 정확도 예측
0
76
2
안녕하세요. 강의 들으면서 업무에 적용하고 싶은 수강생입니다.
0
99
1
카카오톡 채널 있나요
0
107
1
혹시 강의에서 사용하시는 ppt 받을 수 있는건가요
0
189
2
pca 스케일링 관련하여 질문드립니다.
0
100
2
주피터 대신 구글 코랩
0
172
2
강의에서 사용하는 pdf or ppt자료는 따로 없는 건가요?
0
148
2
실루엣 스코어..
0
86
2
float64 null 값 처리 방법
0
103
2





