{"id":13444579,"url":"https://github.com/sajari/regression","last_synced_at":"2025-05-16T08:07:18.047Z","repository":{"id":9425741,"uuid":"11297815","full_name":"sajari/regression","owner":"sajari","description":"Multivariable regression library in Go","archived":false,"fork":false,"pushed_at":"2024-04-23T19:49:24.000Z","size":58,"stargazers_count":406,"open_issues_count":10,"forks_count":70,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-08T20:18:33.797Z","etag":null,"topics":["go","linear-regression","regression"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sajari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-10T00:28:14.000Z","updated_at":"2025-04-08T02:51:52.000Z","dependencies_parsed_at":"2022-08-17T04:30:19.734Z","dependency_job_id":"8ba9e290-d9a2-4454-a028-02dcee7d1547","html_url":"https://github.com/sajari/regression","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajari%2Fregression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajari%2Fregression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajari%2Fregression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajari%2Fregression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sajari","download_url":"https://codeload.github.com/sajari/regression/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493385,"owners_count":22080127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","linear-regression","regression"],"created_at":"2024-07-31T04:00:30.961Z","updated_at":"2025-05-16T08:07:13.024Z","avatar_url":"https://github.com/sajari.png","language":"Go","funding_links":[],"categories":["Regression"],"sub_categories":["Vector Database"],"readme":"regression\n=======\n[![GoDoc](https://godoc.org/github.com/sajari/regression?status.svg)](https://godoc.org/github.com/sajari/regression)\n[![Go Report Card](https://goreportcard.com/badge/sajari/regression)](https://goreportcard.com/report/sajari/regression)\n[![Build Status](https://travis-ci.org/sajari/regression.svg?branch=master)](https://travis-ci.org/sajari/regression)\n[![License][license-image]][license-url]\n\n[license-image]: http://img.shields.io/badge/license-MIT-green.svg?style=flat-square\n[license-url]: LICENSE.txt\n\nMultivariable Linear Regression in Go (golang)\n\ninstallation\n------------\n\n    $ go get github.com/sajari/regression\n\nSupports Go 1.8+\n\nexample usage\n-------------\n\nImport 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.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sajari/regression\"\n)\n\nfunc main() {\n\tr := new(regression.Regression)\n\tr.SetObserved(\"Murders per annum per 1,000,000 inhabitants\")\n\tr.SetVar(0, \"Inhabitants\")\n\tr.SetVar(1, \"Percent with incomes below $5000\")\n\tr.SetVar(2, \"Percent unemployed\")\n\tr.Train(\n\t\tregression.DataPoint(11.2, []float64{587000, 16.5, 6.2}),\n\t\tregression.DataPoint(13.4, []float64{643000, 20.5, 6.4}),\n\t\tregression.DataPoint(40.7, []float64{635000, 26.3, 9.3}),\n\t\tregression.DataPoint(5.3, []float64{692000, 16.5, 5.3}),\n\t\tregression.DataPoint(24.8, []float64{1248000, 19.2, 7.3}),\n\t\tregression.DataPoint(12.7, []float64{643000, 16.5, 5.9}),\n\t\tregression.DataPoint(20.9, []float64{1964000, 20.2, 6.4}),\n\t\tregression.DataPoint(35.7, []float64{1531000, 21.3, 7.6}),\n\t\tregression.DataPoint(8.7, []float64{713000, 17.2, 4.9}),\n\t\tregression.DataPoint(9.6, []float64{749000, 14.3, 6.4}),\n\t\tregression.DataPoint(14.5, []float64{7895000, 18.1, 6}),\n\t\tregression.DataPoint(26.9, []float64{762000, 23.1, 7.4}),\n\t\tregression.DataPoint(15.7, []float64{2793000, 19.1, 5.8}),\n\t\tregression.DataPoint(36.2, []float64{741000, 24.7, 8.6}),\n\t\tregression.DataPoint(18.1, []float64{625000, 18.6, 6.5}),\n\t\tregression.DataPoint(28.9, []float64{854000, 24.9, 8.3}),\n\t\tregression.DataPoint(14.9, []float64{716000, 17.9, 6.7}),\n\t\tregression.DataPoint(25.8, []float64{921000, 22.4, 8.6}),\n\t\tregression.DataPoint(21.7, []float64{595000, 20.2, 8.4}),\n\t\tregression.DataPoint(25.7, []float64{3353000, 16.9, 6.7}),\n\t)\n\tr.Run()\n\n\tfmt.Printf(\"Regression formula:\\n%v\\n\", r.Formula)\n\tfmt.Printf(\"Regression:\\n%s\\n\", r)\n}\n```\n\nNote: You can also add data points one by one.\n\nOnce 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.\n\n```go\n// Get the coefficient for the \"Inhabitants\" variable 0:\nc := r.Coeff(0)\n```\n\nYou can also use the model to predict new data points\n\n```go\nprediction, err := r.Predict([]float64{587000, 16.5, 6.2})\n```\n\nFeature crosses are supported so your model can capture fixed non-linear relationships\n\n```go\n\nr.Train(\n  regression.DataPoint(11.2, []float64{587000, 16.5, 6.2}),\n)\n//Add a new feature which is the first variable (index 0) to the power of 2\nr.AddCross(PowCross(0, 2))\nr.Run()\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajari%2Fregression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsajari%2Fregression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajari%2Fregression/lists"}