Skip to content
Machine Learning for Go
Go C++ C Other
Branch: master
Clone or download

Latest commit

Sentimentron Merge pull request #240 from yaserazfar/check_unchecked_errors
Add error checking for err variables that were being left unchecked
Latest commit 3e43e74 Dec 30, 2019

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
base Fix for error that happens on Go 1.11 and above Mar 23, 2019
clustering clustering: update to new mat64 API Jun 16, 2019
doc add knn.md and installation.md Apr 21, 2017
ensemble adds error checking for err variable that were being left unchecked Dec 26, 2019
evaluation Fix import cycle Jun 16, 2018
examples add "linear" to NewKnnClassifier Apr 18, 2017
filters Fix go vet complaints Jun 13, 2016
kdtree format Jun 16, 2018
knn Fix for error that happens on Go 1.11 and above Mar 23, 2019
linear_models adds error checking for err variable that were being left unchecked Dec 26, 2019
meta adds error checking for err variable that were being left unchecked Dec 26, 2019
metrics/pairwise metrics: fixing pairwise CloneFrom Jun 18, 2019
naive adds error checking for err variable that were being left unchecked Dec 26, 2019
neural neural: update to new mat64 API Jun 18, 2019
optimisation Hopefully, should build now. Jan 27, 2015
pca Add test cases for C1 Jun 5, 2018
perceptron Rebasing against master Jan 15, 2015
trees Fix for error that happens on Go 1.11 and above Mar 23, 2019
utilities Update gonum to latest version Mar 24, 2018
.gitignore change gonum matrix definitions to match with current gonum version Mar 20, 2019
.travis.yml Drop support for Go 1.8 Mar 23, 2019
Dockerfile add dockerfile Apr 14, 2016
LICENSE.md Adding license Apr 30, 2014
README.md Fix repo info Jun 16, 2018
coverage.sh Update .travis.yml and coverage script Jun 16, 2018
golearn.go Refactored knn May 4, 2014

README.md

GoLearn


GoDoc Build Status
Code Coverage

Support via Gittip

GoLearn is a 'batteries included' machine learning library for Go. Simplicity, paired with customisability, is the goal. We are in active development, and would love comments from users out in the wild. Drop us a line on Twitter.

twitter: @golearn_ml

Install

See here for installation instructions.

Getting Started

Data are loaded in as Instances. You can then perform matrix like operations on them, and pass them to estimators. GoLearn implements the scikit-learn interface of Fit/Predict, so you can easily swap out estimators for trial and error. GoLearn also includes helper functions for data, like cross validation, and train and test splitting.

package main

import (
	"fmt"

	"github.com/sjwhitworth/golearn/base"
	"github.com/sjwhitworth/golearn/evaluation"
	"github.com/sjwhitworth/golearn/knn"
)

func main() {
	// Load in a dataset, with headers. Header attributes will be stored.
	// Think of instances as a Data Frame structure in R or Pandas.
	// You can also create instances from scratch.
	rawData, err := base.ParseCSVToInstances("datasets/iris.csv", false)
	if err != nil {
		panic(err)
	}

	// Print a pleasant summary of your data.
	fmt.Println(rawData)

	//Initialises a new KNN classifier
	cls := knn.NewKnnClassifier("euclidean", "linear", 2)

	//Do a training-test split
	trainData, testData := base.InstancesTrainTestSplit(rawData, 0.50)
	cls.Fit(trainData)

	//Calculates the Euclidean distance and returns the most popular label
	predictions, err := cls.Predict(testData)
	if err != nil {
		panic(err)
	}

	// Prints precision/recall metrics
	confusionMat, err := evaluation.GetConfusionMatrix(testData, predictions)
	if err != nil {
		panic(fmt.Sprintf("Unable to get confusion matrix: %s", err.Error()))
	}
	fmt.Println(evaluation.GetSummary(confusionMat))
}
Iris-virginica	28	2	  56	0.9333	0.9333  0.9333
Iris-setosa	    29	0	  59	1.0000  1.0000	1.0000
Iris-versicolor	27	2	  57	0.9310	0.9310  0.9310
Overall accuracy: 0.9545

Examples

GoLearn comes with practical examples. Dive in and see what is going on.

cd $GOPATH/src/github.com/sjwhitworth/golearn/examples/knnclassifier
go run knnclassifier_iris.go
cd $GOPATH/src/github.com/sjwhitworth/golearn/examples/instances
go run instances.go
cd $GOPATH/src/github.com/sjwhitworth/golearn/examples/trees
go run trees.go

Docs

Join the team

Please send me a mail at stephenjameswhitworth@gmail.com

You can’t perform that action at this time.