Documentation ¶
Overview ¶
Package randomforest implement ensemble of classifiers using random forest algorithm by Breiman and Cutler.
Breiman, Leo. "Random forests." Machine learning 45.1 (2001): 5-32.
The implementation is based on various sources and using author experience.
Index ¶
- Constants
- Variables
- type Input
- func (forest *Input) AddBagIndex(bagIndex []int)
- func (forest *Input) AddCartTree(tree cart.Input)
- func (forest *Input) AddOobStats(stats classifiers.TestStats)
- func (forest *Input) Build(samples *dataset.Reader) (e error)
- func (forest *Input) ClassifySet(dataset *dataset.Reader, dsIdx []int) (testStats classifiers.TestStats)
- func (forest *Input) GrowTree(t int, samples *dataset.Reader, totalOobErr float64) (oobErr float64, e error)
- func (forest *Input) Init(samples *dataset.Reader)
Constants ¶
const ( // DefNumTree default number of tree. DefNumTree = 100 // DefPercentBoot default percentage of sample that will be used for // bootstraping a tree. DefPercentBoot = 66 )
Variables ¶
var ( // ErrNoInput will tell you when no input is given. ErrNoInput = errors.New("randomforest: input reader is empty") )
Functions ¶
This section is empty.
Types ¶
type Input ¶
type Input struct { // NTree number of tree in forest. NTree int // NFeature number of feature randomly selected for each tree. NFeature int // PercentBoot percentage of sample for bootstraping. PercentBoot int // NSubsample number of samples used for bootstraping. NSubsample int // OobErrMeanVal contain the average out-of-back error value. OobErrMeanVal float64 // OobErrSteps contain OOB error for each steps building a forest from // the first tree until n tree. OobErrSteps []float64 // OobStats contain OOB statistics from the first tree until NTree. OobStats []classifiers.TestStats // Trees contain all tree in the forest. Trees []cart.Input // contains filtered or unexported fields }
Input contains input and output configuration when generating random forest.
func New ¶
New check and initialize forest input and attributes. `ntree` is number of tree to be generated. `nfeature` is number of feature randomly selected for each tree for splitting (the `m`). `percentboot` is percentage of sample that will be taken randomly for generating a tree.
func (*Input) AddBagIndex ¶
AddBagIndex add bagging index for book keeping.
func (*Input) AddCartTree ¶
AddCartTree add tree to forest
func (*Input) AddOobStats ¶
func (forest *Input) AddOobStats(stats classifiers.TestStats)
AddOOBStats will append new result of OOB statistics.
func (*Input) ClassifySet ¶
func (forest *Input) ClassifySet(dataset *dataset.Reader, dsIdx []int) ( testStats classifiers.TestStats, )
ClassifySet given a dataset predict their class by running each sample in forest. Return miss classification rate:
(number of missed class / number of samples).