Skip to content

Commit 46cb1ab

Browse files
Merge pull request #20 from ubc-systopia/sklearn-compatibility-updates
Changes to fulfill the sklearn API changes that came with version 1.6.1
2 parents 48d9cc8 + 68d71c4 commit 46cb1ab

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/gosdt/_binarizer.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _halfway_points(values):
3030
"""
3131
return [(values[i] + values[i + 1]) / 2 for i in range(len(values) - 1)]
3232

33-
class NumericBinarizer(BaseEstimator, TransformerMixin):
33+
class NumericBinarizer(TransformerMixin, BaseEstimator):
3434
f"""
3535
Encode numerical features as a one-hot numeric array.
3636
@@ -212,8 +212,7 @@ def transform(self, X):
212212
# Check that the input is of the same shape as the one passed
213213
# during fit.
214214
if X.shape[1] != self.n_features_in_:
215-
raise ValueError('Shape of input is different form what was seen'
216-
'in `fit`')
215+
raise ValueError(f"X has {X.shape[1]} features, but NumericBinarizer is expecting {self.n_features_in_} features as input")
217216

218217
# Return a binarization of the input samples based on halfway point splits
219218
Xb_lists = [[X[:, i] <= val for val in _halfway_points(self.column_values_[i])] for i in range(self.n_features_in_)]
@@ -243,8 +242,7 @@ def inverse_transform(self, Xt):
243242
# Check that the input is of the same shape as the one passed
244243
# during fit.
245244
if Xt.shape[1] != self.n_features_out_:
246-
raise ValueError('Shape of input is different from what was seen '
247-
'in `fit`')
245+
raise ValueError(f"X has {Xt.shape[1]} features, but NumericBinarizer.inverse_transform is expecting {self.n_features_out_} features as input")
248246

249247
# Initialize an empty array for inverse transformed data
250248
X = np.empty((Xt.shape[0], self.n_features_in_))

src/gosdt/_threshold_guessing.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sklearn.ensemble import GradientBoostingClassifier
77
from sklearn.utils.validation import check_array, check_is_fitted
88

9-
class ThresholdGuessBinarizer(BaseEstimator, TransformerMixin):
9+
class ThresholdGuessBinarizer(TransformerMixin, BaseEstimator):
1010
f"""
1111
Encode numerical features as a one-hot numeric array.
1212
The encoding is based on the thresholds found by a Gradient Boosting Classifier.
@@ -216,8 +216,7 @@ def transform(self, X):
216216
# Check that the input is of the same shape as the one passed
217217
# during fit.
218218
if X.shape[1] != self.n_features_in_:
219-
raise ValueError('Shape of input is different from what was seen'
220-
'in `fit`')
219+
raise ValueError(f"X has {X.shape[1]} features, but ThresholdBinarizer is expecting {self.n_features_in_} features as input")
221220

222221
return np.concatenate([np.atleast_2d(X[:, j] <= thresh).T for j, thresh in self.thresholds_], axis=1).astype(float)
223222

0 commit comments

Comments
 (0)