models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package models provides machine learning algorithms and utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accuracy

func Accuracy(yTrue, yPred *seriesPkg.Series[any]) float64

Accuracy calculates the accuracy score (correct predictions / total predictions).

func AdjustedR2

func AdjustedR2(yTrue, yPred *seriesPkg.Series[any], nFeatures int) float64

AdjustedR2 calculates the adjusted R² score.

func ConfusionMatrix

func ConfusionMatrix(yTrue, yPred *seriesPkg.Series[any]) [][]int

ConfusionMatrix computes the confusion matrix. Returns a 2D slice where cm[i][j] is the count of samples with true label i and predicted label j.

func F1Score

func F1Score(yTrue, yPred *seriesPkg.Series[any], average string) float64

F1Score calculates the F1 score (harmonic mean of precision and recall).

func MAE

func MAE(yTrue, yPred *seriesPkg.Series[any]) float64

MAE calculates the Mean Absolute Error.

func MSE

func MSE(yTrue, yPred *seriesPkg.Series[any]) float64

MSE calculates the Mean Squared Error.

func Precision

func Precision(yTrue, yPred *seriesPkg.Series[any], average string) float64

Precision calculates the precision score. average: "binary" (for binary classification), "micro", "macro", "weighted"

func R2Score

func R2Score(yTrue, yPred *seriesPkg.Series[any]) float64

R2Score calculates the R² coefficient of determination.

func RMSE

func RMSE(yTrue, yPred *seriesPkg.Series[any]) float64

RMSE calculates the Root Mean Squared Error.

func Recall

func Recall(yTrue, yPred *seriesPkg.Series[any], average string) float64

Recall calculates the recall score.

Types

type ClassificationReport

type ClassificationReport struct {
	Precision map[string]float64
	Recall    map[string]float64
	F1Score   map[string]float64
	Support   map[string]int
}

ClassificationReport contains precision, recall, F1, and support for each class.

func ClassificationReportFunc

func ClassificationReportFunc(yTrue, yPred *seriesPkg.Series[any]) ClassificationReport

ClassificationReportFunc generates a comprehensive classification report.

type Classifier

type Classifier interface {
	Model

	// PredictProba returns class probabilities for each sample
	PredictProba(X *dataframe.DataFrame) (*dataframe.DataFrame, error)
}

Classifier adds classification-specific methods.

type Clusterer

type Clusterer interface {
	// Fit trains the clustering model on data X
	Fit(X *dataframe.DataFrame) error

	// Predict assigns cluster labels to new data X
	Predict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)

	// FitPredict fits the model and returns cluster labels
	FitPredict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)
}

Clusterer is the interface for unsupervised clustering models.

type Model

type Model interface {
	// Fit trains the model on data X with target y
	Fit(X *dataframe.DataFrame, y *seriesPkg.Series[any]) error

	// Predict makes predictions on new data X
	Predict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)
}

Model is the base interface for all ML models.

type Regressor

type Regressor interface {
	Model
}

Regressor is a marker interface for regression models.

type TrainTestSplit

type TrainTestSplit struct {
	XTrain *dataframe.DataFrame
	XTest  *dataframe.DataFrame
	YTrain *seriesPkg.Series[any]
	YTest  *seriesPkg.Series[any]
}

TrainTestSplit contains the split datasets.

func TrainTestSplitFunc

func TrainTestSplitFunc(X *dataframe.DataFrame, y *seriesPkg.Series[any], testSize float64, shuffle bool, stratify string, seed ...int64) (TrainTestSplit, error)

TrainTestSplitFunc splits data into training and test sets. X: feature DataFrame y: target Series testSize: fraction of data to use for testing (0-1) shuffle: whether to shuffle data before splitting stratify: column name to stratify by (maintains class proportions) seed: random seed (optional, defaults to time-based)

type Transformer

type Transformer interface {
	// Fit learns the transformation from data X
	Fit(X *dataframe.DataFrame) error

	// Transform applies the learned transformation to X
	Transform(X *dataframe.DataFrame) (*dataframe.DataFrame, error)

	// FitTransform fits and transforms in one step
	FitTransform(X *dataframe.DataFrame) (*dataframe.DataFrame, error)
}

Transformer is the interface for dimensionality reduction and feature extraction.

Directories

Path Synopsis
Package cluster provides clustering algorithms.
Package cluster provides clustering algorithms.
Package crossval provides cross-validation utilities for model evaluation.
Package crossval provides cross-validation utilities for model evaluation.
Package decomposition provides dimensionality reduction algorithms.
Package decomposition provides dimensionality reduction algorithms.
Package linear provides linear regression models.
Package linear provides linear regression models.
Package tree provides decision tree algorithms.
Package tree provides decision tree algorithms.

Jump to

Keyboard shortcuts

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