Documentation ¶
Index ¶
- Constants
- type CARTDecisionTreeClassifier
- func (tree *CARTDecisionTreeClassifier) Evaluate(test base.FixedDataGrid) (float64, error)
- func (tree *CARTDecisionTreeClassifier) Fit(X base.FixedDataGrid) error
- func (tree *CARTDecisionTreeClassifier) Predict(X_test base.FixedDataGrid) []int64
- func (tree *CARTDecisionTreeClassifier) String() string
- type CARTDecisionTreeRegressor
- type ClassProba
- type ClassesProba
- type DecisionTreeNode
- func (d *DecisionTreeNode) Load(filePath string) error
- func (d *DecisionTreeNode) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
- func (d *DecisionTreeNode) Predict(what base.FixedDataGrid) (base.FixedDataGrid, error)
- func (d *DecisionTreeNode) Prune(using base.FixedDataGrid)
- func (d *DecisionTreeNode) Save(filePath string) error
- func (d *DecisionTreeNode) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
- func (d *DecisionTreeNode) String() string
- type DecisionTreeRule
- type GiniCoefficientRuleGenerator
- type ID3DecisionTree
- func (t *ID3DecisionTree) Fit(on base.FixedDataGrid) error
- func (t *ID3DecisionTree) GetMetadata() base.ClassifierMetadataV1
- func (t *ID3DecisionTree) Load(filePath string) error
- func (t *ID3DecisionTree) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
- func (t *ID3DecisionTree) Predict(what base.FixedDataGrid) (base.FixedDataGrid, error)
- func (t *ID3DecisionTree) PredictProba(what base.FixedDataGrid) (ClassesProba, error)
- func (t *ID3DecisionTree) Save(filePath string) error
- func (t *ID3DecisionTree) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
- func (t *ID3DecisionTree) String() string
- type InformationGainRatioRuleGenerator
- type InformationGainRuleGenerator
- type IsolationForest
- type NodeType
- type RandomTree
- func (rt *RandomTree) Fit(from base.FixedDataGrid) error
- func (rt *RandomTree) GetMetadata() base.ClassifierMetadataV1
- func (rt *RandomTree) Load(filePath string) error
- func (rt *RandomTree) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
- func (rt *RandomTree) Predict(from base.FixedDataGrid) (base.FixedDataGrid, error)
- func (rt *RandomTree) Prune(with base.FixedDataGrid)
- func (rt *RandomTree) Save(filePath string) error
- func (rt *RandomTree) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
- func (rt *RandomTree) String() string
- type RandomTreeRuleGenerator
- type RuleGenerator
- type Slice
Constants ¶
const ( GINI string = "gini" ENTROPY string = "entropy" )
const ( MAE string = "mae" MSE string = "mse" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CARTDecisionTreeClassifier ¶
type CARTDecisionTreeClassifier struct { RootNode *classifierNode // contains filtered or unexported fields }
CARTDecisionTreeClassifier: Tree struct for Decision Tree Classifier It contains the rootNode, as well as all of the hyperparameters chosen by the user. It also keeps track of all splits done at the tree level.
func NewDecisionTreeClassifier ¶
func NewDecisionTreeClassifier(criterion string, maxDepth int64, labels []int64) *CARTDecisionTreeClassifier
Function to Create New Decision Tree Classifier. It assigns all of the hyperparameters by user into the tree attributes.
func (*CARTDecisionTreeClassifier) Evaluate ¶
func (tree *CARTDecisionTreeClassifier) Evaluate(test base.FixedDataGrid) (float64, error)
Given Test data and label, return the accuracy of the classifier. First it retreives predictions from the data, then compares for accuracy. Calls classifierEvaluateFromNode
func (*CARTDecisionTreeClassifier) Fit ¶
func (tree *CARTDecisionTreeClassifier) Fit(X base.FixedDataGrid) error
Fit - Creates an Empty Root Node Trains the tree by calling recursive function classifierBestSplit
func (*CARTDecisionTreeClassifier) Predict ¶
func (tree *CARTDecisionTreeClassifier) Predict(X_test base.FixedDataGrid) []int64
Given test data, return predictions for every datapoint. calls classifierPredictFromNode
func (*CARTDecisionTreeClassifier) String ¶
func (tree *CARTDecisionTreeClassifier) String() string
String : this function prints out entire tree for visualization. Calls a recursive function to print the tree - classifierPrintTreeFromNode
type CARTDecisionTreeRegressor ¶
type CARTDecisionTreeRegressor struct { RootNode *regressorNode // contains filtered or unexported fields }
CARTDecisionTreeRegressor - Tree struct for Decision Tree Regressor It contains the rootNode, as well as the hyperparameters chosen by user. Also keeps track of splits used at tree level.
func NewDecisionTreeRegressor ¶
func NewDecisionTreeRegressor(criterion string, maxDepth int64) *CARTDecisionTreeRegressor
Interface for creating new Decision Tree Regressor
func (*CARTDecisionTreeRegressor) Fit ¶
func (tree *CARTDecisionTreeRegressor) Fit(X base.FixedDataGrid) error
Fit - Build the tree using the data Creates empty root node and builds tree by calling regressorBestSplit
func (*CARTDecisionTreeRegressor) Predict ¶
func (tree *CARTDecisionTreeRegressor) Predict(X_test base.FixedDataGrid) []float64
Predict method for multiple data points. First converts input data into usable format, and then calls regressorPredictFromNode
func (*CARTDecisionTreeRegressor) String ¶
func (tree *CARTDecisionTreeRegressor) String() string
Print Tree for Visualtion - calls regressorPrintTreeFromNode()
type ClassProba ¶
type ClassesProba ¶
type ClassesProba []ClassProba
func (ClassesProba) Len ¶
func (o ClassesProba) Len() int
func (ClassesProba) Less ¶
func (o ClassesProba) Less(i, j int) bool
func (ClassesProba) Swap ¶
func (o ClassesProba) Swap(i, j int)
type DecisionTreeNode ¶
type DecisionTreeNode struct { Type NodeType `json:"node_type"` Children map[string]*DecisionTreeNode `json:"children"` ClassDist map[string]int `json:"class_dist"` Class string `json:"class_string"` ClassAttr base.Attribute `json:"-"` SplitRule *DecisionTreeRule `json:"decision_tree_rule"` }
DecisionTreeNode represents a given portion of a decision tree.
func InferID3Tree ¶
func InferID3Tree(from base.FixedDataGrid, with RuleGenerator) *DecisionTreeNode
InferID3Tree builds a decision tree using a RuleGenerator from a set of Instances (implements the ID3 algorithm)
func (*DecisionTreeNode) Load ¶
func (d *DecisionTreeNode) Load(filePath string) error
Load reads from the classifier from an output file
func (*DecisionTreeNode) LoadWithPrefix ¶
func (d *DecisionTreeNode) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
LoadWithPrefix reads from the classifier from part of another model
func (*DecisionTreeNode) Predict ¶
func (d *DecisionTreeNode) Predict(what base.FixedDataGrid) (base.FixedDataGrid, error)
Predict outputs a base.Instances containing predictions from this tree
func (*DecisionTreeNode) Prune ¶
func (d *DecisionTreeNode) Prune(using base.FixedDataGrid)
Prune eliminates branches which hurt accuracy
func (*DecisionTreeNode) Save ¶
func (d *DecisionTreeNode) Save(filePath string) error
Save sends the classification tree to an output file
func (*DecisionTreeNode) SaveWithPrefix ¶
func (d *DecisionTreeNode) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
func (*DecisionTreeNode) String ¶
func (d *DecisionTreeNode) String() string
String returns a human-readable representation of a given node and it's children
type DecisionTreeRule ¶
type DecisionTreeRule struct { SplitAttr base.Attribute `json:"split_attribute"` SplitVal float64 `json:"split_val"` }
DecisionTreeRule represents the "decision" in "decision tree".
func (*DecisionTreeRule) MarshalJSON ¶
func (d *DecisionTreeRule) MarshalJSON() ([]byte, error)
func (*DecisionTreeRule) String ¶
func (d *DecisionTreeRule) String() string
String prints a human-readable summary of this thing.
func (*DecisionTreeRule) UnmarshalJSON ¶
func (d *DecisionTreeRule) UnmarshalJSON(data []byte) error
type GiniCoefficientRuleGenerator ¶
type GiniCoefficientRuleGenerator struct { }
GiniCoefficientRuleGenerator generates DecisionTreeRules which minimize the Geni impurity coefficient at each node.
func (*GiniCoefficientRuleGenerator) GenerateSplitRule ¶
func (g *GiniCoefficientRuleGenerator) GenerateSplitRule(f base.FixedDataGrid) *DecisionTreeRule
GenerateSplitRule returns the non-class Attribute-based DecisionTreeRule which maximises the information gain.
IMPORTANT: passing a base.Instances with no Attributes other than the class variable will panic()
func (*GiniCoefficientRuleGenerator) GetSplitRuleFromSelection ¶
func (g *GiniCoefficientRuleGenerator) GetSplitRuleFromSelection(consideredAttributes []base.Attribute, f base.FixedDataGrid) *DecisionTreeRule
GetSplitRuleFromSelection returns the DecisionTreeRule which maximises the information gain amongst consideredAttributes
IMPORTANT: passing a zero-length consideredAttributes parameter will panic()
type ID3DecisionTree ¶
type ID3DecisionTree struct { base.BaseClassifier Root *DecisionTreeNode PruneSplit float64 Rule RuleGenerator }
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
NewID3DecisionTree returns a new ID3DecisionTree with the specified test-prune ratio and InformationGain as the rule generator. If the ratio is less than 0.001, the tree isn't pruned.
func NewID3DecisionTreeFromRule ¶
func NewID3DecisionTreeFromRule(prune float64, rule RuleGenerator) *ID3DecisionTree
NewID3DecisionTreeFromRule returns a new ID3DecisionTree with the specified test-prun ratio and the given rule gnereator.
func (*ID3DecisionTree) Fit ¶
func (t *ID3DecisionTree) Fit(on base.FixedDataGrid) error
Fit builds the ID3 decision tree
func (*ID3DecisionTree) GetMetadata ¶
func (t *ID3DecisionTree) GetMetadata() base.ClassifierMetadataV1
func (*ID3DecisionTree) Load ¶
func (t *ID3DecisionTree) Load(filePath string) error
func (*ID3DecisionTree) LoadWithPrefix ¶
func (t *ID3DecisionTree) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
func (*ID3DecisionTree) Predict ¶
func (t *ID3DecisionTree) Predict(what base.FixedDataGrid) (base.FixedDataGrid, error)
Predict outputs predictions from the ID3 decision tree
func (*ID3DecisionTree) PredictProba ¶
func (t *ID3DecisionTree) PredictProba(what base.FixedDataGrid) (ClassesProba, error)
Predict class probabilities of the input samples what, returns a sorted array (by probability) of classes, and another array representing it's probabilities
func (*ID3DecisionTree) Save ¶
func (t *ID3DecisionTree) Save(filePath string) error
func (*ID3DecisionTree) SaveWithPrefix ¶
func (t *ID3DecisionTree) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
func (*ID3DecisionTree) String ¶
func (t *ID3DecisionTree) String() string
String returns a human-readable version of this ID3 tree
type InformationGainRatioRuleGenerator ¶
type InformationGainRatioRuleGenerator struct { }
InformationGainRatioRuleGenerator generates DecisionTreeRules which maximise the InformationGain at each node.
func (*InformationGainRatioRuleGenerator) GenerateSplitRule ¶
func (r *InformationGainRatioRuleGenerator) GenerateSplitRule(f base.FixedDataGrid) *DecisionTreeRule
GenerateSplitRule returns a DecisionTreeRule which maximises information gain ratio considering every available Attribute.
IMPORTANT: passing a base.Instances with no Attributes other than the class variable will panic()
func (*InformationGainRatioRuleGenerator) GetSplitRuleFromSelection ¶
func (r *InformationGainRatioRuleGenerator) GetSplitRuleFromSelection(consideredAttributes []base.Attribute, f base.FixedDataGrid) *DecisionTreeRule
GetSplitRuleFromSelection returns the DecisionRule which maximizes information gain, considering only a subset of Attributes.
IMPORTANT: passing a zero-length consideredAttributes parameter will panic()
type InformationGainRuleGenerator ¶
type InformationGainRuleGenerator struct { }
InformationGainRuleGenerator generates DecisionTreeRules which maximize information gain at each node.
func (*InformationGainRuleGenerator) GenerateSplitRule ¶
func (r *InformationGainRuleGenerator) GenerateSplitRule(f base.FixedDataGrid) *DecisionTreeRule
GenerateSplitRule returns a DecisionTreeNode based on a 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) GetSplitRuleFromSelection ¶
func (r *InformationGainRuleGenerator) GetSplitRuleFromSelection(consideredAttributes []base.Attribute, f base.FixedDataGrid) *DecisionTreeRule
GetSplitRuleFromSelection returns a DecisionTreeRule which maximises the information gain amongst the considered Attributes.
IMPORTANT: passing a zero-length consideredAttributes parameter will panic()
type IsolationForest ¶
type IsolationForest struct {
// contains filtered or unexported fields
}
func NewIsolationForest ¶
func NewIsolationForest(nTrees int, maxDepth int, subSpace int) IsolationForest
Function to create a new isolation forest. nTrees is number of trees in Forest. Maxdepth is maximum depth of each tree. Subspace is number of data points to use per tree.
func (*IsolationForest) Fit ¶
func (iForest *IsolationForest) Fit(X base.FixedDataGrid)
Fit the data based on hyperparameters and data.
func (*IsolationForest) Predict ¶
func (iForest *IsolationForest) Predict(X base.FixedDataGrid) []float64
Return anamoly score for all datapoints.
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.FixedDataGrid) error
Fit builds a RandomTree suitable for prediction
func (*RandomTree) GetMetadata ¶
func (rt *RandomTree) GetMetadata() base.ClassifierMetadataV1
GetMetadata returns required serialization metadata
func (*RandomTree) Load ¶
func (rt *RandomTree) Load(filePath string) error
Load retrieves this model from a file
func (*RandomTree) LoadWithPrefix ¶
func (rt *RandomTree) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
LoadWithPrefix retrives this random tree from disk with a given prefix.
func (*RandomTree) Predict ¶
func (rt *RandomTree) Predict(from base.FixedDataGrid) (base.FixedDataGrid, error)
Predict returns a set of Instances containing predictions
func (*RandomTree) Prune ¶
func (rt *RandomTree) Prune(with base.FixedDataGrid)
Prune removes nodes from the tree which are detrimental to determining the accuracy of the test set (with)
func (*RandomTree) Save ¶
func (rt *RandomTree) Save(filePath string) error
Save outputs this model to a file
func (*RandomTree) SaveWithPrefix ¶
func (rt *RandomTree) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
SaveWithPrefix outputs this model to a file with a prefix.
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) GenerateSplitRule ¶
func (r *RandomTreeRuleGenerator) GenerateSplitRule(f base.FixedDataGrid) *DecisionTreeRule
GenerateSplitRule returns the best attribute out of those randomly chosen which maximises Information Gain
type RuleGenerator ¶
type RuleGenerator interface {
GenerateSplitRule(base.FixedDataGrid) *DecisionTreeRule
}
RuleGenerator implementations analyse instances and determine the best value to split on.