安装说明

安装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的更多相关文章

  1. (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探

    一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...

  2. Linear Regression with Scikit Learn

    Before you read  This is a demo or practice about how to use Simple-Linear-Regression in scikit-lear ...

  3. matlab画图函数plot()/set/legend

    简单plot()/legend/XY轴范围axis 除了坐标轴信息外还可以添加其它的信息,如所画曲线的信息等:测试代码如下 x=0:pi/20:2*pi; y1=sin(x); y2=cos(x); ...

  4. MATLAB的PLOT函数线型设置及横坐标为字符串的代码实例

    2.横坐标为字符串的代码实例 cell={‘PLS’,’SVM’,’RF’,’NNET’,’NB’,’PLR’,’C5.0′,’PDA’,’KNN’,’GLM’,’BCT’};%分类方法yData=[ ...

  5. 【搬砖】【Python数据分析】Pycharm中plot绘图不能显示出来

    最近在看<Python数据分析>这本书,而自己写代码一直用的是Pycharm,在练习的时候就碰到了plot()绘图不能显示出来的问题.网上翻了一下找到知乎上一篇回答,试了一下好像不行,而且 ...

  6. MATLAB plot 绘图的一些经验,记下来,facilitate future work

    [转载请注明出处]http://www.cnblogs.com/mashiqi 2016/03/28 % 调整figure的位置scrsz = get(0,'ScreenSize'); % 这个命令是 ...

  7. R语言画全基因组关联分析中的曼哈顿图(manhattan plot)

    1.在linux中安装好R 2.准备好画曼哈顿图的R脚本即manhattan.r,manhattan.r内容如下: #!/usr/bin/Rscript #example : Rscript plot ...

  8. Mac下 Octave 中plot 无法绘制

    在coursera看机器学习课程的时候用到Octave来做数据处理,但是装了之后用plot画图时就会报错: set terminal aqua enhanced title "Figure ...

  9. MATLAB中plot()画图的颜色线型和希腊字母参数设置

    y         黄色           ·             点线      m         粉红           ○             圈线      c          ...

  10. 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 ...

随机推荐

  1. 微信小程序前端支付

    原文地址 //index.js Page({ data: { }, //点击支付按钮进行支付 payclick: function () { var t = this; wx.login({ //获取 ...

  2. c++ xml 解析“后直接跟值问题

    c++ xml库相关 要解析内容: <ITEM name="SLSJ"head="SLSJ"/> 代码: GetNodeAttri(subnodes ...

  3. Centos7单机安装Tableau2018.2

    cd先将服务器防火墙80级8850端口打开 临时关闭SELinux/防火墙 setenforce 0 iptables -F 重点 重点 不能用root用户安装 不能用root用户安装 第一步先创建一 ...

  4. 【Linux 网络编程】滑动窗口协议

    <1>通知接受窗口(rwnd): 预防应用程序发送的数据超过对方的缓冲区.接收方使用的流量控制<2>拥塞窗口(cwnd): 预防应用程序发送的数据超过网络所承受的能力.发送方使 ...

  5. [转帖]紫光与群联联盟,长江存储NAND+群联主控+紫光品牌SSD可期

    紫光与群联联盟,长江存储NAND+群联主控+紫光品牌SSD可期 全国产的 SSD https://baijiahao.baidu.com/s?id=1620789429952097018&wf ...

  6. 为 JS 的字符串,添加一个 format 的功能。

    <script> String.prototype.format = function (kwargs) { var ret = this.replace(/\{(\w+)\}/g, fu ...

  7. 牛逼哄洪的 Java 8 Stream,性能也牛逼么?

    那么,Stream API的性能到底如何呢,代码整洁的背后是否意味着性能的损耗呢?本文对Stream API的性能一探究竟. 为保证测试结果真实可信,我们将JVM运行在 -server模式下,测试数据 ...

  8. centos 防火墙 iptables firewalld SELinux

    参考 Centos7 只启用iptables 禁用firewalld功能 java.net.NoRouteToHostException: 没有到主机的路由 相关内容 centos7 中才开始引用fi ...

  9. C++笔记(0)——判定一个数字是否是素数

    博主之前使用的编程语言是Python,但是这门语言的效率比较低(通常,不优化的情况下,但是即便如此我还是偏爱Python),而且博主打算参加PAT考试(真正的原因),及博主打算顺便深入学习下机器学习框 ...

  10. msql 事务

    START TRANSACTION      delete from t_emp    delete from t_deptcommit START TRANSACTION delete from t ...