Documentation ¶
Overview ¶
Package knn implements a K Nearest Neighbors object, capable of both classification and regression. It accepts data in the form of a slice of float64s, which are then reshaped into a X by Y matrix.
Index ¶
- type KNNClassifier
- func (KNN *KNNClassifier) Fit(trainingData base.FixedDataGrid) error
- func (KNN *KNNClassifier) GetMetadata() base.ClassifierMetadataV1
- func (KNN *KNNClassifier) Load(filePath string) error
- func (KNN *KNNClassifier) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
- func (KNN *KNNClassifier) Predict(what base.FixedDataGrid) (base.FixedDataGrid, error)
- func (KNN *KNNClassifier) Save(filePath string) error
- func (KNN *KNNClassifier) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
- func (KNN *KNNClassifier) String() string
- type KNNRegressor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KNNClassifier ¶
type KNNClassifier struct { base.BaseEstimator TrainingData base.FixedDataGrid DistanceFunc string Algorithm string NearestNeighbours int AllowOptimisations bool Weighted bool }
A KNNClassifier consists of a data matrix, associated labels in the same order as the matrix, searching algorithm, and a distance function. The accepted distance functions at this time are 'euclidean', 'manhattan', and 'cosine'. The accepted searching algorithm here are 'linear', and 'kdtree'. Optimisations only occur when things are identically group into identical AttributeGroups, which don't include the class variable, in the same order. Using weighted KNN when Weighted set to be true (default: false).
func NewKnnClassifier ¶
func NewKnnClassifier(distfunc, algorithm string, neighbours int) *KNNClassifier
NewKnnClassifier returns a new classifier
func ReloadKNNClassifier ¶
func ReloadKNNClassifier(filePath string) (*KNNClassifier, error)
ReloadKNNClassifier reloads a KNNClassifier when it's the only thing in an output file.
func (*KNNClassifier) Fit ¶
func (KNN *KNNClassifier) Fit(trainingData base.FixedDataGrid) error
Fit stores the training data for later
func (*KNNClassifier) GetMetadata ¶
func (KNN *KNNClassifier) GetMetadata() base.ClassifierMetadataV1
GetMetadata returns required serialization information for this classifier
func (*KNNClassifier) Load ¶
func (KNN *KNNClassifier) Load(filePath string) error
Load reloads a given KNN classifier when it's the only thing in the output file.
func (*KNNClassifier) LoadWithPrefix ¶
func (KNN *KNNClassifier) LoadWithPrefix(reader *base.ClassifierDeserializer, prefix string) error
LoadWithPrefix reloads a given KNN classifier when it's part of another file.
func (*KNNClassifier) Predict ¶
func (KNN *KNNClassifier) Predict(what base.FixedDataGrid) (base.FixedDataGrid, error)
Predict returns a classification for the vector, based on a vector input, using the KNN algorithm.
func (*KNNClassifier) Save ¶
func (KNN *KNNClassifier) Save(filePath string) error
Save outputs a given KNN classifier.
func (*KNNClassifier) SaveWithPrefix ¶
func (KNN *KNNClassifier) SaveWithPrefix(writer *base.ClassifierSerializer, prefix string) error
SaveWithPrefix outputs KNN as part of another file.
func (*KNNClassifier) String ¶
func (KNN *KNNClassifier) String() string
type KNNRegressor ¶
type KNNRegressor struct { base.BaseEstimator Values []float64 DistanceFunc string }
A KNNRegressor consists of a data matrix, associated result variables in the same order as the matrix, and a name.
func NewKnnRegressor ¶
func NewKnnRegressor(distfunc string) *KNNRegressor
NewKnnRegressor mints a new classifier.