首页 > 代码库 > scikit-learn:3.5. Validation curves: plotting scores to evaluate models

scikit-learn:3.5. Validation curves: plotting scores to evaluate models

參考:http://scikit-learn.org/stable/modules/learning_curve.html



estimator‘s generalization error can be decomposed in terms ofbias, variance and noise. The bias of an estimator is its average error for different training sets. The variance of an estimator indicates how sensitive it is to varying training sets. Noise is a property of the data.



首先介绍背景,进而引入本节要讲的内容。背景就是:

针对函数COS(1.5π x),分别使用不同的estimators fit the function:linear regression with polynomial features of degree 1, 4 and 15。结果图例如以下:

技术分享

图一high bias,图二刚好,图三high variance。但,,,。这并非重点。。

。。。。。。

。。



重点是:对于一维的COS函数。能够通过绘图来辨别bias或variance。但对于高维的样例,不能通过绘图来识别。此时。以下要讲的内容就helpful了。。。



1、Validation curve

为了验证一个模型。我们须要一个scoring function(see Model evaluation: quantifying the quality of predictions。翻译文章:http://blog.csdn.net/mmc2015/article/details/47121611)。而为了找到较好的超參数的组合。我们常使用grid search或类似方法 (seeGrid Search: Searching for estimator parameters,翻译文章:http://blog.csdn.net/mmc2015/article/details/47100091) ,在grid search过程中,我们希望找到使validation sets最大的score相应的超參数组合。(注意,validation sets一旦使用,对于模型就是有bias的,所以对于generalization,一定要再选择其它独立的test sets验证。

然而并非重点。

。。

。。

重点是,我们希望能够plot the influence of a single hyperparameter on the training score and the validation score,这样有助于分析estimator是否overfitting、underfitting。。

技术分享

training score and the validation score都low,说明estimator underfittig;training score high but the validation score low,说明overfitting。training score and the validation score都high,说明效果比較好(上图告诉我们。參数gamma最好选择0.001-0.0001);training score low but the validation score high,可能性不大。

(事实上该方法不是非常有用,由于模型不仅受一个參数的影响。还会受其它參数的综合影响,还是grid search靠谱;假设仅仅有一个參数。那么该方法比較好。


2、Learning curve

A learning curve shows the validation and training score of an estimator for varying numbers of training samples.

技术分享

如上图。If both the validation score and the training score converge to a value that is too low with increasing size of the training set, we will not benefit much from more training data.这时,须要考虑换estimator或者调參数。


技术分享

如上图,If the training score is much greater than the validation score for the maximum number of training samples, adding more training samples will most likely increase generalization.这时。须要考虑获取很多其它的samples。



上面几幅图的产生程序參考:

  • Underfitting vs. Overfitting
  • Plotting Validation Curves
  • Plotting Learning Curves

scikit-learn:3.5. Validation curves: plotting scores to evaluate models