# 3.5. 验证曲线: 通过绘制评分图来评估模型¶

## 3.5.1. Validation curve 验证曲线¶

>>> import numpy as np
>>> from sklearn.learning_curve import validation_curve
>>> from sklearn.linear_model import Ridge

>>> np.random.seed(0)
>>> X, y = iris.data, iris.target
>>> indices = np.arange(y.shape[0])
>>> np.random.shuffle(indices)
>>> X, y = X[indices], y[indices]

>>> train_scores, valid_scores = validation_curve(Ridge(), X, y, "alpha",
...                                               np.logspace(-7, 3, 3))
>>> train_scores
array([[ 0.94...,  0.92...,  0.92...],
[ 0.94...,  0.92...,  0.92...],
[ 0.47...,  0.45...,  0.42...]])
>>> valid_scores
array([[ 0.90...,  0.92...,  0.94...],
[ 0.90...,  0.92...,  0.94...],
[ 0.44...,  0.39...,  0.45...]])


## 3.5.2. Learning curve 学习曲线¶

>>> from sklearn.learning_curve import learning_curve
>>> from sklearn.svm import SVC

>>> train_sizes, train_scores, valid_scores = learning_curve(
...     SVC(kernel='linear'), X, y, train_sizes=[50, 80, 110], cv=5)
>>> train_sizes
array([ 50, 80, 110])
>>> train_scores
array([[ 0.98...,  0.98 ,  0.98...,  0.98...,  0.98...],
[ 0.98...,  1.   ,  0.98...,  0.98...,  0.98...],
[ 0.98...,  1.   ,  0.98...,  0.98...,  0.99...]])
>>> valid_scores
array([[ 1. ,  0.93...,  1. ,  1. ,  0.96...],
[ 1. ,  0.96...,  1. ,  1. ,  0.96...],
[ 1. ,  0.96...,  1. ,  1. ,  0.96...]])