scikit-plot
安装说明
安装Scikit-plot非常简单,直接用命令:
pip install scikit-plot
即可完成安装。
仓库地址:
https://github.com/reiinakano/scikit-plot
里面有使用说明和样例(py和ipynb格式)。
使用说明
简单举几个例子
比如画出分类评级指标的ROC曲线的完整代码:
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
X, y = load_digits(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
nb = GaussianNB()
nb.fit(X_train, y_train)
predicted_probas = nb.predict_proba(X_test)
# The magic happens here
import matplotlib.pyplot as plt
import scikitplot as skplt
skplt.metrics.plot_roc(y_test, predicted_probas)
plt.show()
效果如图

图:ROC曲线
P-R曲线就是精确率precision vs 召回率recall 曲线,以recall作为横坐标轴,precision作为纵坐标轴。首先解释一下精确率和召回率。
import matplotlib.pyplot as plt
from sklearn.naive_bayes import GaussianNB
from sklearn.datasets import load_digits as load_data
import scikitplot as skplt
# Load dataset
X, y = load_data(return_X_y=True)
# Create classifier instance then fit
nb = GaussianNB()
nb.fit(X,y)
# Get predicted probabilities
y_probas = nb.predict_proba(X)
skplt.metrics.plot_precision_recall_curve(y, y_probas, cmap='nipy_spectral')
plt.show()

混淆矩阵是分类的重要评价标准,下面代码是用随机森林对鸢尾花数据集进行分类,分类结果画一个归一化的混淆矩阵。
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_digits as load_data
from sklearn.model_selection import cross_val_predict
import matplotlib.pyplot as plt
import scikitplot as skplt
X, y = load_data(return_X_y=True)
# Create an instance of the RandomForestClassifier
classifier = RandomForestClassifier()
# Perform predictions
predictions = cross_val_predict(classifier, X, y)
plot = skplt.metrics.plot_confusion_matrix(y, predictions, normalize=True)
plt.show()

图:归一化混淆矩阵
其他图如学习曲线、特征重要性、聚类的肘点等等,都可以用几行代码搞定。

图:学习曲线、特征重要性

图:K-means肘点图
scikit-plot的更多相关文章
- (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探
一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...
- Linear Regression with Scikit Learn
Before you read This is a demo or practice about how to use Simple-Linear-Regression in scikit-lear ...
- matlab画图函数plot()/set/legend
简单plot()/legend/XY轴范围axis 除了坐标轴信息外还可以添加其它的信息,如所画曲线的信息等:测试代码如下 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); ...
- MATLAB的PLOT函数线型设置及横坐标为字符串的代码实例
2.横坐标为字符串的代码实例 cell={‘PLS’,’SVM’,’RF’,’NNET’,’NB’,’PLR’,’C5.0′,’PDA’,’KNN’,’GLM’,’BCT’};%分类方法yData=[ ...
- 【搬砖】【Python数据分析】Pycharm中plot绘图不能显示出来
最近在看<Python数据分析>这本书,而自己写代码一直用的是Pycharm,在练习的时候就碰到了plot()绘图不能显示出来的问题.网上翻了一下找到知乎上一篇回答,试了一下好像不行,而且 ...
- MATLAB plot 绘图的一些经验,记下来,facilitate future work
[转载请注明出处]http://www.cnblogs.com/mashiqi 2016/03/28 % 调整figure的位置scrsz = get(0,'ScreenSize'); % 这个命令是 ...
- R语言画全基因组关联分析中的曼哈顿图(manhattan plot)
1.在linux中安装好R 2.准备好画曼哈顿图的R脚本即manhattan.r,manhattan.r内容如下: #!/usr/bin/Rscript #example : Rscript plot ...
- Mac下 Octave 中plot 无法绘制
在coursera看机器学习课程的时候用到Octave来做数据处理,但是装了之后用plot画图时就会报错: set terminal aqua enhanced title "Figure ...
- MATLAB中plot()画图的颜色线型和希腊字母参数设置
y 黄色 · 点线 m 粉红 ○ 圈线 c ...
- gnuplot conditional plotting: plot col A:col B if col C == x
http://stackoverflow.com/questions/6564561/gnuplot-conditional-plotting-plot-col-acol-b-if-col-c-x H ...
随机推荐
- flex label如何通过AS3实现颜色设置
如果你想修改label的颜色,你可以在控件上面直接设置color属性,但是有这样一个情况,有些label的颜色是动态设置的,没办法一开始初始化的时候设置 这个时候就需要在AS当中动态的设置,直接.se ...
- Install the Flash plug-in
Flash is a plug-in for your web browser that allows you to watch videos and use interactive web page ...
- 将JSON字符串反序列化为指定的.NET对象类型
目录导航: 前言: 方法一.在项目中定义对应的对象参数模型,用于映射反序列化出来的参数(复杂JSON字符串数据推荐使用): 方法二.直接将JSON字符串格式数据反序列化转化为字典数据(简单JSON字符 ...
- 关于FPS游戏的设计问题
第一个想到的问题: 首先以unity的FPSCharactorController为例,这里规定,相机的方向中心一定是瞄准的方向中心.设置身体的扭曲朝向相机方向,这样身体可以弯腰.你们看图中,我让玩家 ...
- BUUOJ reverse 刮开有奖
刮开有奖 这是一个赌博程序,快去赚钱吧!!!!!!!!!!!!!!!!!!!!!!!!!!!(在编辑框中的输入值,即为flag,提交即可) 注意:得到的 flag 请包上 flag{} 提交 拖到id ...
- [转帖]linux文件描述符文件/etc/security/limits.conf
linux文件描述符文件/etc/security/limits.conf https://blog.csdn.net/fanren224/article/details/79971359 需要多学习 ...
- Python 用户交互程序(day1)
一: 变量 变:变化,重在变字,量:计量,衡量,表示一种状态 变量赋值 : number = 1 变量的规则: 数字,字母,下划线, 任意组合,数字不能开头,python 的关键字不能用,变量名尽量有 ...
- zookeeper集群的搭建(CentOS 7)
注意ip地址为: 虚拟机ip设置 TYPE="Ethernet"BOOTPROTO="static"NAME="enp0s3"DEVICE= ...
- C语言---进制
1. 何为进制 进位机制,逢几进一.数值某一位置上的数在运算时是逢几进一. 生活中的进制:十进制.十二进制(12个月是1年).六十进制(60秒是1分钟) 计算机编程中的进制:二进制.八进制.十六进制. ...
- jmeter强大的扩展插件!!
jmeter4.0以上版本,如jmeter5.1.1版本的集成插件,只需要在官网下下载“plugins-manager.jar”包,放在jmeter安装路径的lib/ext目录下即可使用. (但该ja ...