python机器学习包mlxtend的安装和配置详解
作者:shincling 时间:2021-11-09 22:53:06
今天看到了mlxtend的包,看了下example集成得非常简洁。还有一个吸引我的地方是自带了一些data直接可以用,省去了自己造数据或者找数据的处理过程,所以决定安装体验一下。
依赖环境
首先,sudo pip install mlxtend 得到基础环境。
然后开始看看系统依赖问题的解决。大致看了下基本都是python科学计算用的那几个经典的包,主要是numpy,scipy,matplotlib,sklearn这些。
LINUX环境下的话,一般这些都比较好装pip一般都能搞定。
这里要说的一点是matplotlib的话,pip装的时候提示我的几个问题是png和一个叫Freetype的包被需要,但是装的时候又出现问题。所以matplotlib最后选择用
sudo apt-get install python-matplotlib
直接解决依赖问题。
同样的情况对于scipy也是一样,用
sudo apt-get install python-scipy
解决。
示例代码
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import itertools
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from mlxtend.classifier import EnsembleVoteClassifier
from mlxtend.data import iris_data
from mlxtend.evaluate import plot_decision_regions
# Initializing Classifiers
clf1 = LogisticRegression(random_state=0)
clf2 = RandomForestClassifier(random_state=0)
clf3 = SVC(random_state=0, probability=True)
eclf = EnsembleVoteClassifier(clfs=[clf1, clf2, clf3], weights=[2, 1, 1], voting='soft')
# Loading some example data
X, y = iris_data()
X = X[:,[0, 2]]
# Plotting Decision Regions
gs = gridspec.GridSpec(2, 2)
fig = plt.figure(figsize=(10, 8))
for clf, lab, grd in zip([clf1, clf2, clf3, eclf],
['Logistic Regression', 'Random Forest', 'Naive Bayes', 'Ensemble'],
itertools.product([0, 1], repeat=2)):
clf.fit(X, y)
ax = plt.subplot(gs[grd[0], grd[1]])
fig = plot_decision_regions(X=X, y=y, clf=clf, legend=2)
plt.title(lab)
plt.show()
之后就可以来跑一下这个示例代码。
matplot结果如图:
之后就可以开始玩了~!
附:linux下python科学计算的经典的包的一个总和的命令:
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
来源:https://blog.csdn.net/shincling/article/details/50637528
标签:python,mlxtend,安装
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python Pivot table透视表使用方法解析
2021-06-21 10:22:59
![](https://img.aspxhome.com/file/2023/8/131338_0s.jpg)
python数字图像处理像素的访问与裁剪示例
2023-05-12 11:07:20
![](https://img.aspxhome.com/file/2023/4/127674_0s.png)
使用python脚本实现查询火车票工具
2021-03-10 05:48:54
![](https://img.aspxhome.com/file/2023/0/105340_0s.png)
Python实现滑块拼图验证码详解
2022-04-28 23:22:26
![](https://img.aspxhome.com/file/2023/8/124408_0s.jpg)
Python 安装 virturalenv 虚拟环境的教程详解
2021-04-04 18:27:30
![](https://img.aspxhome.com/file/2023/1/124751_0s.png)
python模块之sys模块和序列化模块(实例讲解)
2022-01-08 07:42:16
![](https://img.aspxhome.com/file/2023/2/89372_0s.png)
Python实现向服务器请求压缩数据及解压缩数据的方法示例
2023-03-14 05:02:08
python实现RSA加密(解密)算法
2023-04-20 06:12:15
![](https://img.aspxhome.com/file/2023/8/107088_0s.png)
树莓派用python中的OpenCV输出USB摄像头画面
2023-11-04 12:12:49
![](https://img.aspxhome.com/file/2023/1/85271_0s.jpg)
python 读取文件并把矩阵转成numpy的两种方法
2023-10-21 23:18:01
python交易记录链的实现过程详解
2022-09-01 19:44:46
![](https://img.aspxhome.com/file/2023/6/90656_0s.png)
python的staticmethod与classmethod实现实例代码
2022-10-02 23:56:45
解决Tensorflow占用GPU显存问题
2021-09-01 14:34:46
![](https://img.aspxhome.com/file/2023/5/81735_0s.jpg)
Python3实现自定义比较排序/运算符
2023-04-15 23:32:25
Django form表单与请求的生命周期步骤详解
2023-06-20 06:29:15
python和C++共享内存传输图像的示例
2021-03-28 01:27:57
![](https://img.aspxhome.com/file/2023/9/120479_0s.png)
只需7行Python代码玩转微信自动聊天
2021-03-09 09:03:22
![](https://img.aspxhome.com/file/2023/9/93779_0s.png)
本地计算机无法启动Apache故障处理
2023-07-17 13:06:48
selenium+opencv实现滑块验证码的登陆
2022-03-28 06:49:04
![](https://img.aspxhome.com/file/2023/6/103606_0s.jpg)
在Python的Django框架中生成CSV文件的方法
2023-07-18 01:13:24