• Stars
    star
    384
  • Rank 111,715 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Multivariable regression library in Go

regression

GoDoc Go Report Card Build Status License

Multivariable Linear Regression in Go (golang)

installation

$ go get github.com/sajari/regression

Supports Go 1.8+

example usage

Import the package, create a regression and add data to it. You can use as many variables as you like, in the below example there are 3 variables for each observation.

package main

import (
	"fmt"

	"github.com/sajari/regression"
)

func main() {
	r := new(regression.Regression)
	r.SetObserved("Murders per annum per 1,000,000 inhabitants")
	r.SetVar(0, "Inhabitants")
	r.SetVar(1, "Percent with incomes below $5000")
	r.SetVar(2, "Percent unemployed")
	r.Train(
		regression.DataPoint(11.2, []float64{587000, 16.5, 6.2}),
		regression.DataPoint(13.4, []float64{643000, 20.5, 6.4}),
		regression.DataPoint(40.7, []float64{635000, 26.3, 9.3}),
		regression.DataPoint(5.3, []float64{692000, 16.5, 5.3}),
		regression.DataPoint(24.8, []float64{1248000, 19.2, 7.3}),
		regression.DataPoint(12.7, []float64{643000, 16.5, 5.9}),
		regression.DataPoint(20.9, []float64{1964000, 20.2, 6.4}),
		regression.DataPoint(35.7, []float64{1531000, 21.3, 7.6}),
		regression.DataPoint(8.7, []float64{713000, 17.2, 4.9}),
		regression.DataPoint(9.6, []float64{749000, 14.3, 6.4}),
		regression.DataPoint(14.5, []float64{7895000, 18.1, 6}),
		regression.DataPoint(26.9, []float64{762000, 23.1, 7.4}),
		regression.DataPoint(15.7, []float64{2793000, 19.1, 5.8}),
		regression.DataPoint(36.2, []float64{741000, 24.7, 8.6}),
		regression.DataPoint(18.1, []float64{625000, 18.6, 6.5}),
		regression.DataPoint(28.9, []float64{854000, 24.9, 8.3}),
		regression.DataPoint(14.9, []float64{716000, 17.9, 6.7}),
		regression.DataPoint(25.8, []float64{921000, 22.4, 8.6}),
		regression.DataPoint(21.7, []float64{595000, 20.2, 8.4}),
		regression.DataPoint(25.7, []float64{3353000, 16.9, 6.7}),
	)
	r.Run()

	fmt.Printf("Regression formula:\n%v\n", r.Formula)
	fmt.Printf("Regression:\n%s\n", r)
}

Note: You can also add data points one by one.

Once calculated you can print the data, look at the R^2, Variance, residuals, etc. You can also access the coefficients directly to use elsewhere, e.g.

// Get the coefficient for the "Inhabitants" variable 0:
c := r.Coeff(0)

You can also use the model to predict new data points

prediction, err := r.Predict([]float64{587000, 16.5, 6.2})

Feature crosses are supported so your model can capture fixed non-linear relationships

r.Train(
  regression.DataPoint(11.2, []float64{587000, 16.5, 6.2}),
)
//Add a new feature which is the first variable (index 0) to the power of 2
r.AddCross(PowCross(0, 2))
r.Run()

More Repositories

1

docconv

Converts PDF, DOC, DOCX, XML, HTML, RTF, etc to plain text
Go
1,370
star
2

fuzzy

Spell checking and fuzzy search suggestion written in Go
Go
367
star
3

word2vec

Go library for performing computations in word2vec binary models
Go
184
star
4

storage

Go package for abstracting local, in-memory, and remote (Google Cloud Storage/S3) filesystems
Go
52
star
5

sdk-react

Official repository of the Search.io SDK for React
TypeScript
40
star
6

fastentity

Fast identification of character sequences in text or documents (multi-lingual)
Go
18
star
7

simple-linkedin-php

A fork of http://code.google.com/p/simple-linkedinphp/
PHP
10
star
8

sdk-node

Official repository of the Search.io SDK for Node.js
TypeScript
8
star
9

sdk-js

Official repository of the Search.io SDK for JavaScript integration into web applications
TypeScript
8
star
10

sdk-php

Official repository of the Search.io SDK for PHP
PHP
8
star
11

sajari-sdk-go

Search.io APIs Go Client Library
Go
4
star
12

sdk-react-guide

Examples and guides to get started with the Search.io React SDK
JavaScript
4
star
13

env

Environment variable management for services
Go
4
star
14

sdk-dotnet

Official repository of the Search.io SDK for .NET
C#
4
star
15

sdk-go

Official repository of the Search.io SDK for Go
Go
3
star
16

mlg

Generates code to a) train ML models in various languages and b) predict directly in Go
Smarty
3
star
17

community

Join to exchange ideas, ask questions, or make suggestions on how we can improve Search.io.
3
star
18

proto

Protocol Buffer Definitions for Search.io gRPC APIs
3
star
19

sdk_ruby

Official repository of the Search.io SDK for Ruby
Ruby
3
star
20

talks

Sajari presentations
Go
3
star
21

gommap

Go
2
star
22

setup-cue

Setup cuelang in your GitHub Actions workflow
2
star
23

protogen-go

Generated Go packages for Search.io gRPC APIs
Shell
1
star
24

node-sdk-scripts

A set of modules to assist with uploading data to Search.io
JavaScript
1
star
25

website-search-integration

Search.io Website Search Integration
TypeScript
1
star
26

sdk-python

Official repository of the Search.io SDK for Python
Python
1
star
27

client-sajari-service

Java
1
star