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()

吴裕雄 python 机器学习——模型选择学习曲线learning_curve模型的更多相关文章

  1. 吴裕雄 python 机器学习——K均值聚类KMeans模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import cluster from sklearn.metrics ...

  2. 吴裕雄 python 机器学习——混合高斯聚类GMM模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import mixture from sklearn.metrics ...

  3. 吴裕雄 python 机器学习——超大规模数据集降维IncrementalPCA模型

    # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datas ...

  4. 吴裕雄 python 机器学习——数据预处理正则化Normalizer模型

    from sklearn.preprocessing import Normalizer #数据预处理正则化Normalizer模型 def test_Normalizer(): X=[[1,2,3, ...

  5. 吴裕雄 python 机器学习——数据预处理标准化MaxAbsScaler模型

    from sklearn.preprocessing import MaxAbsScaler #数据预处理标准化MaxAbsScaler模型 def test_MaxAbsScaler(): X=[[ ...

  6. 吴裕雄 python 机器学习——数据预处理标准化StandardScaler模型

    from sklearn.preprocessing import StandardScaler #数据预处理标准化StandardScaler模型 def test_StandardScaler() ...

  7. 吴裕雄 python 机器学习——数据预处理标准化MinMaxScaler模型

    from sklearn.preprocessing import MinMaxScaler #数据预处理标准化MinMaxScaler模型 def test_MinMaxScaler(): X=[[ ...

  8. 吴裕雄 python 机器学习——支持向量机线性分类LinearSVC模型

    import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model,svm fr ...

  9. 吴裕雄 python 机器学习——数据预处理字典学习模型

    from sklearn.decomposition import DictionaryLearning #数据预处理字典学习DictionaryLearning模型 def test_Diction ...

随机推荐

  1. ping和tracert

    ping命令常用于测试2台主机网络是否连通 TTL的默认值有:64(linux),128(windows),255(路由器) 此例TTL是63所以选用64来减去63等于1,这是说明经过了1个路由器,没 ...

  2. Linux system basic 2 + add kernel for Jupyter

    Linux install LibreOffice: install LibreOffice: install command: sudo apt install ./XXX.deb PS: don' ...

  3. socket 简单实现HTTP服务器

    # -*- coding: utf-8 -*- # @Time : 2019-07-17 1:39 # @File : 网络socket实现http服务器.py # @Software: PyChar ...

  4. jquery-validation.js验证插件使用详解

    jquery-validation 使用 一.用前必备 官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: ...

  5. windows查询端口,杀进程

    C:\Users\chenquan>tasklist | findstr 4720Thunder.exe 4720 Console 1 3,456 K C:\Users\chenquan> ...

  6. Jquery实现点击当前radio button设置选中属性,其它设置非选中属性

    一.HTML代码: <div class="ques-tc-r" id="question_type"> <ul class="cl ...

  7. select出来的表增加递增列

    Select identity(int,1,1) as no,* into #tmp from table

  8. (GHRD)HPS

    DE1作为ARM+FPGA的组合,ARM和FPGA之间通信,两个区块间有三个通道可以让两部分实现传输数据,统称为 HPS-FPGA AXI Bridges. 分别为:FPGA-to-HPS Bridg ...

  9. 解决VS2013报错fopen、sprintf等函数安全的问题

    VS2013中使用fopen.sprintf等函数是会出现安全问题: error C4996: 'fopen': This function or variable may be unsafe. Co ...

  10. 解决“(1146, "Table 'mydb.django_session' doesn't exist")”报错的方法

    执行 ./manage.py makemigrations sessions ./manage.py migrate sessions