regression

package module
v0.0.0-...-54b7f48 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: MIT Imports: 3 Imported by: 0

README

regression

linear, quadratic regression

package regression // import "github.com/Konstantin8105/regression"


FUNCTIONS

func Linear(data [][2]float64) (
	a, b float64,
	R2 float64,
	err error,
)
    Linear regression model:

        y   = a*x+b
        R^2 - the relative predictive power of a linear model

func Quadratic(data [][2]float64) (
	a, b, c float64,
	R2 float64,
	err error,
)
    Quadratic regression model:

        y   = a*x^2+b*x+c
        R^2 - the relative predictive power of a quadratic model

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Linear

func Linear(data [][2]float64) (
	a, b float64,
	R2 float64,
	err error,
)

Linear regression model:

y   = a*x+b
R^2 - the relative predictive power of a linear model
Example
a, b, R2, err := Linear([][2]float64{
	{2, 3},
	{4, 7},
	{6, 5},
	{8, 10},
})
if err != nil {
	panic(err)
}
fmt.Fprintf(os.Stdout, "y   = %.4f*x+%.4f\n", a, b)
fmt.Fprintf(os.Stdout, "R^2 = %.4f\n", R2)
Output:

y   = 0.9500*x+1.5000
R^2 = 0.6748

func Quadratic

func Quadratic(data [][2]float64) (
	a, b, c float64,
	R2 float64,
	err error,
)

Quadratic regression model:

y   = a*x^2+b*x+c
R^2 - the relative predictive power of a quadratic model
Example
a, b, c, R2, err := Quadratic([][2]float64{
	{-3.00, 7.50},
	{-2.00, 3.00},
	{-1.00, 0.50},
	{+0.00, 1.00},
	{+1.00, 3.00},
	{+2.00, 6.00},
	{+3.00, 14.0},
})
if err != nil {
	panic(err)
}
fmt.Fprintf(os.Stdout, "y   = %.4f*x^2+%.4f*x+%.4f\n", a, b, c)
fmt.Fprintf(os.Stdout, "R^2 = %.4f\n", R2)
Output:

y   = 1.1071*x^2+1.0000*x+0.5714
R^2 = 0.9884

Types

This section is empty.

Jump to

Keyboard shortcuts

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