trees

package
v0.0.0-...-4fa0698 Latest Latest
Warning

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

Go to latest
Published: May 24, 2014 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecisionTreeNode

type DecisionTreeNode struct {
	Type      NodeType
	Children  map[string]*DecisionTreeNode
	SplitAttr base.Attribute
	ClassDist map[string]int
	Class     string
	ClassAttr *base.Attribute
}

DecisionTreeNode represents a given portion of a decision tree

func InferID3Tree

func InferID3Tree(from *base.Instances, with RuleGenerator) *DecisionTreeNode

InferID3Tree builds a decision tree using a RuleGenerator from a set of Instances (implements the ID3 algorithm)

func (*DecisionTreeNode) Predict

func (d *DecisionTreeNode) Predict(what *base.Instances) *base.Instances

Predict outputs a base.Instances containing predictions from this tree

func (*DecisionTreeNode) Prune

func (d *DecisionTreeNode) Prune(using *base.Instances)

Prune eliminates branches which hurt accuracy

func (*DecisionTreeNode) String

func (d *DecisionTreeNode) String() string

String returns a human-readable representation of a given node and it's children

type ID3DecisionTree

type ID3DecisionTree struct {
	base.BaseClassifier
	Root       *DecisionTreeNode
	PruneSplit float64
}

ID3DecisionTree represents an ID3-based decision tree using the Information Gain metric to select which attributes to split on at each node.

func NewID3DecisionTree

func NewID3DecisionTree(prune float64) *ID3DecisionTree

Returns a new ID3DecisionTree with the specified test-prune ratio. Of the ratio is less than 0.001, the tree isn't pruned

func (*ID3DecisionTree) Fit

func (t *ID3DecisionTree) Fit(on *base.Instances)

Fit builds the ID3 decision tree

func (*ID3DecisionTree) Predict

func (t *ID3DecisionTree) Predict(what *base.Instances) *base.Instances

Predict outputs predictions from the ID3 decision tree

func (*ID3DecisionTree) String

func (t *ID3DecisionTree) String() string

String returns a human-readable version of this ID3 tree

type InformationGainRuleGenerator

type InformationGainRuleGenerator struct {
}

func (*InformationGainRuleGenerator) GenerateSplitAttribute

func (r *InformationGainRuleGenerator) GenerateSplitAttribute(f *base.Instances) base.Attribute

GetSplitAttribute returns the non-class Attribute which maximises the information gain.

IMPORTANT: passing a base.Instances with no Attributes other than the class variable will panic()

func (*InformationGainRuleGenerator) GetSplitAttributeFromSelection

func (r *InformationGainRuleGenerator) GetSplitAttributeFromSelection(consideredAttributes []int, f *base.Instances) base.Attribute

GetSplitAttribute from selection returns the class Attribute which maximises the information gain amongst consideredAttributes

IMPORTANT: passing a zero-length consideredAttributes parameter will panic()

type NodeType

type NodeType int

NodeType determines whether a DecisionTreeNode is a leaf or not

const (
	// LeafNode means there are no children
	LeafNode NodeType = 1
	// RuleNode means we should look at the next attribute value
	RuleNode NodeType = 2
)

type RandomTree

type RandomTree struct {
	base.BaseClassifier
	Root *DecisionTreeNode
	Rule *RandomTreeRuleGenerator
}

RandomTree builds a decision tree by considering a fixed number of randomly-chosen attributes at each node

func NewRandomTree

func NewRandomTree(attrs int) *RandomTree

NewRandomTree returns a new RandomTree which considers attrs randomly chosen attributes at each node.

func (*RandomTree) Fit

func (rt *RandomTree) Fit(from *base.Instances)

Train builds a RandomTree suitable for prediction

func (*RandomTree) Predict

func (rt *RandomTree) Predict(from *base.Instances) *base.Instances

Predict returns a set of Instances containing predictions

func (*RandomTree) Prune

func (rt *RandomTree) Prune(with *base.Instances)

Prune removes nodes from the tree which are detrimental to determining the accuracy of the test set (with)

func (*RandomTree) String

func (rt *RandomTree) String() string

String returns a human-readable representation of this structure

type RandomTreeRuleGenerator

type RandomTreeRuleGenerator struct {
	Attributes int
	// contains filtered or unexported fields
}

RandomTreeRuleGenerator is used to generate decision rules for Random Trees

func (*RandomTreeRuleGenerator) GenerateSplitAttribute

func (r *RandomTreeRuleGenerator) GenerateSplitAttribute(f *base.Instances) base.Attribute

GenerateSplitAttribute returns the best attribute out of those randomly chosen which maximises Information Gain

type RuleGenerator

type RuleGenerator interface {
	GenerateSplitAttribute(*base.Instances) base.Attribute
}

RuleGenerator implementations analyse instances and determine the best value to split on

Jump to

Keyboard shortcuts

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