Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,5 @@
|
|||
(setq X1 '[0 1 2 3 4 5 6 7 8 9 10])
|
||||
(setq X2 '[0 1 1 3 3 7 6 7 3 9 8])
|
||||
(setq Y '[1 6 17 34 57 86 121 162 209 262 321])
|
||||
(calc-eval
|
||||
(format "fit(a*X1+b*X2+c,[X1,X2],[a,b,c],[%s %s %s])" X1 X2 Y))
|
||||
33
Task/Multiple-regression/Go/multiple-regression-1.go
Normal file
33
Task/Multiple-regression/Go/multiple-regression-1.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gonum/matrix/mat64"
|
||||
)
|
||||
|
||||
func givens() (x, y *mat64.Dense) {
|
||||
height := []float64{1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63,
|
||||
1.65, 1.68, 1.70, 1.73, 1.75, 1.78, 1.80, 1.83}
|
||||
weight := []float64{52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93,
|
||||
61.29, 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46}
|
||||
degree := 2
|
||||
x = Vandermonde(height, degree)
|
||||
y = mat64.NewDense(len(weight), 1, weight)
|
||||
return
|
||||
}
|
||||
|
||||
func Vandermonde(a []float64, degree int) *mat64.Dense {
|
||||
x := mat64.NewDense(len(a), degree+1, nil)
|
||||
for i := range a {
|
||||
for j, p := 0, 1.; j <= degree; j, p = j+1, p*a[i] {
|
||||
x.Set(i, j, p)
|
||||
}
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func main() {
|
||||
x, y := givens()
|
||||
fmt.Printf("%.4f\n", mat64.Formatted(mat64.QR(x).Solve(y)))
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/gomatrix/matrix"
|
||||
"fmt"
|
||||
|
||||
"github.com/skelterjohn/go.matrix"
|
||||
)
|
||||
|
||||
func givens() (x, y *matrix.DenseMatrix) {
|
||||
11
Task/Multiple-regression/Python/multiple-regression-1.py
Normal file
11
Task/Multiple-regression/Python/multiple-regression-1.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import numpy as np
|
||||
|
||||
height = [1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63,
|
||||
1.65, 1.68, 1.70, 1.73, 1.75, 1.78, 1.80, 1.83]
|
||||
weight = [52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93,
|
||||
61.29, 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46]
|
||||
|
||||
X = np.mat(height**np.arange(3)[:, None])
|
||||
y = np.mat(weight)
|
||||
|
||||
print(y * X.T * (X*X.T).I)
|
||||
11
Task/Multiple-regression/Python/multiple-regression-2.py
Normal file
11
Task/Multiple-regression/Python/multiple-regression-2.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import numpy as np
|
||||
|
||||
height = [1.47, 1.50, 1.52, 1.55, 1.57, 1.60, 1.63,
|
||||
1.65, 1.68, 1.70, 1.73, 1.75, 1.78, 1.80, 1.83]
|
||||
weight = [52.21, 53.12, 54.48, 55.84, 57.20, 58.57, 59.93,
|
||||
61.29, 63.11, 64.47, 66.28, 68.10, 69.92, 72.19, 74.46]
|
||||
|
||||
X = np.array(height)[:, None]**range(3)
|
||||
y = weight
|
||||
|
||||
print(np.linalg.lstsq(X, y)[0])
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
import numpy as np
|
||||
from numpy.random import random
|
||||
|
||||
n=100; k=10
|
||||
y = np.mat(random((1,n)))
|
||||
X = np.mat(random((k,n)))
|
||||
|
||||
b= y * X.T * np.linalg.inv(X*X.T)
|
||||
print(b)
|
||||
Loading…
Add table
Add a link
Reference in a new issue