Skip to content

Commit

Permalink
FIX: type checking from PR #566 (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin-Laurent authored Dec 16, 2024
1 parent c39946f commit 662adad
Showing 1 changed file with 13 additions and 12 deletions.
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

0 comments on commit 662adad

Please sign in to comment.