Online algorithms for machine learning implemented in Golang.
For installation, execute the following command:
$ go get github.com/mitsuse/olive
Olive uses the following libraries:
Olive provides learning algorithms as follow:
- Perceptron
Olive provides an implementation of multi-class linear classifier.
Call classifier.New
with the size of classes and the dimensions of features.
classSize, dimensions := 4, 8
c := classifier.New(classSize, dimensions)
Classify an instance by applying (*Classifier).Classify
to its feature matrix.
The feature matrix is typed as Matrix
of mitsuse/matrix-go
.
features := dense.New(classSize, dimensions)(
0, 0, 1, 1, 0.5, 0.1, -2, 3, 0,
)
class := c.Classify(features)
Learner such as perceptron can update classifier by using the given training data.
classSize, dimensions := 2, 6
iterations := 3
feature := dense.New(1, dimensions)
// training data (pairs of a feature vector and its class).
instances := []*olive.Instance{
olive.NewInstance(feature(1, 1, 1, 0, 0, 0), 0),
olive.NewInstance(feature(1, 1, 0, 0, 0, 0), 0),
olive.NewInstance(feature(0, 0, 0, 1, 1, 1), 1),
olive.NewInstance(feature(0, 0, 0, 0, 1, 1), 1),
}
// Initialize a learner
learner := perceptron.New(iterations)
// Update the given classifier with the training data and return an updated classifier.
c := learner.Learn(classifier.New(classSize, dimensions), instances)
Please read LICENSE.txt.