sklearn不同数量的训练集在测试集上的表现的曲线刻画

def plot_learning_curve(estimator,X,y,cv=5,train_sizes=[0.1,0.3,0.5,0.7,0.8,0.9]):
"""
描述:对于不同数量的训练样本的估计器的验证和训练评分
param estimator:object|
param X:shape=[n_samples,n_feature]
param y:shape=[n_samples,]
param cv:int
param train_size:list of float
"""
import matplotlib.pyplot as plt
   from sklearn.model_selection import learning_curve plt.figure()
plt.title("learning curves")
plt.xlabel("Training examples")
plt.ylabel("Score") train_sizes, train_scores, test_scores = learning_curve(estimator=estimator,
X=X,
y=y,
cv=cv,
train_sizes=train_sizes)
train_scores_mean = np.mean(train_scores,axis=1)
train_scores_std = np.std(train_scores,axis=1)
test_scores_mean = np.mean(test_scores, axis=1)
test_scores_std = np.std(test_scores, axis=1) plt.grid()
plt.fill_between(train_sizes,
y1=train_scores_mean-train_scores_std,
y2=train_scores_mean+train_scores_std,
alpha=0.1,
color="r") plt.fill_between(train_sizes,
y1=test_scores_mean-test_scores_std,
y2=test_scores_mean+test_scores_std,
alpha=0.1,
color="g") plt.plot(train_sizes,train_scores_mean,"o-",color="r",label="training score")
plt.plot(train_sizes, test_scores_mean,'o-',color="g",label="testing score") plt.legend(loc="best") plt.show() plot_learning_curve(estimator=SVC(),X=X,y=y,cv=5,train_sizes=[0.1,0.3,0.5,0.7,0.8,0.9])

文章来源地址https://www.yii666.com/article/756327.html文章地址https://www.yii666.com/article/756327.html网址:yii666.com<网址:yii666.com文章来源地址:https://www.yii666.com/article/756327.html

版权声明:本文内容来源于网络,版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。文本页已经标记具体来源原文地址,请点击原文查看来源网址,站内文章以及资源内容站长不承诺其正确性,如侵犯了您的权益,请联系站长如有侵权请联系站长,将立刻删除

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信图片_20190322181744_03.jpg

微信扫一扫打赏

请作者喝杯咖啡吧~

支付宝扫一扫领取红包,优惠每天领

二维码1

zhifubaohongbao.png

二维码2

zhifubaohongbao2.png