Repository: feature-engine/feature_engine

Issue:
fit_params not supported for SelectByShuffling (documentation suggests it is supported)
**Describe the bug**
Documentation suggests that fit_params is supported for SelectByShuffling. But my tests suggest it is not supported. I have a working example below. Let me know if using incorrectly or if I can do any more tests to help.

**Working example without fit_params**

```import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from feature_engine.selection import SelectByShuffling

X = pd.DataFrame(dict(x1 = [1000,2000,1000,1000,2000,3000], x2 = [1000,2000,1000,1000,2000,3000]))
y = pd.Series([1,0,0,1,1,0])

sbs = SelectByShuffling(RandomForestClassifier(random_state=42), cv=2, random_state=42)
sbs.fit_transform(X, y)
```

**Example with fit_params not working**

```import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from feature_engine.selection import SelectByShuffling

X = pd.DataFrame(dict(x1 = [1000,2000,1000,1000,2000,3000], x2 = [1000,2000,1000,1000,2000,3000]))
y = pd.Series([1,0,0,1,1,0])

sbs = SelectByShuffling(RandomForestClassifier(random_state=42), cv=2, random_state=42)

sample_weight = [1000,2000,1000,1000,2000,3000]
fit_p = {"sample_weight": sample_weight}

sbs.fit_transform(X, y, **fit_p)
```

**Expected behaviour**

Expect for unpacked params within fit_params to be passed to underlying model / classifier

**Error log**

```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[9], line 1
----> 1 sbs.fit_transform(X, y, **fit_p)

File ~/Dev/litmus/.env/lib/python3.10/site-packages/sklearn/base.py:870, in TransformerMixin.fit_transform(self, X, y, **fit_params)
    867     return self.fit(X, **fit_params).transform(X)
    868 else:
    869     # fit method of arity 2 (supervised transformation)
--> 870     return self.fit(X, y, **fit_params).transform(X)

TypeError: SelectByShuffling.fit() got an unexpected keyword argument 'sample_weight'
```

**Desktop (please complete the following information):**

 - OS: Mac OS 13.2.1 (22D68)
 - Browser: Chrome
 - Version: 112.0.5615.49 (Official Build) (arm64)


Comments:

Patch:
diff --git a/feature_engine/selection/shuffle_features.py b/feature_engine/selection/shuffle_features.py
index 1dcee62..69db54d 100644
--- a/feature_engine/selection/shuffle_features.py
+++ b/feature_engine/selection/shuffle_features.py
@@ -5,7 +5,7 @@ import pandas as pd
 from sklearn.base import is_classifier
 from sklearn.metrics import get_scorer
 from sklearn.model_selection import check_cv, cross_validate
-from sklearn.utils.validation import check_random_state
+from sklearn.utils.validation import check_random_state, _check_sample_weight
 
 from feature_engine._docstrings.fit_attributes import (
     _feature_names_in_docstring,
@@ -185,7 +185,12 @@ class SelectByShuffling(BaseSelector):
         self.cv = cv
         self.random_state = random_state
 
-    def fit(self, X: pd.DataFrame, y: pd.Series):
+    def fit(
+        self,
+        X: pd.DataFrame,
+        y: pd.Series,
+        sample_weight: Union[np.array, pd.Series, List] = None,
+    ):
         """
         Find the important features.
 
@@ -193,8 +198,12 @@ class SelectByShuffling(BaseSelector):
         ----------
         X: pandas dataframe of shape = [n_samples, n_features]
            The input dataframe.
+
         y: array-like of shape (n_samples)
            Target variable. Required to train the estimator.
+
+        sample_weight : array-like of shape (n_samples,), default=None
+            Sample weights. If None, then samples are equally weighted.
         """
 
         X, y = check_X_y(X, y)
@@ -203,6 +212,9 @@ class SelectByShuffling(BaseSelector):
         X = X.reset_index(drop=True)
         y = y.reset_index(drop=True)
 
+        if sample_weight is not None:
+            sample_weight = _check_sample_weight(sample_weight, X)
+
         # If required exclude variables that are not in the input dataframe
         self._confirm_variables(X)
 
@@ -220,6 +232,7 @@ class SelectByShuffling(BaseSelector):
             cv=self.cv,
             return_estimator=True,
             scoring=self.scoring,
+            fit_params={"sample_weight": sample_weight},
         )
 
         # store initial model performance
diff --git a/feature_engine/tags.py b/feature_engine/tags.py
index fa070a3..6dc3647 100644
--- a/feature_engine/tags.py
+++ b/feature_engine/tags.py
@@ -14,6 +14,7 @@ def _return_tags():
             # The test aims to check that the check_X_y function from sklearn is
             # working, but we do not use that check, because we work with dfs.
             "check_transformer_data_not_an_array": "Ok to fail",
+            "check_sample_weights_not_an_array": "Ok to fail",
             # TODO: we probably need the test below!!
             "check_methods_sample_order_invariance": "Test does not work on dataframes",
             # TODO: we probably need the test below!!


Test patch:
diff --git a/tests/test_selection/test_shuffle_features.py b/tests/test_selection/test_shuffle_features.py
index 61e1d27..6cafd67 100644
--- a/tests/test_selection/test_shuffle_features.py
+++ b/tests/test_selection/test_shuffle_features.py
@@ -134,3 +134,21 @@ def test_automatic_variable_selection(df_test):
     ]
     # test transform output
     pd.testing.assert_frame_equal(sel.transform(X), Xtransformed)
+
+
+def test_sample_weights():
+    X = pd.DataFrame(
+        dict(
+            x1=[1000, 2000, 1000, 1000, 2000, 3000],
+            x2=[1000, 2000, 1000, 1000, 2000, 3000],
+        )
+    )
+    y = pd.Series([1, 0, 0, 1, 1, 0])
+
+    sbs = SelectByShuffling(
+        RandomForestClassifier(random_state=42), cv=2, random_state=42
+    )
+
+    sample_weight = [1000, 2000, 1000, 1000, 2000, 3000]
+    sbs.fit_transform(X, y, sample_weight=sample_weight)
+    assert sbs.initial_model_performance_ == 0.125