学习曲线就是通过画出不同训练集大小时训练集和交叉验证的准确率,可以看到模型在训练集和验证集上的表现,进而可以判断模型是否过拟合了。
具体的可参考这里
我这里用随机森林画的学习曲线,具体代码如下:
from sklearn.model_selection import learning_curve
from sklearn.model_selection import ShuffleSplit
import matplotlib.pyplot as plt
# learning_curve
def plot_learning_curve(estimator, title, X, y, ylim=None, cv=None,n_jobs=1, train_size=np.linspace(.1, 1.0, 5)):
plt.figure()