-
Notifications
You must be signed in to change notification settings - Fork 2
Enhance estimator validation and implement "fit-if-needed" logic #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| __version__ = "1.0.1" | ||
|
|
||
| from .wrapper import Pearsonify | ||
| from .wrapper import Pearsonify |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| from sklearn.base import BaseEstimator | ||
| from sklearn.utils.validation import NotFittedError, check_is_fitted | ||
|
|
||
| from .utils import ( | ||
| compute_pearson_residuals, | ||
| compute_confidence_intervals, | ||
| calculate_coverage, | ||
| compute_confidence_intervals, | ||
| compute_pearson_residuals, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -24,7 +26,15 @@ def __init__(self, estimator: BaseEstimator, alpha=0.05): | |
| def fit(self, X_train, y_train, X_cal, y_cal): | ||
| """Fit the model and compute Pearson residual-based quantile from calibration data.""" | ||
| # Train the model if it's not already fitted | ||
| self.estimator.fit(X_train, y_train) | ||
| try: | ||
| check_is_fitted(self.estimator) | ||
| if not hasattr(self.estimator, "predict_proba"): | ||
| raise TypeError("The estimator must have 'predict_proba' method.") | ||
| except TypeError as e: | ||
| raise TypeError(f"Estimator validation failed: {e}") from e | ||
|
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Narrow or simplify the This |
||
| except NotFittedError: | ||
| # Attempt to fit the estimator if not already fitted | ||
| self.estimator.fit(X_train, y_train) | ||
|
|
||
| # Compute residuals on calibration set | ||
| y_cal_pred_proba = self.estimator.predict_proba(X_cal)[:, 1] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.