You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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"
)
funcmain() {
// 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", true)
iferr!=nil {
panic(err)
}
// Print a pleasant summary of your data.fmt.Println(rawData)
//Initialises a new KNN classifiercls:=knn.NewKnnClassifier("euclidean", "linear", 2)
//Do a training-test splittrainData, testData:=base.InstancesTrainTestSplit(rawData, 0.50)
cls.Fit(trainData)
//Calculates the Euclidean distance and returns the most popular labelpredictions, err:=cls.Predict(testData)
iferr!=nil {
panic(err)
}
// Prints precision/recall metricsconfusionMat, err:=evaluation.GetConfusionMatrix(testData, predictions)
iferr!=nil {
panic(fmt.Sprintf("Unable to get confusion matrix: %s", err.Error()))
}
fmt.Println(evaluation.GetSummary(confusionMat))
}