Documentation ¶
Overview ¶
The cluster package contains code for various clustering algorithms and other related functions needed to run them.
As of now, the list of functionality supported is Principal Component Analysis, KMeans clustering, Spectral Clustering, and generating scatterplots for labeled data.
Index ¶
- func Covariance(data [][]float64, rowvar bool) ([][]float64, error)
- func EigenSym(data [][]float64) ([]float64, [][]float64, error)
- func Euclidean(point []float64, data [][]float64) []float64
- func PCA(data [][]float64, n int) ([][]float64, error)
- func ScatterPlot2DimenData(data [][]float64, label []string, params []string) error
- func Spectral(data [][]float64, radius float64) ([]string, error)
- type KMeans
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Covariance ¶
Covariance returns the covariance matrix of data. If `rowvar` is true, the data is treated with the variables being arranged via rows. It returns an error if data dimensions are inconsistent/empty.
func EigenSym ¶
EigenSym returns the eigenvalues and eigenvectors of a real symmetric matrix. It returns an error if data dimensions are inconsistent/empty or if it fails to factorize
func Euclidean ¶
Euclidean returns all the euclidean distances from point to each coordinate in data
func PCA ¶
PCA performs principal component analysis on `data` and reduces dimensionality to `n` dimensions. It assumes that the variable data is arranged via columns. It returns the reduced data. It returns an error if data dimensions are inconsistent/empty or if there are more variables than n.
func ScatterPlot2DimenData ¶
ScatterPlot2DimenData generates a scatterplot using Go's plotter package. `Data` provides the points on the plot, `label` contains the label for each point, `params` consist of the plot's parameters such as output directory, plot title, and axis names. It returns an error if any string params are provided incorrectly.
func Spectral ¶
Spectral performs spectral clustering on `data` and returns the classified labels for each point. Spectral clustering partitions the data into 2 clusters. `radius` determines the connectivity of each point. It returns an error if eigenvectors fail to be generated from the Laplacian matrix.
Types ¶
type KMeans ¶
type KMeans struct { CENTROIDS [][]float64 // contains filtered or unexported fields }
KMeans represents a classification model utilizing K-Means clustering
func NewKMeans ¶
NewKMeans creates a new K-Means model with `n` clusters. `Max_eps` represents the maximum amount of episodes or iterations the model will train on until convergence.
func (*KMeans) Evaluate ¶
Evaluate takes in `data` and classifies it according to the trained K-Means model. It returns the data along with the centroid points with its correlated labels. An error is returned if the model was not yet trained.