基於 ID3 演算法的 ML 決策樹的實現
本庫是實現用於決策樹學習的 ID3 演算法的 Ruby 庫,目前能夠學習連續和離散的數據集。
Github 鏈接:
https://github.com/igrigorik/decisiontree
特點
用於連續和離散情況的 ID3 演算法,支持不一致的數據集。
Graphviz 組件可視化學習樹
支持多個符號輸出和連續樹形圖。
當沒有分支適合輸入時返回默認值
實現
Bagging 是一個基於 Bagging 的訓練器,它可以訓練 10 個 Ruleset 訓練器,並通過投票預測最佳的輸出結果。
詳細信息請訪問以下鏈接:
https://www.igvita.com/2007/04/16/decision-tree-learning-in-ruby/
示例
require"decisiontree"
attributes = ["Temperature"]
training = [
[36.6,"healthy"],
[37,"sick"],
[38,"sick"],
[36.7,"healthy"],
[40,"sick"],
[50,"really sick"],
]
# Instantiate the tree, and train it based on the data (set default to "1")
dec_tree = DecisionTree::ID3Tree.new(attributes, training,"sick",:continuous)
dec_tree.train
test = [37,"sick"]
decision = dec_tree.predict(test)
puts"Predicted:#... True decision:#"
# => Predicted: sick ... True decision: sick
# Specify type ("discrete" or "continuous") in the training data
labels = ["hunger","color"]
training = [
[8,"red","angry"],
[6,"red","angry"],
[7,"red","angry"],
[7,"blue","not angry"],
[2,"red","not angry"],
[3,"blue","not angry"],
[2,"blue","not angry"],
[1,"red","not angry"]
]
dec_tree = DecisionTree::ID3Tree.new(labels, training,"not angry",color::discrete,hunger::continuous)
dec_tree.train
test = [7,"red","angry"]
decision = dec_tree.predict(test)
puts"Predicted:#... True decision:#"
# => Predicted: angry ... True decision: angry
從Python入門-如何成為AI工程師
BAT資深演算法工程師獨家研發課程
最貼近生活與工作的好玩實操項目
班級管理助學搭配專業的助教答疑
學以致用拿offer,學完即推薦就業
新人福利
關注 AI 研習社(okweiwu),回復1領取
【超過 1000G 神經網路 / AI / 大數據資料】
開發者自述:我是如何理解決策樹的
※谷歌開源 FHIR 標準協議緩衝工具,利用機器學習預測醫療事件
※李飛飛斯坦福CS231n,原來學霸們都是這麼學的
TAG:AI研習社 |