吴裕雄 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()

吴裕雄 python 机器学习——模型选择学习曲线learning_curve模型的更多相关文章
- 吴裕雄 python 机器学习——K均值聚类KMeans模型
import numpy as np import matplotlib.pyplot as plt from sklearn import cluster from sklearn.metrics ...
- 吴裕雄 python 机器学习——混合高斯聚类GMM模型
import numpy as np import matplotlib.pyplot as plt from sklearn import mixture from sklearn.metrics ...
- 吴裕雄 python 机器学习——超大规模数据集降维IncrementalPCA模型
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datas ...
- 吴裕雄 python 机器学习——数据预处理正则化Normalizer模型
from sklearn.preprocessing import Normalizer #数据预处理正则化Normalizer模型 def test_Normalizer(): X=[[1,2,3, ...
- 吴裕雄 python 机器学习——数据预处理标准化MaxAbsScaler模型
from sklearn.preprocessing import MaxAbsScaler #数据预处理标准化MaxAbsScaler模型 def test_MaxAbsScaler(): X=[[ ...
- 吴裕雄 python 机器学习——数据预处理标准化StandardScaler模型
from sklearn.preprocessing import StandardScaler #数据预处理标准化StandardScaler模型 def test_StandardScaler() ...
- 吴裕雄 python 机器学习——数据预处理标准化MinMaxScaler模型
from sklearn.preprocessing import MinMaxScaler #数据预处理标准化MinMaxScaler模型 def test_MinMaxScaler(): X=[[ ...
- 吴裕雄 python 机器学习——支持向量机线性分类LinearSVC模型
import numpy as np import matplotlib.pyplot as plt from sklearn import datasets, linear_model,svm fr ...
- 吴裕雄 python 机器学习——数据预处理字典学习模型
from sklearn.decomposition import DictionaryLearning #数据预处理字典学习DictionaryLearning模型 def test_Diction ...
随机推荐
- ubuntu18 + caffe+cpu+anaconda3
本记录只暂时只记录一些错误. 编译错误,opencv3.2与anaconda3下的libtiff不兼容,冲突. 问题查找(查找所有的TIFF库与编译错误提示匹配/usr/lib/x86_64-linu ...
- PP: Time series clustering via community detection in Networks
Improvement can be done in fulture:1. the algorithm of constructing network from distance matrix. 2. ...
- 显示当前目录命令 - pwd
1) 命令名称:pwd 2) 英文原意:print working directory 3) 命令所在路径:/bin/pwd 4) 执行权限:所有用户 5) 功能描述:显示当前目录 6) 语法: pw ...
- 终极教程【zhong】
just for a better future! 资源教程 aiim 综合类 前端知识体系 前端知识结构 Web前端开发大系概览 We ...
- python中乱码怎么由来与解决方法
前言曾几何时 Python 中文乱码的问题困扰了我很多很多年,每次出现中文乱码都要去网上搜索答案,虽然解决了当时遇到的问题但下次出现乱码的时候又会懵逼,究其原因还是知其然不知其所以然.现在有的小伙伴为 ...
- Thinkcmf对接支付宝支付和获取用户信息
一. 登录支付宝开放平台 平台地址:https://open.alipay.com/ 二. 创建应用并申请上线 登录后,[进入我的开放平台],依次点击[开发者中心]-& ...
- C++-POJ2155-Matrix[数据结构][树状数组]
二维树状数组+叉分 区间修改转化为单点修改 单点查询本来就可视为区间查询 于是本题可解 PS:不知道为什么函数传参数,传的是变量就会出现奇奇怪怪的问题? 所以读入单独写了,还有就是循环的初始化硬是多定 ...
- Python入门3 —— 基本数据类型
一:为何变量值(记录的数据)要有类型呢? 1.既然可以记录事物的状态,为什么要分类型呢? 变量值是来记录事物状态的, 而事物的状态是多种多样的, 所以对应着就要应该用不同类型的值去记录这些状态. 二: ...
- 小议WebRTC拥塞控制算法:GCC介绍
网络拥塞是基于IP协议的数据报交换网络中常见的一种网络传输问题,它对网络传输的质量有严重的影响,网络拥塞是导致网络吞吐降低,网络丢包等的主要原因之一,这些问题使得上层应用无法有效的利用网络带宽获得高质 ...
- 查看ie版本
window10系统还好说,一般都是IE11版本,其他系统或服务器看=查看ie版本就很烦 方法一:按组合键 ALT+H 打开“帮助”,再按 A 选择“关于Internet Explorer” 方法二 ...