|
1 | 1 | regression v2
|
2 | 2 | =======
|
3 |
| -[![License][license-image]][license-url] |
4 | 3 |
|
5 |
| -[license-image]: http://img.shields.io/badge/license-MIT-green.svg?style=flat-square |
6 |
| -[license-url]: LICENSE |
| 4 | +This repository contains v2 of regression library that provides totally different API from the original version. |
7 | 5 |
|
8 |
| -Goで重回帰分析するライブラリ |
9 |
| -Multivariable Linear Regression in Go (golang) |
| 6 | +v2 is under `v2/` directory, or you can find at https://github.com/anyappinc/regression/tree/master/v2. |
10 | 7 |
|
11 |
| -*NOTE: This project is originally based on https://github.com/sajari/regression* |
12 |
| - |
13 |
| -installation |
14 |
| ------------- |
15 |
| - |
16 |
| - $ go get github.com/anyappinc/regression/v2 |
17 |
| - |
18 |
| -example usage |
19 |
| -------------- |
20 |
| - |
21 |
| -Import the package, create a regression and add data to it. You can use as many variables as you like, in the below example there are 3 variables for each observation. |
22 |
| - |
23 |
| -```go |
24 |
| -package main |
25 |
| - |
26 |
| -import ( |
27 |
| - "fmt" |
28 |
| - |
29 |
| - "github.com/anyappinc/regression/v2" |
30 |
| -) |
31 |
| - |
32 |
| -func main() { |
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}), |
59 |
| - ) |
60 |
| - model, err := r.Run() |
61 |
| - if err != nil { |
62 |
| - log.Fatalln(err) |
63 |
| - } |
64 |
| - |
65 |
| - fmt.Printf("Regression formula:\n%v\n", model.FormulaString()) |
66 |
| -} |
67 |
| -``` |
68 |
| - |
69 |
| -Note: You can also add observations one by one. |
70 |
| - |
71 |
| -Once calculated, you can look at the R^2, Standard Error, ANOVA, Coefficients, etc. e.g. |
72 |
| - |
73 |
| -```go |
74 |
| -// Get the coefficient for the "Inhabitants" variable 0: |
75 |
| -c := model.ExplanatoryVars[0].Coeff |
76 |
| -``` |
77 |
| - |
78 |
| -You can also use the model to predict new observation |
79 |
| - |
80 |
| -```go |
81 |
| -prediction, err := model.Predict([]float64{587000, 16.5, 6.2}) |
82 |
| -``` |
| 8 | +The original library that this one is based on is available at https://github.com/sajari/regression. |
0 commit comments