首页 > 其他 > 详细

ML assignment #1

时间:2017-03-18 15:28:44      阅读:213      评论:0      收藏:0      [点我收藏+]

ML assignment #1

Problem:

implement classification model to train the Iris dataset and make predictions. 

Environment:

Navigator and Jupyter notebook

Language:

python 2.7

Module:

graphlab, matplotlib

Workflow:

1、decision tree using trainset and testset

首先使用graphlab.SFrame.read_csv(“Iris.csv”)導入數據集,然後將數據集,然後將其random split為trainset 和 testset,使用graphlab.decision_tree_classifier.create(train_data,target = target,features = features)

訓練model.該function會自動進行pruning 來防止overfitting.

訓練結果: 

 

技术分享

 

接著使用model.evaluate()分析預測準確率,準確率結果為:0.9629629629629629

使用model.predict()對testset做出prediction,檢驗訓練模型. 並用 matplotlib畫出confusion matrix.

 

confusion matrix: 

 技术分享

 

2、decision tree using K-fold cross validation

首先使用 graphlab.cross_validation.KFold(iris,10)將iris數據集進行10-fold拆分. 然後loop進行模型訓練,計算平均誤差.

最後的平均正確率結果為: 0.926666666667, 更佳符合實際.

 

3、decision using boosting 

graphlab.boosted_trees_classifier.create(train_data,target=target,features=features)

對 train_data用boosting進行訓練,從結果中可以發現,耗時優於上面其他decision tree 算法.

 技术分享

 

 

接著使用model.evaluate()分析預測準確率,準確率結果為:0.9629629629629629

使用model.predict()對testset做出prediction,檢驗訓練模型. 並用 matplotlib畫出confusion matrix.

 

4、using random forest   graphlab.random_forest_classifier.create(train_data,target=target,features=features)

對 train_data進行random forest訓練.

結果如下:

會發現耗時較長,效率較差.

 

 技术分享 

 

Conclusion: 

總共使用了四種方法來對Iris 數據集進行模型訓練,其中1,3,4準確率相等,2略低但更符合test結果.所有的模型的confusion matrix均相同.

ML assignment #1

原文:http://www.cnblogs.com/kinsomy/p/6574231.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!