Skip to content

Instantly share code, notes, and snippets.

@smazzanti
Last active April 9, 2020 14:31
Show Gist options
  • Save smazzanti/a80adebaf62cfc5a9b75137649b8d9a3 to your computer and use it in GitHub Desktop.
Save smazzanti/a80adebaf62cfc5a9b75137649b8d9a3 to your computer and use it in GitHub Desktop.
def X2y(X, with_error = True):
# functional form of the dependence between y and X
y_star = X['linear'] + X['nonlinear_square'] ** 2 + np.sin(3 * X['nonlinear_sin']) + (X['interaction_1'] * X['interaction_2'] * X['interaction_3'])
# add random error called epsilon (this will be used for creating y)
if with_error:
np.random.seed(0)
epsilon = np.random.normal(0, .1, len(y_star))
return y_star + epsilon
# do not add error (this will be used for prediction)
else:
return y_star
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment