Documentation
¶
Overview ¶
Example ¶
data := [][]float64{ {1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}, } labels := []string{"ben", "cassie", "floki", "luna"} rf := New(100) // Define your own split evaluator // Return a score of how good this split is // Default is Gini // // rf.SplitEvaluator = func(t *Tree, left, right []int) float64 { // return rand.Float64() // } rf.Fit(data, labels) for idx, vals := range data { prediction := rf.Predict(vals) log.Printf("Wanted: %s Got: %s", labels[idx], prediction) }
Output:
Index ¶
- func Gini(t *Tree, left, right []int) float64
- func Visualize(tree *Tree) error
- type Node
- type RandomForest
- func (r *RandomForest) Dump(w io.Writer) error
- func (r *RandomForest) Fit(data [][]float64, labels []string) error
- func (r *RandomForest) Predict(data []float64) string
- func (r *RandomForest) PredictProbability(data []float64) map[string]float64
- func (r *RandomForest) Sample() ([][]float64, []string)
- type SplitEvaluator
- type Tree
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Node ¶
type RandomForest ¶
type RandomForest struct { TreeCount int // Number of trees to include in forest MaxDepth int // MinSize int // FeatureCount int // Number of features to include in each tree Trees []*Tree // List of trees created in `Fit` Evaluator SplitEvaluator // Function to evaluate each split SampleSize float64 // Ratio of rows to consider in each tree Data [][]float64 Labels []string }
func New ¶
func New(treeCnt int) *RandomForest
func (*RandomForest) Predict ¶
func (r *RandomForest) Predict(data []float64) string
func (*RandomForest) PredictProbability ¶
func (r *RandomForest) PredictProbability(data []float64) map[string]float64
func (*RandomForest) Sample ¶
func (r *RandomForest) Sample() ([][]float64, []string)
Click to show internal directories.
Click to hide internal directories.