Created
December 15, 2015 09:14
-
-
Save alstat/8907a7679a2a7ee8c13f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly.plotly as py | |
import plotly.graph_objs as go | |
import itertools | |
def expandgrid(*itrs): | |
product = list(itertools.product(*itrs)) | |
return {'Var{}'.format(i+1):[x[i] for x in product] for i in range(len(itrs))} | |
x1_pred = np.linspace(np.min(x1), np.max(x1), num = 100) | |
x2_pred = np.linspace(np.min(x2), np.max(x2), num = 100) | |
grid = expandgrid(x1_pred, x2_pred) | |
x1_gr = np.array(grid['Var1']).reshape((10000, 1)) | |
x2_gr = np.array(grid['Var2']).reshape((10000, 1)) | |
X_gr = np.concatenate((x1_gr, x2_gr), 1) | |
error_pred = np.random.normal(scale = 7, size = 10000).reshape((10000, 1)) | |
y_pred = X_gr.dot(beta_hat) | |
y_pred = y_pred.reshape((100,100)) | |
trace2 = go.Surface( | |
x = x1_pred, | |
y = x2_pred, | |
z = y_pred, | |
colorscale = 'YIGnBu', | |
opacity = 1 | |
) | |
fig = go.Figure(data = [trace1, trace2], layout = layout) | |
plot_url = py.plot(fig, filename = 'Simulated Data With Prediction Plane') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment