knn

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EuclideanDistance

func EuclideanDistance(p1, p2 []float64) float64

EuclideanDistance calculates euclidean distance between two points

Types

type Classifier

type Classifier struct {
	KNN       *KNN
	VectorMap *wordvectors.VectorMap
	K         int
}

Classifier is a K-Nearest Neighbors classifier

func Load

func Load(directory string) (classifier *Classifier, err error)

func NewClassifier

func NewClassifier(wordVecConfig wordvectors.Config, params map[string]interface{}) *Classifier

NewClassifier creates a KNN classifier with truncate and file data

func NewClassifierFromFile

func NewClassifierFromFile(name string) (*Classifier, error)

func (*Classifier) Learn

func (c *Classifier) Learn(texts dataset.DataSet, pipe *pipeline.Config) float32

Learn takes the training texts and trains the K-Nearest Neighbors classifier

func (*Classifier) Predict

func (c *Classifier) Predict(text string, pipe *pipeline.Config) (predictedClass string, proba float32)

Predict predict a class for a given text

func (*Classifier) Save

func (c *Classifier) Save(directory string) error

Save persists the model to a file

func (*Classifier) SaveToFile

func (c *Classifier) SaveToFile(name string) error

type KNN

type KNN struct {
	K      int
	Data   [][]float64
	Labels []string
}

KNN main structure

func NewKNNClassifierFromFile

func NewKNNClassifierFromFile(name string) (*KNN, error)

func (*KNN) PredictMany

func (knn *KNN) PredictMany(x [][]float64) (predictedLabels []string, probabilities []float64)

PredictMany performs a classification on multiple input vectors

func (*KNN) PredictOne

func (knn *KNN) PredictOne(x []float64) (predictedLabel string, probability float64)

PredictOne performs a classification on one input vector

func (*KNN) SaveToFile

func (knn *KNN) SaveToFile(name string) error

type Parameters

type Parameters struct {
	K int `mapstructure:"k"`
}

Parameters represents the model hyperparameters

Jump to

Keyboard shortcuts

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