Py之mglearn:python库之mglearn简介、安装、使用方法之详细攻略

简介: Py之mglearn:python库之mglearn简介、安装、使用方法之详细攻略

mglearn简介


     mglearn库,该库集成了sklearn和数据的许多操作方法,很便捷,获取对应数据。Helper functions for the book "Introduction to Machine Learning with Python"

GitHub:https://github.com/amueller/mglearn


1、英文解释


This repository holds the code for the forthcoming book "Introduction to Machine Learning with Python" by Andreas Muellerand Sarah Guido. You can find details about the book on the O'Reilly website.


The books requires the current stable version of scikit-learn, that is 0.20.0. Most of the book can also be used with previous versions of scikit-learn, though you need to adjust the import for everything from the model_selection module, mostly cross_val_score, train_test_split and GridSearchCV.


This repository provides the notebooks from which the book is created, together with the mglearn library of helper functions to create figures and datasets.


For the curious ones, the cover depicts a hellbender.


All datasets are included in the repository, with the exception of the aclImdb dataset, which you can download from the page of Andrew Maas. See the book for details.


If you get ImportError: No module named mglearn you can try to install mglearn into your python environment using the command pip install mglearn in your terminal or !pip install mglearn in Jupyter Notebook.




mglearn安装


pip install mglearn==0.1.6


image.png




mglearn使用方法


1、Helper functions for the book "Introduction to Machine Learning with Python"


This is the mglearn package used in the book, which you can also find in the accompanying repository


You don't need this repo, all the code is there:


https://github.com/amueller/introduction_to_ml_with_python

This repository is a stand-alone package in case you really feel like you want to install mglearn into your Python environment, for some reason or another. You can install it by running


pip install mglearn

in your terminal, or by running


!pip install mglearn

in Jupyter Notebook.


In particular, installing this package is a very easy way to add it to your Python search path. Or you can just check out the notebooks from the repository above, and add the path to the mglearn subfolder to your PYTHONPATH environment variable (or set it in your IDE).



2、Setup


To run the code, you need the packages numpy, scipy, scikit-learn, matplotlib, pandas and pillow. Some of the visualizations of decision trees and neural networks structures also require graphviz. The chapter on text processing also requirs nltk and spacy.


The easiest way to set up an environment is by installing Anaconda.


Installing packages with conda:


If you already have a Python environment set up, and you are using the conda package manager, you can get all packages by running


conda install numpy scipy scikit-learn matplotlib pandas pillow graphviz python-graphviz

For the chapter on text processing you also need to install nltk and spacy:


conda install nltk spacy

Installing packages with pip


If you already have a Python environment and are using pip to install packages, you need to run


pip install numpy scipy scikit-learn matplotlib pandas pillow graphviz

You also need to install the graphiz C-library, which is easiest using a package manager. If you are using OS X and homebrew, you can brew install graphviz. If you are on Ubuntu or debian, you can apt-get install graphviz. Installing graphviz on Windows can be tricky and using conda / anaconda is recommended. For the chapter on text processing you also need to install nltk and spacy:


pip install nltk spacy

Downloading English language model


For the text processing chapter, you need to download the English language model for spacy using


python -m spacy download en



 


相关文章
|
3天前
|
算法 Python
请解释Python中的关联规则挖掘以及如何使用Sklearn库实现它。
使用Python的mlxtend库,可以通过Apriori算法进行关联规则挖掘。首先导入TransactionEncoder和apriori等模块,然后准备数据集(如购买行为列表)。对数据集编码并转换后,应用Apriori算法找到频繁项集(设置最小支持度)。最后,生成关联规则并计算置信度(设定最小置信度阈值)。通过调整这些参数可以优化结果。
25 9
|
3天前
|
索引 Python
如何在Python中使用Pandas库进行季节性调整?
在Python中使用Pandas和Statsmodels进行季节性调整的步骤包括:导入pandas和seasonal_decompose模块,准备时间序列DataFrame,调用`seasonal_decompose()`函数分解数据为趋势、季节性和残差,可选地绘制图表分析,以及根据需求去除季节性影响(如将原始数据减去季节性成分)。这是对时间序列数据进行季节性分析的基础流程。
19 2
|
20小时前
|
5G Python
Windows11搭建Python环境(Anaconda安装与使用)
Windows11搭建Python环境(Anaconda安装与使用)
|
1天前
|
数据挖掘 数据处理 索引
如何使用Python的Pandas库进行数据筛选和过滤?
Pandas是Python数据分析的核心库,提供DataFrame数据结构。基本步骤包括导入库、创建DataFrame及进行数据筛选。示例代码展示了如何通过布尔索引、`query()`和`loc[]`方法筛选`Age`大于19的记录。
8 0
|
2天前
|
数据处理 Python
如何使用Python的Pandas库进行数据排序和排名
【4月更文挑战第22天】Pandas Python库提供数据排序和排名功能。使用`sort_values()`按列进行升序或降序排序,如`df.sort_values(by='A', ascending=False)`。`rank()`函数用于计算排名,如`df['A'].rank(ascending=False)`。多列操作可传入列名列表,如`df.sort_values(by=['A', 'B'], ascending=[True, False])`和分别对'A'、'B'列排名。
13 2
|
3天前
|
Python
如何使用Python的Pandas库进行数据缺失值处理?
Pandas在Python中提供多种处理缺失值的方法:1) 使用`isnull()`检查;2) `dropna()`删除含缺失值的行或列;3) `fillna()`用常数、前后值填充;4) `interpolate()`进行插值填充。根据需求选择合适的方法处理数据缺失。
29 9
|
Python Windows
python怎么安装第三方库,python国内镜像源,终于找到最全的安装教程啦;如Requests,Scrapy,NumPy,matplotlib,Pygame,Pyglet,Tkinter
python怎么安装第三方库,python国内镜像源,终于找到最全的安装教程啦;如Requests,Scrapy,NumPy,matplotlib,Pygame,Pyglet,Tkinter
762 0
|
Shell Python
python安装pygame------我的是python3.8.1,电脑64位机
python安装pygame------我的是python3.8.1,电脑64位机
python安装pygame------我的是python3.8.1,电脑64位机
|
IDE 开发工具 Python
最详细python安装库的方法(以安装pygame库为例)
最详细python安装库的方法(以安装pygame库为例)
155 0
|
Python 容器 Docker
Python游戏开发! Mac完美安装pygame
pygame是python的2D游戏开发库, 优点是秉承了Python风格,简单好用 最近在macOS High Sierra10.13.
2948 0