Machine Learning algorithms : Decision Tree, Random Forest implementations
"This section applies the CART algorithm to the Bank Note dataset."
types := map[string]string{"y": "float"}
df := io.LoadCsv("./testdata/data_banknote_authentication.txt", csv.Headers([]string{"col_0", "col_1", "col_2", "col_3", "y"}), csv.Types(types))
m := io.ToMatrix(df)
scores := eval.CrossVal(m, 4, 5, decision.Fit, map[string]int{"maxDepth": 5, "minSize": 10})
fmt.Println("Decision Tree", scores)
Output :
Decision Tree [95.25547445255475 98.17518248175182 96.71532846715328 90.51094890510949 98.91304347826086]
scores = eval.CrossVal(m, 4, 5, ensemble.Fit, map[string]int{"n_estimator": 5, "maxDepth": 5, "minSize": 10})
fmt.Println("RandoForest", scores)
Output :
RandoForest [90.14598540145985 89.78102189781022 96.71532846715328 92.33576642335767 93.11594202898551]
-
io / : it has
ReadCSV
that returns aQFrame
(like pandas.DataFrame for golang).ToMatrix
takes aQFrame
and return agonum.mat.Dense
object -
mathelper / : matrix helpers like
[]float64
togonum.mat.Vector
convertion (into aRow
orColumn
object). There is aMode
(statistic) function taking agonum.mat.Vector
-
eval / : has
Accuracy
score function inmetric.go
and exposeCrossVal
that takes an algoFit
function and return an array of the resultted accuracy scores for many folds -
model.go
: defines theModel
interface which hasPredict
contract.- decision / : DecisionTree is exposed by this package, using CART and the gini function.
- ensemble / : RandomForest algorithm is exposed by this package. It uses Boostraping and Bagging of DecisionTrees.