knn

package
v0.0.0-...-b69056f Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package knn contains structures and functions that help implemnt the K-Nearest Neighbors algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Classify

func Classify(numNeighbors int, point interface{}, training DataSet, df DistanceFunc, cf ClassificationFunc) interface{}

Classify is the main entry point for the KNN processing for an individual piece of data that needs to be classified. It requires the number of neighbors needed for classification, the data point being classified, the training data used to perform the classification, a method for calculating distance between neighbors, and a method for converting between classification types.

func KNN

func KNN(numNeighbors int, testing, training DataSet, df DistanceFunc, cf ClassificationFunc) []interface{}

KNN performs K-Nearest Neighbors analysis on a testing data set given a training data set.

Types

type ClassificationFunc

type ClassificationFunc func(t interface{}) interface{}

ClassificationFunc returns the classification label for a given neighbor.

type DataSet

type DataSet interface {
	Iterate() <-chan interface{}
}

DataSet provides the classifer the ability to iterate over data being used for training and/or classification.

type DistanceFunc

type DistanceFunc func(a, b interface{}) float64

DistanceFunc is responsible for calculaing the distance between two neighbors.

type TopNList

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

TopNList is a data structure that stores the a classification target's top-N neighbors weighted by minium distance.

func NewTopNList

func NewTopNList(n int) (TopNList, error)

NewTopNList creates a new TopNList that will retain up to n neighbors, keep the closest neighbors.

func (*TopNList) Add

func (l *TopNList) Add(dist float64, neighbor interface{})

Add adds a neighbor to the TopNList if the neighbor is one of the n-closest neighbors.

func (*TopNList) GetClassification

func (l *TopNList) GetClassification(cf ClassificationFunc) interface{}

GetClassification polls the top-n neighbors for their classification and then returns the most common classification found among the neighbors. The ClassificationExtractor is used to extract the classification from the neighbor.

func (*TopNList) Iterate

func (l *TopNList) Iterate() <-chan interface{}

Iterate allows looping over the neighbors contained in the TopNList.

Jump to

Keyboard shortcuts

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