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)
|
2018-06-16 22:30:19 +08:00
|
|
|
[](https://travis-ci.org/sjwhitworth/golearn)<br>
|
|
|
|
[](https://codecov.io/gh/sjwhitworth/golearn)
|
2014-05-01 08:24:22 +01:00
|
|
|
|
2014-08-10 23:03:01 +01:00
|
|
|
[](https://www.gittip.com/sjwhitworth/)
|
2014-08-10 23:00:40 +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
|
|
|
|
=======
|
|
|
|
|
2014-07-20 08:58:59 -07:00
|
|
|
See [here](https://github.com/sjwhitworth/golearn/wiki/Installation) for installation instructions.
|
2014-05-01 11:59:24 +08:00
|
|
|
|
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-07-22 15:40:39 +00:00
|
|
|
```go
|
2014-12-21 19:09:43 -08:00
|
|
|
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.
|
2014-12-22 08:32:14 -08:00
|
|
|
rawData, err := base.ParseCSVToInstances("datasets/iris.csv", false)
|
2014-12-21 19:09:43 -08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print a pleasant summary of your data.
|
|
|
|
fmt.Println(rawData)
|
|
|
|
|
|
|
|
//Initialises a new KNN classifier
|
2017-04-17 15:20:31 +08:00
|
|
|
cls := knn.NewKnnClassifier("euclidean", "linear", 2)
|
2014-12-21 19:09:43 -08:00
|
|
|
|
|
|
|
//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
|
2016-10-10 19:45:20 -07:00
|
|
|
predictions, err := cls.Predict(testData)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-12-21 19:09:43 -08:00
|
|
|
|
|
|
|
// 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))
|
|
|
|
}
|
2014-05-17 21:17:57 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
Iris-virginica 28 2 56 0.9333 0.9333 0.9333
|
|
|
|
Iris-setosa 29 0 59 1.0000 1.0000 1.0000
|
2014-07-22 15:40:39 +00:00
|
|
|
Iris-versicolor 27 2 57 0.9310 0.9310 0.9310
|
2014-05-17 21:17:57 +01:00
|
|
|
Overall accuracy: 0.9545
|
|
|
|
```
|
|
|
|
|
|
|
|
Examples
|
|
|
|
========
|
|
|
|
|
|
|
|
GoLearn comes with practical examples. Dive in and see what is going on.
|
|
|
|
|
2014-07-22 15:40:39 +00:00
|
|
|
```bash
|
|
|
|
cd $GOPATH/src/github.com/sjwhitworth/golearn/examples/knnclassifier
|
2014-05-01 11:59:24 +08:00
|
|
|
go run knnclassifier_iris.go
|
2014-07-22 15:40:39 +00:00
|
|
|
```
|
|
|
|
```bash
|
|
|
|
cd $GOPATH/src/github.com/sjwhitworth/golearn/examples/instances
|
2014-05-17 21:17:57 +01:00
|
|
|
go run instances.go
|
2014-05-01 11:59:24 +08:00
|
|
|
```
|
2014-07-22 15:40:39 +00:00
|
|
|
```bash
|
|
|
|
cd $GOPATH/src/github.com/sjwhitworth/golearn/examples/trees
|
|
|
|
go run trees.go
|
|
|
|
```
|
2014-05-01 11:59:24 +08:00
|
|
|
|
2017-04-07 09:34:49 +08:00
|
|
|
Docs
|
|
|
|
====
|
|
|
|
|
2017-04-07 09:54:52 +08:00
|
|
|
* [English](https://github.com/sjwhitworth/golearn/wiki)
|
2017-06-16 16:33:50 +08:00
|
|
|
* [中文文档(简体)](doc/zh_CN/Home.md)
|
|
|
|
* [中文文档(繁体)](doc/zh_TW/Home.md)
|
2017-04-07 09:34:49 +08:00
|
|
|
|
2014-04-30 08:22:58 +01:00
|
|
|
Join the team
|
2014-04-28 08:11:40 +01:00
|
|
|
=============
|
|
|
|
|
2015-05-06 07:39:21 +01:00
|
|
|
Please send me a mail at stephenjameswhitworth@gmail.com
|