go-chart/polynomial_regression_test.go

36 lines
585 B
Go
Raw Normal View History

2017-04-26 09:27:11 +02:00
package chart
import (
"testing"
2018-04-05 09:42:38 +02:00
assert "github.com/blend/go-sdk/assert"
2018-12-06 16:38:58 +01:00
"git.gutmet.org/go-chart.git/matrix"
2017-04-26 09:27:11 +02:00
)
func TestPolynomialRegression(t *testing.T) {
assert := assert.New(t)
var xv []float64
var yv []float64
for i := 0; i < 100; i++ {
xv = append(xv, float64(i))
yv = append(yv, float64(i*i))
}
values := ContinuousSeries{
XValues: xv,
YValues: yv,
}
poly := &PolynomialRegressionSeries{
InnerSeries: values,
Degree: 2,
}
for i := 0; i < 100; i++ {
_, y := poly.GetValues(i)
2017-04-26 09:27:11 +02:00
assert.InDelta(float64(i*i), y, matrix.DefaultEpsilon)
}
}