-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from cnellington/dev
Merge Dev -> Main
- Loading branch information
Showing
9 changed files
with
1,742 additions
and
287 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Utility functions for bootstraps | ||
|
||
def select_good_bootstraps(sklearn_wrapper, train_errs, tol=2, **kwargs): | ||
""" | ||
Select bootstraps that are good for a given model. | ||
Parameters | ||
---------- | ||
sklearn_wrapper : contextualized.easy.wrappers.SKLearnWrapper | ||
train_errs : np.ndarray of shape (n_bootstraps, n_samples, n_outcomes) | ||
tol : float tolerance for the mean of the train_errs | ||
Returns | ||
------- | ||
sklearn_wrapper : sklearn_wrapper with only selected bootstraps | ||
""" | ||
if len(train_errs.shape) == 2: | ||
train_errs = train_errs[:, :, None] | ||
|
||
train_errs_by_bootstrap = np.mean(train_errs, axis=(1, 2)) | ||
sklearn_wrapper.models = sklearn_wrapper.models[ | ||
train_errs_by_bootstrap < tol*np.min(train_errs_by_bootstrap)] | ||
return sklearn_wrapper |
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
Oops, something went wrong.