Skip to content
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

FIX: type checking #567

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions mapie/regression/quantile_regression.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import warnings
from typing import Iterable, Dict, List, Optional, Tuple, Union, cast
from typing import Iterable, List, Optional, Tuple, Union, cast, Any

import numpy as np
from sklearn.base import RegressorMixin, clone
Expand Down Expand Up @@ -547,7 +547,7 @@ def fit(
The model itself.
"""

self.init_fit()
self.initialize_fit()

if self.cv == "prefit":
X_calib, y_calib = self.prefit_estimators(X, y)
Expand All @@ -570,8 +570,7 @@ def fit(

return self

def init_fit(self):

def initialize_fit(self) -> None:
self.cv = self._check_cv(cast(str, self.cv))
self.alpha_np = self._check_alpha(self.alpha)
self.estimators_: List[RegressorMixin] = []
Expand Down Expand Up @@ -667,29 +666,31 @@ def fit_estimators(

def conformalize(
self,
X_conf: ArrayLike,
y_conf: ArrayLike,
X: ArrayLike,
y: ArrayLike,
sample_weight: Optional[ArrayLike] = None,
predict_params: Dict = {},
):
# Parameter groups kept for compliance with superclass MapieRegressor
groups: Optional[ArrayLike] = None,
**kwargs: Any,
) -> MapieRegressor:

self.n_calib_samples = _num_samples(y_conf)
self.n_calib_samples = _num_samples(y)

y_calib_preds = np.full(
shape=(3, self.n_calib_samples),
fill_value=np.nan
)

for i, est in enumerate(self.estimators_):
y_calib_preds[i] = est.predict(X_conf, **predict_params).ravel()
y_calib_preds[i] = est.predict(X, **kwargs).ravel()

self.conformity_scores_ = np.full(
shape=(3, self.n_calib_samples),
fill_value=np.nan
)

self.conformity_scores_[0] = y_calib_preds[0] - y_conf
self.conformity_scores_[1] = y_conf - y_calib_preds[1]
self.conformity_scores_[0] = y_calib_preds[0] - y
self.conformity_scores_[1] = y - y_calib_preds[1]
self.conformity_scores_[2] = np.max(
[
self.conformity_scores_[0],
Expand Down
Loading