From ca97a5fa2ee8bb99c4520525a4c443c986840c1a Mon Sep 17 00:00:00 2001 From: Lamron Date: Thu, 23 Jan 2025 15:09:14 +0900 Subject: [PATCH 1/2] Can get "residual sum of squares" --- regression.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/regression.go b/regression.go index d5f76fb..5bc62ca 100644 --- a/regression.go +++ b/regression.go @@ -31,6 +31,7 @@ type Regression struct { Formula string crosses []featureCross hasRun bool + residual_sum_of_squares float64 } type dataPoint struct { @@ -233,15 +234,21 @@ func (r *Regression) calcPredicted() string { observations := len(r.data) var predicted float64 var output string + r.residual_sum_of_squares = 0.0 for i := 0; i < observations; i++ { r.data[i].Predicted, _ = r.Predict(r.data[i].Variables) r.data[i].Error = r.data[i].Predicted - r.data[i].Observed + r.residual_sum_of_squares += r.data[i].Error * r.data[i].Error output += fmt.Sprintf("%v. observed = %v, Predicted = %v, Error = %v", i, r.data[i].Observed, predicted, r.data[i].Error) } return output } +func (r *Regression) GetResidualSumOfSquares() float64 { + return r.residual_sum_of_squares +} + func (r *Regression) calcVariance() string { observations := len(r.data) var obtotal, prtotal, obvar, prvar float64 From fa6ef2f4129d4175e6bb6a2a3626eae9cb20643e Mon Sep 17 00:00:00 2001 From: Lamron Date: Thu, 23 Jan 2025 15:20:32 +0900 Subject: [PATCH 2/2] Init by `go mod` and remove ".travis.yml" --- .travis.yml | 11 ----------- go.mod | 5 +++++ go.sum | 4 ++++ 3 files changed, 9 insertions(+), 11 deletions(-) delete mode 100644 .travis.yml create mode 100644 go.mod create mode 100644 go.sum diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 090a868..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -sudo: false -language: go -go: -- 1.8.x -- 1.9.x -- 1.10.x -- tip - -notifications: - email: - - infra@sajari.com diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c9e33be --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/lamrongol/regression + +go 1.23.4 + +require gonum.org/v1/gonum v0.15.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2e11a1a --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= +gonum.org/v1/gonum v0.15.1 h1:FNy7N6OUZVUaWG9pTiD+jlhdQ3lMP+/LcTpJ6+a8sQ0= +gonum.org/v1/gonum v0.15.1/go.mod h1:eZTZuRFrzu5pcyjN5wJhcIhnUdNijYxX1T2IcrOGY0o=