def plot_learning_curve(est, x, y):
from sklearn.model_selection import learning_curve,KFold
training_set_size, train_scores, test_scores = learning_curve(
est, x, y, train_sizes=np.linspace(.1, 1, 20), cv=KFold(20, shuffle=True, random_state=1))
estimator_name = est.__class__.__name__
line = plt.plot(training_set_size, train_scores.mean(axis=1), '--',
label="training " + estimator_name)
plt.plot(training_set_size, test_scores.mean(axis=1), '-',
label="test " + estimator_name, c=line[0].get_color())
plt.xlabel('Training set size')
plt.ylabel('Score (R^2)')
plt.ylim(0, 1.1)
评论列表
文章目录