Skip to content

Instantly share code, notes, and snippets.

@juchiast
Created May 8, 2017 13:52
Show Gist options
  • Save juchiast/927655bb37abea346e8244b1c8ef2842 to your computer and use it in GitHub Desktop.
Save juchiast/927655bb37abea346e8244b1c8ef2842 to your computer and use it in GitHub Desktop.
Approximating hidden function using scikit-learn linear regression model
import numpy as np
from sklearn.linear_model import LinearRegression
def f(x):
return 1 + 0.87*x[0] + 0.34*x[1] + 0.5*x[2]
X = np.random.random((2000, 3)) * 100
y = [f(x) for x in X]
lm = LinearRegression()
lm.fit(X, y)
x = [[2, -1, 5]];
print(lm.predict(x), f(x[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment