Debian Codegraph @

examples/poly_regression/main.go

raw symbols SCIP
1 package main
2
3 //go:generate go run main.go
4
5 import (
6 "os"
7
8 chart "github.com/wcharczuk/go-chart/v2"
9 )
10
11 func main() {
12
13 /*
14 In this example we add a new type of series, a `PolynomialRegressionSeries` that takes another series as a required argument.
15 InnerSeries only needs to implement `ValuesProvider`, so really you could chain `PolynomialRegressionSeries` together if you wanted.
16 */
17
18 mainSeries := chart.ContinuousSeries{
19 Name: "A test series",
20 XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(1.0).WithEnd(100.0)}.Values(), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
21 YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(0).WithMax(100)}.Values(), //generates a []float64 randomly from 0 to 100 with 100 elements.
22 }
23
24 polyRegSeries := &chart.PolynomialRegressionSeries{
25 Degree: 3,
26 InnerSeries: mainSeries,
27 }
28
29 graph := chart.Chart{
30 Series: []chart.Series{
31 mainSeries,
32 polyRegSeries,
33 },
34 }
35
36 f, _ := os.Create("output.png")
37 defer f.Close()
38 graph.Render(chart.PNG, f)
39 }