vspaz / wls-go

WLS, weighted least squares (weighted linear regression) in pure Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wls-go

WLS, weighted linear regression in pure Go w/o any 3d party dependencies or frameworks.

How-to

package main

import (
	"fmt"
	"github.com/vspaz/wls-go/pkg/models"
)

func main() {
	xPoints := []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}  // ∈ {int8, int16, int32, int, float32, float64}
	yPoints := []float64{1.0, 3.0, 4.0, 5.0, 2.0, 3.0, 4.0}  // ∈ {int8, int16, int32, int, float32, float64}
	weights := []float64{10.0, 1.0, 3.0, 8.0, 14.0, 21.0, 13.0}  // ∈ {int8, int16, int32, int, float32, float64}
	wls := models.NewWlsWithWeights(xPoints, yPoints, weights)  
	point := wls.FitLinearRegression()
	fmt.Println(point.GetSlope())
	fmt.Println(point.GetIntercept())
}

Description

WLS is based on the OLS method and help solve problems of model inadequacy or violations of the basic regression assumptions.

Estimating a linear regression with WLS is useful, but can appear to be daunting w/o special stats packages, such as Python statsmodels or Pandas.

References

About

WLS, weighted least squares (weighted linear regression) in pure Go

License:MIT License


Languages

Language:Go 94.9%Language:Makefile 5.1%