kmeans

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EuclideanDistance is one of the common distance measurement.
	EuclideanDistance = func(a, b []float64) float64 {
		var (
			s, t float64
		)

		for i := range a {
			t = a[i] - b[i]
			s += t * t
		}

		return math.Sqrt(s)
	}

	// EuclideanDistanceSquared is one of the common distance measurement.
	EuclideanDistanceSquared = func(a, b []float64) float64 {
		var (
			s, t float64
		)

		for i := range a {
			t = a[i] - b[i]
			s += t * t
		}

		return s
	}
)

Functions

This section is empty.

Types

type Dataset

type Dataset [][]float64

type DistanceFunc

type DistanceFunc func([]float64, []float64) float64

DistanceFunc represents a function for measuring distance between n-dimensional vectors.

type Model

type Model struct {
	// contains filtered or unexported fields
}

func (*Model) Cluster

func (m *Model) Cluster(i int) []float64

Cluster returns cluster at position i.

func (*Model) Guesses

func (m *Model) Guesses() []int

Guesses returns mapping from data point indices to cluster numbers.

func (*Model) Iter

func (m *Model) Iter() int

Iter returns model number of iterations.

func (*Model) Predict

func (m *Model) Predict(p []float64) int

Predict returns number of cluster to which the observation would be assigned.

type Trainer

type Trainer struct {
	// contains filtered or unexported fields
}

func NewTrainer

func NewTrainer(k int, options ...TrainerOption) Trainer

NewTrainer create new Trainer.

func (Trainer) Fit

func (t Trainer) Fit(data Dataset) *Model

Fit create and train the *Model.

type TrainerOption

type TrainerOption func(*Trainer)

func WithConcurrency

func WithConcurrency(c int) TrainerOption

func WithDeltaThreshold

func WithDeltaThreshold(delta float64) TrainerOption

func WithDistanceFunc

func WithDistanceFunc(fn DistanceFunc) TrainerOption

func WithMaxIterations

func WithMaxIterations(i int) TrainerOption

Jump to

Keyboard shortcuts

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