Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions doc/whats_new/v1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ Changelog
`max_iter` and `tol`.
:pr:`21341` by :user:`Arturo Amor <ArturoAmorQ>`.

:mod:`sklearn.isotonic`
.......................

- |Enhancement| Adds :term:`get_feature_names_out` to `IsotonicRegression`.
:pr:`22249` by `Thomas Fan`_.

:mod:`sklearn.linear_model`
...........................

Expand Down
20 changes: 20 additions & 0 deletions sklearn/isotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,26 @@ def predict(self, T):
"""
return self.transform(T)

# We implement get_feature_names_out here instead of using
# `_ClassNamePrefixFeaturesOutMixin`` because `input_features` are ignored.
# `input_features` are ignored because `IsotonicRegression` accepts 1d
# arrays and the semantics of `feature_names_in_` are not clear for 1d arrays.
def get_feature_names_out(self, input_features=None):
"""Get output feature names for transformation.

Parameters
----------
input_features : array-like of str or None, default=None
Ignored.

Returns
-------
feature_names_out : ndarray of str objects
An ndarray with one string i.e. ["isotonicregression0"].
"""
class_name = self.__class__.__name__.lower()
return np.asarray([f"{class_name}0"], dtype=object)

def __getstate__(self):
"""Pickle-protocol - return state of the estimator."""
state = super().__getstate__()
Expand Down
1 change: 0 additions & 1 deletion sklearn/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ def test_pandas_column_name_consistency(estimator):
GET_FEATURES_OUT_MODULES_TO_IGNORE = [
"cluster",
"ensemble",
"isotonic",
"kernel_approximation",
"preprocessing",
"manifold",
Expand Down
15 changes: 15 additions & 0 deletions sklearn/tests/test_isotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,18 @@ def test_isotonic_regression_sample_weight_not_overwritten():

IsotonicRegression().fit(X, y, sample_weight=sample_weight_fit)
assert_allclose(sample_weight_fit, sample_weight_original)


@pytest.mark.parametrize("shape", ["1d", "2d"])
def test_get_feature_names_out(shape):
"""Check `get_feature_names_out` for `IsotonicRegression`."""
X = np.arange(10)
if shape == "2d":
X = X.reshape(-1, 1)
y = np.arange(10)

iso = IsotonicRegression().fit(X, y)
names = iso.get_feature_names_out()
assert isinstance(names, np.ndarray)
assert names.dtype == object
assert_array_equal(["isotonicregression0"], names)