Skip to content

Instantly share code, notes, and snippets.

@MKaptein
Last active June 20, 2020 09:51
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/4277de539ac63645c46148b44951e515 to your computer and use it in GitHub Desktop.
Save MKaptein/4277de539ac63645c46148b44951e515 to your computer and use it in GitHub Desktop.
sclbl_101_model
# Imports
import numpy as np
from sklearn.linear_model import LinearRegression
# Data generation y = 10 + 2*x1 -.5*x2 + noise:
np.random.seed(0)
n = 100
x1 = np.random.uniform(0,10,(n,))
x2 = np.random.uniform(0,10,(n,))
y = 10 + 2 * x1 -.5*x2 + np.random.normal(0,1,(n,))
X = np.column_stack((x1, x2))
# Model fitting
lm = LinearRegression()
lm.fit(X, y.reshape(-1, 1))
# Scailable demo:
import sclblpy as sp
# Create an example feature vector
fv = np.array([2,5])
# Create documentation for this model (accepts Markdown)
docs = {}
docs['name'] = "Simple linear regression demo"
docs['documentation'] = """#Linear regression demonstration.
\nFor the [getting started tutorial](https://github.com/scailable/sclbl-tutorials/blob/master/README.md)."""
# Upload the model to transpile to WASM and make available
sp.upload(lm, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment