Skip to content

Commit 6f757c7

Browse files
committed
Sklearn API changes fix test 2
1 parent ac8fa2a commit 6f757c7

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

docs/pythresh.thresholds.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228

229229
.. automodule:: pythresh.thresholds.meta
230230
:members:
231-
:exclude-members: _wrap_around_discrepancy
231+
:exclude-members: _patch_ridge, _wrap_around_discrepancy
232232
:undoc-members:
233233
:show-inheritance:
234234
:inherited-members:

pythresh/thresholds/meta.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import numpy as np
66
import pandas as pd
77
import scipy.stats as stats
8+
import sklearn
89
from numba import njit, prange
910
from sklearn.linear_model import RidgeClassifierCV
1011
from sklearn.preprocessing import MinMaxScaler
1112

1213
from .base import BaseThresholder
1314

15+
_NEEDS_CLASSES = tuple(map(int, sklearn.__version__.split('.')[:2])) >= (1, 8)
16+
1417

1518
class META(BaseThresholder):
1619
r"""META class for Meta-modelling thresholder.
@@ -115,14 +118,11 @@ def eval(self, decision):
115118
parent = up(up(__file__))
116119
model = joblib.load(os.path.join(parent, 'models', clf))
117120

118-
def _patch_ridge(est):
119-
if isinstance(est, RidgeClassifierCV) and not hasattr(est, 'classes_'):
120-
est.classes_ = np.array([0, 1])
121-
121+
# Sklearn 1.8.0 API patch
122122
for e in getattr(model, 'estimators_', {}).values():
123-
_patch_ridge(e)
123+
self._patch_ridge(e)
124124

125-
_patch_ridge(getattr(model, 'estimator', None))
125+
self._patch_ridge(getattr(model, 'estimator', None))
126126

127127
if self.method == 'GNBM':
128128

@@ -184,6 +184,12 @@ def _patch_ridge(est):
184184

185185
return lbls
186186

187+
@staticmethod
188+
def _patch_ridge(est):
189+
"""RidgeClassifierCV classes_ attribute patch."""
190+
if _NEEDS_CLASSES and isinstance(est, RidgeClassifierCV) and not hasattr(est, 'classes_'):
191+
est.classes_ = np.array([0, 1])
192+
187193
@staticmethod
188194
@njit(fastmath=True, parallel=True)
189195
def _wrap_around_discrepancy(data, check):

0 commit comments

Comments
 (0)