溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python機(jī)器學(xué)習(xí)包mlxtend的安裝和配置詳解

發(fā)布時(shí)間:2020-10-26 09:07:52 來源:腳本之家 閱讀:512 作者:shincling 欄目:開發(fā)技術(shù)

今天看到了mlxtend的包,看了下example集成得非常簡潔。還有一個(gè)吸引我的地方是自帶了一些data直接可以用,省去了自己造數(shù)據(jù)或者找數(shù)據(jù)的處理過程,所以決定安裝體驗(yàn)一下。

依賴環(huán)境

首先,sudo pip install mlxtend 得到基礎(chǔ)環(huán)境。

然后開始看看系統(tǒng)依賴問題的解決。大致看了下基本都是python科學(xué)計(jì)算用的那幾個(gè)經(jīng)典的包,主要是numpy,scipy,matplotlib,sklearn這些。

LINUX環(huán)境下的話,一般這些都比較好裝pip一般都能搞定。
這里要說的一點(diǎn)是matplotlib的話,pip裝的時(shí)候提示我的幾個(gè)問題是png和一個(gè)叫Freetype的包被需要,但是裝的時(shí)候又出現(xiàn)問題。所以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()

之后就可以來跑一下這個(gè)示例代碼。

matplot結(jié)果如圖:

python機(jī)器學(xué)習(xí)包mlxtend的安裝和配置詳解

之后就可以開始玩了~!

附:linux下python科學(xué)計(jì)算的經(jīng)典的包的一個(gè)總和的命令:

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI