今天看到了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
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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