utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package utils provides utility functions for outlier detection.

Package utils provides utility functions for outlier detection.

Package utils provides utility functions for outlier detection.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidParameter = errors.New("parameter out of valid range")

ErrInvalidParameter is returned when a parameter is out of valid range

Functions

func Accuracy

func Accuracy(yTrue, yPred []int) float64

Accuracy calculates the accuracy score

func ApplyStandardize

func ApplyStandardize(X [][]float64, means, stds []float64) [][]float64

ApplyStandardize applies standardization using pre-computed mean and std

func ArgMaxN

func ArgMaxN(values []float64, n int) []int

ArgMaxN returns the indices of top n elements in descending order

func ArgMinN

func ArgMinN(values []float64, n int) []int

ArgMinN returns the indices of bottom n elements in ascending order

func BalancedAccuracy

func BalancedAccuracy(yTrue, yPred []int) float64

BalancedAccuracy calculates the balanced accuracy score

func CheckParameter

func CheckParameter(param, low, high float64, includeLow, includeHigh bool) error

CheckParameter checks if a parameter is within the specified range

func ConfusionMatrix

func ConfusionMatrix(yTrue, yPred []int) [4]int

ConfusionMatrix calculates the confusion matrix Returns [TN, FP, FN, TP]

func F1Score

func F1Score(yTrue, yPred []int) float64

F1Score calculates the F1 score

func GenerateData

func GenerateData(opts *GenerateDataOptions) (XTrain, XTest [][]float64, yTrain, yTest []float64)

GenerateData generates synthesized data for outlier detection testing. Normal data is generated by a multivariate Gaussian distribution and outliers are generated by a uniform distribution.

func GenerateDataClusters

func GenerateDataClusters(nTrain, nFeatures, nClusters int, contamination float64, rng *rand.Rand) ([][]float64, []float64)

GenerateDataClusters generates clustered data with outliers

func GetLabelN

func GetLabelN(yTrue, yPred []float64, n int) []int

GetLabelN returns binary labels by assigning 1 to top n outlier scores

func GetOptimalNBins

func GetOptimalNBins(data []float64) int

GetOptimalNBins calculates the optimal number of bins using Birge-Rozenblac method

func GetOutliersInliers

func GetOutliersInliers(X [][]float64, y []float64) (XOutliers, XInliers [][]float64)

GetOutliersInliers separates inliers from outliers

func InvertOrder

func InvertOrder(scores []float64) []float64

InvertOrder inverts the order of scores

func MaxFloat

func MaxFloat(data []float64) float64

MaxFloat returns the maximum of a slice of floats

func Mean

func Mean(data []float64) float64

Mean returns the mean of a slice of floats

func MeanAbsoluteError

func MeanAbsoluteError(yTrue, yPred []float64) float64

MeanAbsoluteError calculates the mean absolute error

func MeanSquaredError

func MeanSquaredError(yTrue, yPred []float64) float64

MeanSquaredError calculates the mean squared error

func MinFloat

func MinFloat(data []float64) float64

MinFloat returns the minimum of a slice of floats

func Percentile

func Percentile(data []float64, p float64) float64

Percentile calculates the p-th percentile of the data

func PrecisionAtN

func PrecisionAtN(yTrue []float64, yScores []float64, n int) float64

PrecisionAtN calculates precision at rank n

func PrecisionScore

func PrecisionScore(yTrue, yPred []int) float64

PrecisionScore calculates the precision score

func ROCAUCScore

func ROCAUCScore(yTrue []float64, yScores []float64) float64

ROCAUCScore calculates the Area Under the Receiver Operating Characteristic Curve

func RecallScore

func RecallScore(yTrue, yPred []int) float64

RecallScore calculates the recall score

func RootMeanSquaredError

func RootMeanSquaredError(yTrue, yPred []float64) float64

RootMeanSquaredError calculates the root mean squared error

func ScoreToLabel

func ScoreToLabel(scores []float64, outliersFraction float64) []int

ScoreToLabel converts raw outlier scores to binary labels

func Standardize

func Standardize(X [][]float64) ([][]float64, []float64, []float64)

Standardize performs Z-score normalization on data

func StdDev

func StdDev(data []float64) float64

StdDev returns the standard deviation of a slice of floats

func Sum

func Sum(data []float64) float64

Sum returns the sum of a slice of floats

func TrainTestSplit

func TrainTestSplit(X [][]float64, y []float64, testSize float64, rng *rand.Rand) (XTrain, XTest [][]float64, yTrain, yTest []float64)

TrainTestSplit splits data into training and testing sets

func Variance

func Variance(data []float64) float64

Variance returns the variance of a slice of floats

Types

type GenerateDataOptions

type GenerateDataOptions struct {
	NTrain        int
	NTest         int
	NFeatures     int
	Contamination float64
	TrainOnly     bool
	Offset        float64
	RandomState   *rand.Rand
}

GenerateDataOptions holds options for data generation

func DefaultGenerateDataOptions

func DefaultGenerateDataOptions() *GenerateDataOptions

DefaultGenerateDataOptions returns default options for data generation

Jump to

Keyboard shortcuts

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