iforest

package
v1.62.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Column

func Column(matrix [][]float64, columnIndex int) []float64

Column returns a slice containing the specified column from the matrix.

func MinMax

func MinMax(floats []float64) (float64, float64)

MinMax returns the minimum and maximum values from a slice of float64.

func Quantile

func Quantile(numbers []float64, q float64) float64

Quantile computes the q-th quantile (0 <= q <= 1) of a slice of float64 values.

func SampleRows

func SampleRows(matrix [][]float64, size int) [][]float64

SampleRows randomly selects 'size' rows from the matrix.

Types

type DetectionType

type DetectionType string

type IsolationForest

type IsolationForest struct {
	*Options

	Trees []*TreeNode
}

IsolationForest orchestrates anomaly detection using isolation trees

func New

func New() *IsolationForest

New creates an IsolationForest with default options.

func NewWithOptions

func NewWithOptions(options Options) *IsolationForest

NewWithOptions creates an IsolationForest with the specified options.

func (*IsolationForest) BuildTree

func (f *IsolationForest) BuildTree(samples [][]float64, depth int) *TreeNode

BuildTree recursively partitions samples to isolate outliers

func (*IsolationForest) FeatureImportance

func (f *IsolationForest) FeatureImportance(sample []float64) []int

FeatureImportance computes an importance score for each feature

func (*IsolationForest) Fit

func (f *IsolationForest) Fit(samples [][]float64)

Fit constructs isolation trees from a given dataset

func (*IsolationForest) Predict

func (f *IsolationForest) Predict(samples [][]float64) []int

Predict labels samples as outliers (1) or normal (0) based on the detection type

func (*IsolationForest) Score

func (f *IsolationForest) Score(samples [][]float64) []float64

Score computes anomaly scores for each sample

type Options

type Options struct {
	// The anomaly score threshold
	Threshold float64 `json:"threshold"`

	// The proportion of outliers in the dataset
	Proportion float64 `json:"proportion"`

	// The number of trees to build in the forest
	NumTrees int `json:"numTrees"`

	// The sample size for each isolation tree
	SampleSize int `json:"sampleSize"`

	// The maximum depth of each isolation tree
	MaxDepth int `json:"maxDepth"`
}

func (*Options) SetDefaultValues

func (o *Options) SetDefaultValues()

SetDefaultValues applies default settings to unspecified fields

type TreeNode

type TreeNode struct {
	Left       *TreeNode
	Right      *TreeNode
	Size       int
	SplitIndex int
	SplitValue float64
}

func (*TreeNode) FeatureImportance

func (t *TreeNode) FeatureImportance(sample []float64) []int

FeatureImportance calculates how many times each feature index is used during splits for the given sample.

func (*TreeNode) IsLeaf

func (t *TreeNode) IsLeaf() bool

IsLeaf checks if the node is a leaf (no children).

Jump to

Keyboard shortcuts

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