| 1 | diff --git a/sklearn/isotonic.py b/sklearn/isotonic.py |
| 2 | --- a/sklearn/isotonic.py |
| 3 | +++ b/sklearn/isotonic.py |
| 4 | @@ -360,23 +360,16 @@ def fit(self, X, y, sample_weight=None): |
| 5 | self._build_f(X, y) |
| 6 | return self |
| 7 | |
| 8 | - def transform(self, T): |
| 9 | - """Transform new data by linear interpolation. |
| 10 | - |
| 11 | - Parameters |
| 12 | - ---------- |
| 13 | - T : array-like of shape (n_samples,) or (n_samples, 1) |
| 14 | - Data to transform. |
| 15 | + def _transform(self, T): |
| 16 | + """`_transform` is called by both `transform` and `predict` methods. |
| 17 | |
| 18 | - .. versionchanged:: 0.24 |
| 19 | - Also accepts 2d array with 1 feature. |
| 20 | + Since `transform` is wrapped to output arrays of specific types (e.g. |
| 21 | + NumPy arrays, pandas DataFrame), we cannot make `predict` call `transform` |
| 22 | + directly. |
| 23 | |
| 24 | - Returns |
| 25 | - ------- |
| 26 | - y_pred : ndarray of shape (n_samples,) |
| 27 | - The transformed data. |
| 28 | + The above behaviour could be changed in the future, if we decide to output |
| 29 | + other type of arrays when calling `predict`. |
| 30 | """ |
| 31 | - |
| 32 | if hasattr(self, "X_thresholds_"): |
| 33 | dtype = self.X_thresholds_.dtype |
| 34 | else: |
| 35 | @@ -397,6 +390,24 @@ def transform(self, T): |
| 36 | |
| 37 | return res |
| 38 | |
| 39 | + def transform(self, T): |
| 40 | + """Transform new data by linear interpolation. |
| 41 | + |
| 42 | + Parameters |
| 43 | + ---------- |
| 44 | + T : array-like of shape (n_samples,) or (n_samples, 1) |
| 45 | + Data to transform. |
| 46 | + |
| 47 | + .. versionchanged:: 0.24 |
| 48 | + Also accepts 2d array with 1 feature. |
| 49 | + |
| 50 | + Returns |
| 51 | + ------- |
| 52 | + y_pred : ndarray of shape (n_samples,) |
| 53 | + The transformed data. |
| 54 | + """ |
| 55 | + return self._transform(T) |
| 56 | + |
| 57 | def predict(self, T): |
| 58 | """Predict new data by linear interpolation. |
| 59 | |
| 60 | @@ -410,7 +421,7 @@ def predict(self, T): |
| 61 | y_pred : ndarray of shape (n_samples,) |
| 62 | Transformed data. |
| 63 | """ |
| 64 | - return self.transform(T) |
| 65 | + return self._transform(T) |
| 66 | |
| 67 | # We implement get_feature_names_out here instead of using |
| 68 | # `ClassNamePrefixFeaturesOutMixin`` because `input_features` are ignored. |