Coder Social home page Coder Social logo

golearn's Introduction

GoLearn


GoDoc Build Status

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 [email protected]

golearn's People

Contributors

sentimentron avatar sjwhitworth avatar frozenkp avatar amitkgupta avatar lazywei avatar njern avatar tncardoso avatar ifesdjeen avatar npbool avatar nbsantos avatar meirwah avatar penberg avatar etiennebruines avatar mtchavez avatar xn0px90 avatar hpxro7 avatar grahamannett avatar albrow avatar vineethrp avatar lupino avatar dhrp avatar saromanov avatar rschmukler avatar nairboon avatar pontusmelke avatar defcube avatar nickpoorman avatar linkerlin avatar okjake avatar p1gd0g avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.