regression

package module
v0.0.0-...-bd62029 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2014 License: MIT Imports: 5 Imported by: 0

README

regression

Multivariable Linear Regression in Go (golang)

installation

go get github.com/sajari/regression

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

import "github.com/sajari/regression"

func main() {
    var r regression.Regression
    r.SetObservedName("Distance")
    r.SetVarName(0, "Weight")
    r.SetVarName(1, "Height")
    r.SetVarName(2, "Blood sugar")
    r.AddDataPoint(regression.DataPoint{Observed : 98, Variables : []float64{483, 343, 0.0386}})
    r.AddDataPoint(regression.DataPoint{Observed : 75, Variables : []float64{227, 419, 0.0705}})
    r.AddDataPoint(regression.DataPoint{Observed : 0, Variables : []float64{380, 666, 0.0245}})
    r.AddDataPoint(regression.DataPoint{Observed : 20, Variables : []float64{85, 833, 0.0567}})
    r.AddDataPoint(regression.DataPoint{Observed : 50, Variables : []float64{188, 182, 0.0143}})
    r.RunLinearRegression()
    r.Dump(true)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataPoint

type DataPoint struct {
	Observed  float64
	Variables []float64
	Predicted float64
	Error     float64
}

type Describe

type Describe struct {
	ObservedName  string
	VariableNames map[int]string
}

type Regression

type Regression struct {
	Names             Describe
	Data              []DataPoint
	RegCoeff          map[int]float64
	Rsquared          float64
	VarianceObserved  float64
	VariancePredicted float64
	Debug             bool
	Initialised       bool
	Formula           string
}

func (*Regression) AddDataPoint

func (r *Regression) AddDataPoint(d DataPoint)

func (*Regression) Dump

func (r *Regression) Dump(data bool)

func (*Regression) GetObservedName

func (r *Regression) GetObservedName() string

func (*Regression) GetRegCoeff

func (r *Regression) GetRegCoeff(i int) float64

func (*Regression) GetVarName

func (r *Regression) GetVarName(i int) string

func (*Regression) RunLinearRegression

func (r *Regression) RunLinearRegression()

func (*Regression) SetObservedName

func (r *Regression) SetObservedName(name string)

func (*Regression) SetVarName

func (r *Regression) SetVarName(i int, name string)

Directories

Path Synopsis
Loops through a CSV file and adds each row as a new data point in a linear regression calculation.
Loops through a CSV file and adds each row as a new data point in a linear regression calculation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL