iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 6
0

一樣用scikit-learn來做做看(連結)

# -*- coding: utf-8 -*-
from sklearn import tree
from sklearn.model_selection import train_test_split
from sklearn import datasets
from sklearn.metrics import accuracy_score


iris = datasets.load_iris()  #load進iris的資料庫

features = iris.feature_names
X = iris.data  
y = iris.target

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)  #test_size預設是0.25

#設定tree的地方
clf = tree.DecisionTreeClassifier(criterion='entropy', max_depth=3)  #criterion可換成entropy,預設是gini

clf = clf.fit(X_train, y_train)

y_result = clf.predict(X_test)
print('score: ', accuracy_score(y_test, y_result))


dot_data = tree.export_graphviz(clf, out_file=None, feature_names=iris.feature_names) #web version http://webgraphviz.com/

[Gini的結果,accu=0.933333333]
https://ithelp.ithome.com.tw/upload/images/20181004/201117857LEsQpHM3d.png

[Entropy的結果,accu=0.9777777]
https://ithelp.ithome.com.tw/upload/images/20181005/20111785bJXrCvLC5j.png


上一篇
[第5天]決策樹
下一篇
[第7天]單純貝氏分類器(Naive Bayes)
系列文
資料工程師的Machine Learning/工作學習歷程20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言