iforest

package
v1.64.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: AGPL-3.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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