Created
May 30, 2020 14:03
-
-
Save oborchers/78d7c7369997215a6ae74d5bdcbcb387 to your computer and use it in GitHub Desktop.
This file contains 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
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