这是我的kfolds代码
kf = KFold(class_label.shape[0], n_folds=5, shuffle=True).
for train_index, test_index in kf:.
print("Train:", train_index, "Validation:",test_index).
X_train, X_test = np.array(x)[train_index], np.array(x)[test_index].
y_train, y_test = np.array(class_label)[train_index], np.array(class_label)[test_index]
情节应该看起来像这样,但有10条线
我想为每一折画一条线,所以总共应该有十条线:
test_score = [].
train_score = [].
for depth in range(20):.
clf = DecisionTreeClassifier(max_depth = depth + 1).
clf.fit(X_train,y_train).
train_score.append(clf.score(X_train,y_train)).
test_score.append(clf.score(X_test,y_test)).
plt.figure(figsize = (8,8)).
plt.plot(range(20),train_score).
plt.plot(range(20), test_score).
plt.xlabel('Tree Depth').
plt.ylabel('Accuracy').
plt.legend(['Training set','Test set']).
相关分类