ml

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(actual Datum, expected Datum) (bool, error)

Match returns true if the Datum' are the same, otherwise false.

An error is returned if the Datum' have different lengths.

func Split

func Split(samples []Sample, split float64) ([]Sample, []Sample)

Split can be used to split training ang test data by a percentage.

The resulting arrays are pseudorandom in composition; not consistent
between runs.

func Test

func Test(cls Predictor, testData []Sample) (float64, error)

Test runs test samples against a trained predictor to see how accurate it is.

The result is percentage accuracy.

Types

type Datum

type Datum []float64

Datum is an array of floating point values, used as the input to a ML model.

func InitializeKMeans

func InitializeKMeans(input []Datum, k int) ([]Datum, error)

InitializeKMeans implements the init step for KMeans++ (at least,

 it implements whatever this GeeksForGeeks article says:
	https://www.geeksforgeeks.org/ml-k-means-algorithm/)

func (Datum) AsCSV

func (d Datum) AsCSV() string

AsCSV maps a datum to a CSV line for ML purposes.

type KNNClassifier

type KNNClassifier struct {
	K      uint
	Points []Sample
}

KNNClassifier defines a KNN model for classifying input against known

samples. All training data is saved in the model, so be wary of size and
performance for large training sets.

func LoadKNNClassifier

func LoadKNNClassifier(path string) (*KNNClassifier, error)

LoadKNNClassifier is a convenience method for loading a save KNNClassifier model.

func NewKNNClassifier

func NewKNNClassifier(k uint) *KNNClassifier

NewKNNClassifier constructs an untrained KNNClassifier.

func (*KNNClassifier) Fit

func (kc *KNNClassifier) Fit(samples []Sample) error

Fit trains a KNNClassifier using given Samples.

func (*KNNClassifier) Predict

func (kc *KNNClassifier) Predict(input []Datum) ([]Datum, error)

Predict finds the "closest" known Sample for each given Datum, and returns

the associated Sample output.

func (*KNNClassifier) PredictSingle

func (kc *KNNClassifier) PredictSingle(input Datum) (Datum, error)

PredictSingle finds the "closest" known Sample the given Datum, and returns

the associated output.

func (*KNNClassifier) Save

func (kc *KNNClassifier) Save(path string) error

Save saves a KNNClassifier to disk.

type Predictor

type Predictor interface {
	Fit(samples []Sample) error
	Predict(input []Datum) ([]Datum, error)
	PredictSingle(input Datum) (Datum, error)
	Save(path string) error
}

Predictor defines the methods necessary to Train, Predict, and Save a

ML model. The design is influence by scikit-learn (https://scikit-learn.org/stable/about.html).

type Sample

type Sample struct {
	Input  Datum
	Output Datum
}

Sample holds the input of a model to its expected output.

type Transformer

type Transformer interface {
	Fit(samples []Datum) error
	Transform(input []Datum) ([]Datum, error)
	TransformSingle(input Datum) (Datum, error)
	Save(path string) error
}

Transformer defines the methods to Train, Predict, and Save a pre-processing

model. The key difference from a Predictor is that it doesn't fit against
Samples, but just raw input Datum.

Directories

Path Synopsis
train

Jump to

Keyboard shortcuts

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