randomforest

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2016 License: BSD-3-Clause Imports: 7 Imported by: 0

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

View Source
const (
	// DefNumTree default number of tree.
	DefNumTree = 100
	// DefPercentBoot default percentage of sample that will be used for
	// bootstraping a tree.
	DefPercentBoot = 66
)

Variables

View Source
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

func New(ntree, nfeature, percentboot int) (forest *Input)

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

func (forest *Input) AddBagIndex(bagIndex []int)

AddBagIndex add bagging index for book keeping.

func (*Input) AddCartTree

func (forest *Input) AddCartTree(tree cart.Input)

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) Build

func (forest *Input) Build(samples *dataset.Reader) (e error)

Build the forest using samples dataset.

- samples: as original dataset.

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).

func (*Input) GrowTree

func (forest *Input) GrowTree(t int, samples *dataset.Reader,
	totalOobErr float64) (
	oobErr float64,
	e error,
)

func (*Input) Init

func (forest *Input) Init(samples *dataset.Reader)

Init initialize the forest.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL