温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python机器学习包mlxtend的安装和配置详解

发布时间:2020-10-26 09:07:52 来源:脚本之家 阅读:494 作者:shincling 栏目:开发技术

今天看到了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结果如图:

python机器学习包mlxtend的安装和配置详解

之后就可以开始玩了~!

附:linux下python科学计算的经典的包的一个总和的命令:

sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI