欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

数据挖掘-3.建模调参

程序员文章站 2022-05-15 14:35:26
...

数据挖掘-3.建模调参

绘制学习率曲线与验证曲线

learning_curve :param ::train_size
fill_between

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()
    plt.title(title)
    if ylim is not None:
        plt.ylim(*ylim)
    plt.xlabel('Training example')
    plt.ylabel('score')

    train_sizes, train_scores, test_scores = learning_curve(estimator, X, y, cv=cv, 
                                                           n_jobs = n_jobs,
                                                           train_sizes = train_size, 
                                                           scoring = make_scorer(mean_absolute_error))
    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, train_scores_mean - train_scores_std,
                    train_scores_mean + test_scores_std, alpha=.1, color='r')
    plt.fill_between(train_sizes,test_scores_mean - test_scores_std,
                    test_scores_mean + test_scores_std, alpha=.1, color='g')
    plt.plot(train_sizes,train_scores_mean, 'o-', color='r', label='train_mean')
    plt.plot(train_sizes,test_scores_mean, 'o-', color='g', label='val_mean')

    plt.legend(loc='best')
    return plt
相关标签: 数据挖掘