{"id":13341539,"url":"https://github.com/vsoch/regression-wasm","last_synced_at":"2025-04-12T12:33:09.355Z","repository":{"id":54801758,"uuid":"212387171","full_name":"vsoch/regression-wasm","owner":"vsoch","description":"Testing doing basic regression with web assembly","archived":false,"fork":false,"pushed_at":"2021-01-28T16:27:25.000Z","size":3936,"stargazers_count":32,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T07:11:16.379Z","etag":null,"topics":["golang","linear-regression","multiple-regression","wasm","web-assembly"],"latest_commit_sha":null,"homepage":"https://vsoch.github.io/regression-wasm/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vsoch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-02T16:20:07.000Z","updated_at":"2021-01-28T16:27:27.000Z","dependencies_parsed_at":"2022-08-14T03:20:22.539Z","dependency_job_id":null,"html_url":"https://github.com/vsoch/regression-wasm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fregression-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fregression-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fregression-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsoch%2Fregression-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vsoch","download_url":"https://codeload.github.com/vsoch/regression-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248566533,"owners_count":21125680,"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":["golang","linear-regression","multiple-regression","wasm","web-assembly"],"created_at":"2024-07-29T19:25:29.162Z","updated_at":"2025-04-12T12:33:09.328Z","avatar_url":"https://github.com/vsoch.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Regression Wasm\n\nThis repository serves a simple [web assembly](https://webassembly.org/) (wasm) application \nto perform a regression, using data from a table in the browser, which can be loaded as a delimited file\nby the user. We use a simple [regression library](https://github.com/sajari/regression) to do\nthe work. See the demo [here](https://vsoch.github.io/regression-wasm/) or continue reading.\n\n## Summary\n\n - Run a multiple or single regression using Web Assembly\n - Two variables (one predictor, one regression) will generate a line plot showing X vs. Y and predictions\n - More than two variables (one predictor, multiple regressors) performs multiple regression to generate a residual histogram\n - Upload your own data file, change the delimiter, the file name to be saved, or the predictor column\n\n## Overview\n\nWhen you load the page, you are presented with a loaded data frame. The data is a bit dark,\nbut it's a nice dataset to show how this works. The first column is the number of murders (per\nmillion habitants) for some city, and each of the remaining columns are variables that might\nbe used to predict it (inhabitants, percent with incomes below $5000, and percent unemployed).\nThis is what you see:\n\n![img/basics.png](img/basics.png)\n\n### Formula\n\nThe formula for our regression model is shown below the plot, in human friendly terms.\n\n```\nPredicted = -36.7649 + Inhabitants*0.0000 + Percent with incomes below $5000*1.1922 + Percent unemployed*4.7198\n```\n\n### Residual Plot\n\nGiven that we have more than one regressor variable, we need to run a multiple regression,\nand so the plot in the upper right is a histogram of the residuals.\n\n \u003e the residuals are the difference between the actual values (number of murders per million habitants) and the values predicted by our model.\n\n### Filtering\n\nIf you remove any single value from a row, it invalidates it, and it won't be included\nin the plot. If you remove a column heading, it's akin to removing the entire column.\n\n### Line Plot\n\nBut what if we want to plot the relationship between one of the variables X, and our Y?\nThis is where the tool gets interesting! By removing a column header, we essentially\nremove the column from the dataset. Let's first try removing just one, Inhabitants:\n\n![img/remove1.png](img/remove1.png)\n\n\nWe still see a residual plot because it would require more than two dimensions to plot.\nLet's remove another one, the percent unemployed:\n\n![img/line-plot.png](img/line-plot.png)\n\nNow we see a line plot, along with the plotting of the predictions! By simply removing\neach column one at a time (and leaving only one Y, and one X) we are actually running\na single regression, and we can do this for each variable:\n\n#### Inhabitants to predict murders\n\n![img/inhabitants-predict-murders.png](img/inhabitants-predict-murders.png)\n\n\u003cbr\u003e\n\n#### Unemployment to predict murders\n\n![img/unemployment-predict-murders.png](img/unemployment-predict-murders.png)\n\n\u003cbr\u003e\n\n#### Low Income Percentage to predict murders\n\n![img/incomes-predict-murders.png](img/incomes-predict-murders.png)\n\n\nAs we can see, the number of inhabitants (on its own) is fairly useless. The variables\nthat are strongest here are unemployment and income. \n\n## Download Data\n\nThis of course is a very superficial overview, you would want to download the full model data to get more detail:\nThe \"Download Results\" will appear after you generate any kind of plot, and it downloads\na text file with the model output. Here is an example:\n\n```\nDinosaur Regression Wasm\nPredicted = -36.7649 + Inhabitants*0.0000 + Percent with incomes below $5000*1.1922 + Percent unemployed*4.7198\nMurders per annum per one million inhabitants|\tInhabitants|\tPercent with incomes below $5000|\tPercent unemployed\n11.20|\t587000.00|\t16.50|\t6.20\n13.40|\t643000.00|\t20.50|\t6.40\n40.70|\t635000.00|\t26.30|\t9.30\n5.30|\t692000.00|\t16.50|\t5.30\n24.80|\t1248000.00|\t19.20|\t7.30\n12.70|\t643000.00|\t16.50|\t5.90\n20.90|\t1964000.00|\t20.20|\t6.40\n35.70|\t1531000.00|\t21.30|\t7.60\n8.70|\t713000.00|\t17.20|\t4.90\n9.60|\t749000.00|\t14.30|\t6.40\n14.50|\t7895000.00|\t18.10|\t6.00\n26.90|\t762000.00|\t23.10|\t7.40\n15.70|\t2793000.00|\t19.10|\t5.80\n36.20|\t741000.00|\t24.70|\t8.60\n18.10|\t625000.00|\t18.60|\t6.50\n28.90|\t854000.00|\t24.90|\t8.30\n14.90|\t716000.00|\t17.90|\t6.70\n25.80|\t921000.00|\t22.40|\t8.60\n21.70|\t595000.00|\t20.20|\t8.40\n25.70|\t3353000.00|\t16.90|\t6.70\n\nN = 20\nVariance observed = 92.76010000000001\nVariance Predicted = 75.90724706481737\nR2 = 0.8183178658153383\n```\n\n## About\n\n### Why?\n\nWeb assembly can allow us to interact with compiled code directly in the browser,\ndoing away with any need for a server. While I don't do a large amount of data analysis\nfor my role proper, I realize that many researchers do, and so with this in mind, \nI wanted to create a starting point for developers to interact with data in the browser.\nThe minimum conditions for success meant:\n\n 1. being able to load a delimited file into the browser\n 2. having the file render as a table\n 3. having the data be processed by a compiled wasm\n 4. updating a plot based on output from 3.\n\nThus, the application performs a simple regression based on loading data in the table,\nand then plotting the result. To make it fun, I added a cute gopher logo and used an xkcd\nplotting library for the result.\n\n### Customization\n\nThe basics are here for a developer to create (some GoLang based) functions to\nperform data analysis on an input file, and render back to the screen as a plot.\nIf you need any help, or want to request a custom tool, please don't hesitate to\n[open up an issue](https://www.github.com/vsoch/regression-wasm/issues).\n\n## Development\n\n### Local\n\nIf you are comfortable with GoLang, and have installed [emscripten](https://emscripten.org), \nyou can clone the repository into your $GOPATH under the github folder:\n\n```bash\n$ mkdir -p $GOPATH/src.github.com/vsoch\n$ cd $GOPATH/src.github.com/vsoch\n$ git clone https://www.github.com/vsoch/regression-wasm\n```\n\nAnd then build the wasm.\n\n```bash\n$ cd regression-wasm\n$ make\n```\n\nAdd your own Go version specific `wasm_exec.js` file :\n\n```bash\n$ cp \"$(go env GOROOT)/misc/wasm/wasm_exec.js\" ./docs\n```\n\nAnd cd into the \"docs\" folder and start a server to see the result.\n\n```bash\n$ cd docs\n$ python -m http.server 9999\n```\n\nOpen the browser to http://localhost:9999\n\n\n## Docker\n\nIf you don't want to install dependencies, just clone the repository, and\nbuild the Docker image:\n\n```bash\n$ docker build -t vanessa/regression-wasm .\n```\n\nIt will install [emscripten](https://emscripten.org/docs/getting_started/FAQ.html),\nadd the source code to the repository, and compile to wasm. You can then\nrun the container and expose port 80 to see the compiled interface:\n\n```bash\n$ docker run -it --rm -p 80:80 vanessa/regression-wasm\n``` \n\nThen you can proceed to use the interface.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsoch%2Fregression-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvsoch%2Fregression-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsoch%2Fregression-wasm/lists"}