tree

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecisionTreeClassifier

type DecisionTreeClassifier struct {
	// contains filtered or unexported fields
}

DecisionTreeClassifier implements a decision tree for classification

func NewDecisionTreeClassifier

func NewDecisionTreeClassifier(opts ...DecisionTreeClassifierOption) *DecisionTreeClassifier

NewDecisionTreeClassifier creates a new decision tree classifier

func (*DecisionTreeClassifier) Fit

func (dt *DecisionTreeClassifier) Fit(X, y mat.Matrix) error

Fit trains the decision tree

func (*DecisionTreeClassifier) GetDepth

func (dt *DecisionTreeClassifier) GetDepth() int

GetDepth returns the depth of the tree

func (*DecisionTreeClassifier) GetFeatureImportances

func (dt *DecisionTreeClassifier) GetFeatureImportances() []float64

GetFeatureImportances returns feature importance scores

func (*DecisionTreeClassifier) GetNLeaves

func (dt *DecisionTreeClassifier) GetNLeaves() int

GetNLeaves returns the number of leaf nodes

func (*DecisionTreeClassifier) GetParams

func (dt *DecisionTreeClassifier) GetParams() map[string]interface{}

GetParams returns the model hyperparameters

func (*DecisionTreeClassifier) Predict

func (dt *DecisionTreeClassifier) Predict(X mat.Matrix) (mat.Matrix, error)

Predict makes predictions for input data

func (*DecisionTreeClassifier) PredictProba

func (dt *DecisionTreeClassifier) PredictProba(X mat.Matrix) (mat.Matrix, error)

PredictProba returns probability estimates for each class

func (*DecisionTreeClassifier) Score

func (dt *DecisionTreeClassifier) Score(X, y mat.Matrix) float64

Score returns the mean accuracy on the given test data

func (*DecisionTreeClassifier) SetParams

func (dt *DecisionTreeClassifier) SetParams(params map[string]interface{}) error

SetParams sets the model hyperparameters

type DecisionTreeClassifierOption

type DecisionTreeClassifierOption func(*DecisionTreeClassifier)

DecisionTreeClassifierOption is a functional option

func WithCriterion

func WithCriterion(criterion string) DecisionTreeClassifierOption

WithCriterion sets the splitting criterion

func WithDTRandomState

func WithDTRandomState(seed int64) DecisionTreeClassifierOption

WithDTRandomState sets the random seed

func WithMaxDepth

func WithMaxDepth(depth int) DecisionTreeClassifierOption

WithMaxDepth sets the maximum tree depth

func WithMinSamplesLeaf

func WithMinSamplesLeaf(n int) DecisionTreeClassifierOption

WithMinSamplesLeaf sets minimum samples in leaf

func WithMinSamplesSplit

func WithMinSamplesSplit(n int) DecisionTreeClassifierOption

WithMinSamplesSplit sets minimum samples to split

type TreeNode

type TreeNode struct {
	IsLeaf       bool      // Whether this is a leaf node
	Feature      int       // Feature index for split (internal nodes)
	Threshold    float64   // Threshold value for split (internal nodes)
	Left         *TreeNode // Left child (values <= threshold)
	Right        *TreeNode // Right child (values > threshold)
	Value        float64   // Predicted value (leaf nodes - regression)
	ClassCounts  []int     // Class counts (leaf nodes - classification)
	PredictClass int       // Predicted class (leaf nodes - classification)
	Impurity     float64   // Node impurity
	NSamples     int       // Number of samples at this node
	Depth        int       // Depth of this node in the tree
}

TreeNode represents a node in the decision tree

Jump to

Keyboard shortcuts

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