• 吴裕雄 python 机器学习——模型选择学习曲线learning_curve模型


    import numpy as np
    import matplotlib.pyplot as plt
    
    from sklearn.svm import LinearSVC
    from sklearn.datasets import load_digits
    from sklearn.model_selection import learning_curve
    
    #模型选择学习曲线learning_curve模型
    def test_learning_curve():
        ### 加载数据
        digits = load_digits()
        X,y=digits.data,digits.target
        #### 获取学习曲线 ######
        train_sizes=np.linspace(0.1,1.0,endpoint=True,dtype='float')
        abs_trains_sizes,train_scores, test_scores = learning_curve(LinearSVC(),X, y,cv=10, scoring="accuracy",train_sizes=train_sizes)
        ###### 对每个 C ,获取 10 折交叉上的预测得分上的均值和方差 #####
        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)
        ####### 绘图 ######
        fig=plt.figure()
        ax=fig.add_subplot(1,1,1)
    
        ax.plot(abs_trains_sizes, train_scores_mean, label="Training Accuracy", color="r")
        ax.fill_between(abs_trains_sizes, train_scores_mean - train_scores_std,train_scores_mean + train_scores_std, alpha=0.2, color="r")
        ax.plot(abs_trains_sizes, test_scores_mean, label="Testing Accuracy", color="g")
        ax.fill_between(abs_trains_sizes, test_scores_mean - test_scores_std,test_scores_mean + test_scores_std, alpha=0.2, color="g")
    
        ax.set_title("Learning Curve with LinearSVC")
        ax.set_xlabel("Sample Nums")
        ax.set_ylabel("Score")
        ax.set_ylim(0,1.1)
        ax.legend(loc='best')
        plt.show()
        
    #调用test_learning_curve()
    test_learning_curve()

  • 相关阅读:
    第一阶段冲刺4
    用户场景分析
    最小不重复数
    BOM
    虚拟机下ubuntu系统设置分辨率
    富文本编辑器KindEditor使用
    页面路径设置
    VMware虚拟机不能上网的问题
    Apache Tomcat/7.0.42配置用户
    JFreeChart 横轴文字竖着显示
  • 原文地址:https://www.cnblogs.com/tszr/p/10802374.html
Copyright © 2020-2023  润新知