Skip to content

Instantly share code, notes, and snippets.

@MKaptein
Last active June 15, 2020 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MKaptein/61b72ecef79efb099a352bbe608ce862 to your computer and use it in GitHub Desktop.
Save MKaptein/61b72ecef79efb099a352bbe608ce862 to your computer and use it in GitHub Desktop.
Simple linear regression to .WASM example.
# imports
import sclblpy as sp
import numpy as np
from sklearn.linear_model import LinearRegression
# generate some data:
n = 100
x = np.random.uniform(0,10,(n,))
# y = 10 + 2x + noise:
y = 10 + 2*x + np.random.normal(0,1,(n,))
# fit a model (note the reshape of the vectors)
mod = LinearRegression()
mod.fit(x.reshape(-1, 1), y.reshape(-1, 1))
# prepare for upload to scailable
fv = np.array([10]).reshape(1,-1) # an example feature vector
docs = {}
docs['name'] = "Simple linear regression demo"
docs['documentation'] = "Linear regression demonstration."
# upload the model; a single-line-of-code
sp.upload(mod, fv, docs=docs)
# Note: the last call will only work if you have a valid scailable account
# get one at https://admin.sclbl.net/signup.html
# and install sclblpy using pip or conda.
# A demo is available here: https://admin.sclbl.net/run.html?cfid=7d4f8549-a637-11ea-88a1-9600004e79cc&exin=%5B%5B10%5D%5D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment