Skip to content

Instantly share code, notes, and snippets.

@oborchers
Created May 30, 2020 14:03
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 oborchers/78d7c7369997215a6ae74d5bdcbcb387 to your computer and use it in GitHub Desktop.
Save oborchers/78d7c7369997215a6ae74d5bdcbcb387 to your computer and use it in GitHub Desktop.
exog_perf = [] # Exogenous performance
# Iterate rows of exclusion matrix and estimate model on reduced data
for row in trange(excl_mat.shape[0]):
# Get exclusion mask and invert to inclusion mask (True = included)
# Inversion is necessary for numpy indexing with boolean arrays
mask = invert(squeeze(excl_mat[row].toarray()))
# Fit arbtitrary estimator
est = LinearRegression(n_jobs=-1)
est.fit(
data["train_noise"].X[mask],
data["train_noise"].y[mask],
)
# Evaluate estimator on exogenous performance and store result
# Here we use the MSE on the validation data as exogenous performance.
exog_perf.append(
mean_squared_error(
est.predict(data["val"]. X),
data["val"].y,
)
)
exog_perf = array(exog_perf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment