2013-12-26 17:07:24 +00:00
|
|
|
GoLearn
|
2013-12-26 13:06:55 +00:00
|
|
|
=======
|
|
|
|
|
2014-05-04 09:31:31 +01:00
|
|
|
<img src="http://talks.golang.org/2013/advconc/gopherhat.jpg" width=125><br>
|
2014-05-31 10:52:17 +03:00
|
|
|
[](https://godoc.org/github.com/sjwhitworth/golearn)
|
|
|
|
[](https://travis-ci.org/sjwhitworth/golearn)<br>
|
2014-05-01 08:24:22 +01:00
|
|
|
|
2014-05-17 21:17:57 +01:00
|
|
|
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.
|
2014-01-04 11:12:06 +00:00
|
|
|
|
2014-05-03 18:38:20 +01:00
|
|
|
twitter: [@golearn_ml](http://www.twitter.com/golearn_ml)
|
|
|
|
|
2014-05-01 11:59:24 +08:00
|
|
|
Install
|
|
|
|
=======
|
|
|
|
|
|
|
|
```
|
|
|
|
go get github.com/sjwhitworth/golearn
|
|
|
|
cd src/github.com/sjwhitworth/golearn
|
|
|
|
go get ./...
|
|
|
|
```
|
|
|
|
|
2014-05-17 21:17:57 +01:00
|
|
|
Getting Started
|
2014-05-01 11:59:24 +08:00
|
|
|
=======
|
|
|
|
|
2014-05-17 21:19:31 +01:00
|
|
|
Data are loaded in as Instances. You can then perform matrix like operations on them, and pass them to estimators.
|
2014-05-17 21:20:34 +01:00
|
|
|
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.
|
2014-05-17 21:19:18 +01:00
|
|
|
|
2014-05-17 21:17:57 +01:00
|
|
|
```
|
|
|
|
// 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.
|
|
|
|
data, err := base.ParseCSVToInstances("datasets/iris_headers.csv", true)
|
|
|
|
|
|
|
|
// Print a pleasant summary of your data.
|
|
|
|
fmt.Println(data)
|
|
|
|
|
|
|
|
// Split your dataframe into a training set, and a test set, with an 80/20 proportion.
|
|
|
|
trainTest := base.InstancesTrainTestSplit(rawData, 0.8)
|
|
|
|
trainData := trainTest[0]
|
|
|
|
testData := trainTest[1]
|
|
|
|
|
|
|
|
// Instantiate a new KNN classifier. Euclidean distance, with 2 neighbours.
|
|
|
|
cls := knn.NewKnnClassifier("euclidean", 2)
|
|
|
|
|
|
|
|
// Fit it on your training data.
|
|
|
|
cls.Fit(trainData)
|
|
|
|
|
|
|
|
// Get your predictions against test instances.
|
|
|
|
predictions := cls.Predict(testData)
|
|
|
|
|
|
|
|
// Print a confusion matrix with precision and recall metrics.
|
|
|
|
confusionMat := evaluation.GetConfusionMatrix(testData, predictions)
|
|
|
|
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.
|
|
|
|
|
2014-05-01 11:59:24 +08:00
|
|
|
```
|
|
|
|
cd examples/
|
|
|
|
go run knnclassifier_iris.go
|
2014-05-17 21:17:57 +01:00
|
|
|
go run instances.go
|
2014-05-01 11:59:24 +08:00
|
|
|
```
|
|
|
|
|
2014-04-30 08:22:58 +01:00
|
|
|
Join the team
|
2014-04-28 08:11:40 +01:00
|
|
|
=============
|
|
|
|
|
2014-05-17 21:17:57 +01:00
|
|
|
Please send me a mail at stephen dot whitworth at hailocab dot com.
|