Skip to content
/ wls-go Public

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

License

Notifications You must be signed in to change notification settings

vspaz/wls-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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