Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.