1
1
regression
2
2
=======
3
- [ ![ GoDoc] ( https://godoc.org/github.com/sajari/regression?status.svg )] ( https://godoc.org/github.com/sajari/regression )
4
- [ ![ Go Report Card] ( https://goreportcard.com/badge/sajari/regression )] ( https://goreportcard.com/report/sajari/regression )
5
- [ ![ Build Status] ( https://travis-ci.org/sajari/regression.svg?branch=master )] ( https://travis-ci.org/sajari/regression )
6
3
[ ![ License] [ license-image ]] [ license-url ]
7
4
8
5
[ license-image ] : http://img.shields.io/badge/license-MIT-green.svg?style=flat-square
9
- [ license-url ] : LICENSE.txt
6
+ [ license-url ] : LICENSE
10
7
8
+ Goで重回帰分析するライブラリ
11
9
Multivariable Linear Regression in Go (golang)
12
10
11
+ * NOTE: This project is originally based on https://github.com/sajari/regression *
12
+
13
13
installation
14
14
------------
15
15
16
- $ go get github.com/sajari/regression
17
-
18
- Supports Go 1.8+
16
+ $ go get github.com/anyappinc/regression
19
17
20
18
example usage
21
19
-------------
@@ -28,68 +26,57 @@ package main
28
26
import (
29
27
" fmt"
30
28
31
- " github.com/sajari /regression"
29
+ " github.com/anyappinc /regression"
32
30
)
33
31
34
32
func main () {
35
- r := new ( regression.Regression )
36
- r.SetObserved (" Murders per annum per 1,000,000 inhabitants" )
37
- r.SetVar (0 , " Inhabitants" )
38
- r.SetVar (1 , " Percent with incomes below $5000" )
39
- r.SetVar (2 , " Percent unemployed" )
40
- r.Train (
41
- regression.DataPoint (11.2 , []float64 {587000 , 16.5 , 6.2 }),
42
- regression.DataPoint (13.4 , []float64 {643000 , 20.5 , 6.4 }),
43
- regression.DataPoint (40.7 , []float64 {635000 , 26.3 , 9.3 }),
44
- regression.DataPoint (5.3 , []float64 {692000 , 16.5 , 5.3 }),
45
- regression.DataPoint (24.8 , []float64 {1248000 , 19.2 , 7.3 }),
46
- regression.DataPoint (12.7 , []float64 {643000 , 16.5 , 5.9 }),
47
- regression.DataPoint (20.9 , []float64 {1964000 , 20.2 , 6.4 }),
48
- regression.DataPoint (35.7 , []float64 {1531000 , 21.3 , 7.6 }),
49
- regression.DataPoint (8.7 , []float64 {713000 , 17.2 , 4.9 }),
50
- regression.DataPoint (9.6 , []float64 {749000 , 14.3 , 6.4 }),
51
- regression.DataPoint (14.5 , []float64 {7895000 , 18.1 , 6 }),
52
- regression.DataPoint (26.9 , []float64 {762000 , 23.1 , 7.4 }),
53
- regression.DataPoint (15.7 , []float64 {2793000 , 19.1 , 5.8 }),
54
- regression.DataPoint (36.2 , []float64 {741000 , 24.7 , 8.6 }),
55
- regression.DataPoint (18.1 , []float64 {625000 , 18.6 , 6.5 }),
56
- regression.DataPoint (28.9 , []float64 {854000 , 24.9 , 8.3 }),
57
- regression.DataPoint (14.9 , []float64 {716000 , 17.9 , 6.7 }),
58
- regression.DataPoint (25.8 , []float64 {921000 , 22.4 , 8.6 }),
59
- regression.DataPoint (21.7 , []float64 {595000 , 20.2 , 8.4 }),
60
- regression.DataPoint (25.7 , []float64 {3353000 , 16.9 , 6.7 }),
33
+ r := regression.NewRegression ( )
34
+ r.SetObjectiveVariableLabel (" Murders per annum per 1,000,000 inhabitants" )
35
+ r.SetExplanatoryVariableLabel (0 , " Inhabitants" )
36
+ r.SetExplanatoryVariableLabel (1 , " Percent with incomes below $5000" )
37
+ r.SetExplanatoryVariableLabel (2 , " Percent unemployed" )
38
+ r.AddObservations (
39
+ regression.NewObservation (11.2 , []float64 {587000 , 16.5 , 6.2 }),
40
+ regression.NewObservation (13.4 , []float64 {643000 , 20.5 , 6.4 }),
41
+ regression.NewObservation (40.7 , []float64 {635000 , 26.3 , 9.3 }),
42
+ regression.NewObservation (5.3 , []float64 {692000 , 16.5 , 5.3 }),
43
+ regression.NewObservation (24.8 , []float64 {1248000 , 19.2 , 7.3 }),
44
+ regression.NewObservation (12.7 , []float64 {643000 , 16.5 , 5.9 }),
45
+ regression.NewObservation (20.9 , []float64 {1964000 , 20.2 , 6.4 }),
46
+ regression.NewObservation (35.7 , []float64 {1531000 , 21.3 , 7.6 }),
47
+ regression.NewObservation (8.7 , []float64 {713000 , 17.2 , 4.9 }),
48
+ regression.NewObservation (9.6 , []float64 {749000 , 14.3 , 6.4 }),
49
+ regression.NewObservation (14.5 , []float64 {7895000 , 18.1 , 6 }),
50
+ regression.NewObservation (26.9 , []float64 {762000 , 23.1 , 7.4 }),
51
+ regression.NewObservation (15.7 , []float64 {2793000 , 19.1 , 5.8 }),
52
+ regression.NewObservation (36.2 , []float64 {741000 , 24.7 , 8.6 }),
53
+ regression.NewObservation (18.1 , []float64 {625000 , 18.6 , 6.5 }),
54
+ regression.NewObservation (28.9 , []float64 {854000 , 24.9 , 8.3 }),
55
+ regression.NewObservation (14.9 , []float64 {716000 , 17.9 , 6.7 }),
56
+ regression.NewObservation (25.8 , []float64 {921000 , 22.4 , 8.6 }),
57
+ regression.NewObservation (21.7 , []float64 {595000 , 20.2 , 8.4 }),
58
+ regression.NewObservation (25.7 , []float64 {3353000 , 16.9 , 6.7 }),
61
59
)
62
- r.Run ()
60
+ model , err := r.Run ()
61
+ if err != nil {
62
+ log.Fatalln (err)
63
+ }
63
64
64
- fmt.Printf (" Regression formula:\n %v \n " , r.Formula )
65
- fmt.Printf (" Regression:\n %s \n " , r)
65
+ fmt.Printf (" Regression formula:\n %v \n " , model.FormulaString ())
66
66
}
67
67
```
68
68
69
- Note: You can also add data points one by one.
69
+ Note: You can also add observations one by one.
70
70
71
- Once calculated you can print the data, look at the R^2, Variance, residuals, etc. You can also access the coefficients directly to use elsewhere, e.g.
71
+ Once calculated, you can look at the R^2, Standard Error, ANOVA, Coefficients, etc. e.g.
72
72
73
73
``` go
74
74
// Get the coefficient for the "Inhabitants" variable 0:
75
- c := r. Coeff ( 0 )
75
+ c := model. ExplanatoryVars [ 0 ]. Coeff
76
76
```
77
77
78
- You can also use the model to predict new data points
78
+ You can also use the model to predict new observation
79
79
80
80
``` go
81
- prediction , err := r.Predict ([]float64 {587000 , 16.5 , 6.2 })
82
- ```
83
-
84
- Feature crosses are supported so your model can capture fixed non-linear relationships
85
-
86
- ``` go
87
-
88
- r.Train (
89
- regression.DataPoint (11.2 , []float64 {587000 , 16.5 , 6.2 }),
90
- )
91
- // Add a new feature which is the first variable (index 0) to the power of 2
92
- r.AddCross (PowCross (0 , 2 ))
93
- r.Run ()
94
-
81
+ prediction , err := model.Predict ([]float64 {587000 , 16.5 , 6.2 })
95
82
```
0 commit comments