对mglearn库的理解

先看该库的配置文件

from . import plots
from . import tools
from .plots import cm3, cm2
from .tools import discrete_scatter
from .plot_helpers import ReBl

__version__ = "0.1.7"

__all__ = ['tools', 'plots', 'cm3', 'cm2', 'discrete_scatter', 'ReBl']

下面是简单的理解,暂时写了4条:

1:这个库中的plots模块内有许多已经做好的数据视图。方便查看,帮助你省略了构建的过程。
  列:一行简单的代码,就可以查看线性回归在回归问题中的使用情况。

mglearn.plots.plot_linear_regression_wave()

在这里插入图片描述
  例:一行代码就可以查看,参数C的大小对LinearSVC算法的影响

mglearn.plots.plot_linear_svc_regularization()

在这里插入图片描述

2:这个库中的cm2、cm3内有配置好的配色方案,在用pyplot作图时可以方便的调用
这是定位到的源代码:

# create a smooth transition from the first to to the second color of cm3
# similar to RdBu but with our red and blue, also not going through white,
# which is really bad for greyscale

cdict = {'red': [(0.0, 0.0, cm2(0)[0]),
                 (1.0, cm2(1)[0], 1.0)],

         'green': [(0.0, 0.0, cm2(0)[1]),
                   (1.0, cm2(1)[1], 1.0)],

         'blue': [(0.0, 0.0, cm2(0)[2]),
                  (1.0, cm2(1)[2], 1.0)]}

ReBl = LinearSegmentedColormap("ReBl", cdict)

  例:

    ax.plot(X_train, y_train, '^', c=mglearn.cm2(0), markersize=8)
    ax.plot(X_test, y_test, 'v', c=mglearn.cm2(1), markersize=8)

3.这个库引用的sklearn.datasets模块内,有加载和获取常用数据集、人工生成数据集的方法。

  例:加载波士顿房价数据集(带有load关键字的方法,均为加载库中已有数据。)

X, y = mglearn.datasets.load_extended_boston()

  例:人工生成数据(带有make关键字的方法)。

from sklearn.datasets import make_moons
X, y = make_moons(n_samples=100, noise=0.25, random_state=3)

4:这个库中的plots模块对matplotlib.pyplot做出了修改,更适合绘制类和集群的视图。
  例:

mglearn.plots.plot_2d_separator(clf, X, fill=False, eps=0.5,
                                    ax=ax, alpha=.7)
  • 12
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值