今天看到了mlxtend的包,看了下example集成得非常簡(jiǎn)潔。還有一個(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
直接解決依賴問題。
同樣的情況對(duì)于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()
之后就可以來(lái)跑一下這個(gè)示例代碼。
matplot結(jié)果如圖:
之后就可以開始玩了~!
附: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
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
