knn

package
v0.0.0-...-4fa0698 Latest Latest
Warning

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

Go to latest
Published: May 24, 2014 License: MIT Imports: 4 Imported by: 0

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

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.Instances
	DistanceFunc      string
	NearestNeighbours int
}

A KNN Classifier. Consists of a data matrix, associated labels in the same order as the matrix, and a distance function. The accepted distance functions at this time are 'euclidean' and 'manhattan'.

func NewKnnClassifier

func NewKnnClassifier(distfunc string, neighbours int) *KNNClassifier

Returns a new classifier

func (*KNNClassifier) Fit

func (KNN *KNNClassifier) Fit(trainingData *base.Instances)

Train stores the training data for llater

func (*KNNClassifier) Predict

func (KNN *KNNClassifier) Predict(what *base.Instances) *base.Instances

func (*KNNClassifier) PredictOne

func (KNN *KNNClassifier) PredictOne(vector []float64) string

Returns a classification for the vector, based on a vector input, using the KNN algorithm. See http://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm.

type KNNRegressor

type KNNRegressor struct {
	base.BaseEstimator
	Values       []float64
	DistanceFunc string
}

A KNN Regressor. 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

Mints a new classifier.

func (*KNNRegressor) Fit

func (KNN *KNNRegressor) Fit(values []float64, numbers []float64, rows int, cols int)

func (*KNNRegressor) Predict

func (KNN *KNNRegressor) Predict(vector *mat64.Dense, K int) float64

Jump to

Keyboard shortcuts

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