cluster

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: 6 Imported by: 0

Documentation

Overview

Package cluster provides clustering algorithms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KMeans

type KMeans struct {
	// NClusters is the number of clusters (K)
	NClusters int

	// MaxIter is the maximum number of iterations
	MaxIter int

	// Tol is the convergence tolerance
	Tol float64

	// Init specifies initialization method: "k-means++" or "random"
	Init string

	// Seed for random number generator
	Seed int64
	// contains filtered or unexported fields
}

KMeans implements the K-Means clustering algorithm. Partitions data into K clusters by minimizing within-cluster variance.

func NewKMeans

func NewKMeans(nClusters int, maxIter int, init string, seed int64) *KMeans

NewKMeans creates a new K-Means clusterer.

func (*KMeans) Centers

func (km *KMeans) Centers() [][]float64

Centers returns the cluster centroids.

func (*KMeans) Fit

func (km *KMeans) Fit(X *dataframe.DataFrame) error

Fit trains the K-Means model on data X.

func (*KMeans) FitPredict

func (km *KMeans) FitPredict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)

FitPredict fits the model and returns cluster labels.

func (*KMeans) Inertia

func (km *KMeans) Inertia() float64

Inertia returns the sum of squared distances to cluster centers.

func (*KMeans) NIter

func (km *KMeans) NIter() int

NIter returns the number of iterations performed.

func (*KMeans) Predict

func (km *KMeans) Predict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)

Predict assigns cluster labels to new data.

Jump to

Keyboard shortcuts

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