Possible bug in sklearn 1.6.1 PartialDependenceDisplay.from_estimator when target and feature are both binary

### Describe the bug

PartialDependenceDisplay.from_estimator does not seem able to handle dummy variables when the response variable is binary. See example below. The example works fine in 1.5.2 but returns `ValueError: cannot reshape array of size 1 into shape (2)` in 1.6.1

### Steps/Code to Reproduce

```py
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.inspection import PartialDependenceDisplay

np.random.seed(42)
n_samples = 1000
age = np.random.normal(35, 10, n_samples)
smoker = np.random.choice([0, 1], n_samples, p=[0.7, 0.3])
prob_disease = 1 / (1 + np.exp(-(age - 35) / 10 - 2 * smoker))
heart_disease = (np.random.random(n_samples) < prob_disease).astype(int)
df = pd.DataFrame({"age": age, "smoker": smoker, "heart_disease": heart_disease})
X = df[["age", "smoker"]]
y = df["heart_disease"]

rf_model = RandomForestClassifier(n_estimators=100, random_state=42)
rf_model.fit(X, y)

pdp_age = PartialDependenceDisplay.from_estimator(rf_model, X, features=[0, 1])
```

### Expected Results

PDP plots for age and smoker.

### Actual Results

```tb
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], [line 19](vscode-notebook-cell:?execution_count=1&line=19)
     [16](vscode-notebook-cell:?execution_count=1&line=16) rf_model = RandomForestClassifier(n_estimators=100, random_state=42)
     [17](vscode-notebook-cell:?execution_count=1&line=17) rf_model.fit(X, y)
---> [19](vscode-notebook-cell:?execution_count=1&line=19) pdp_age = PartialDependenceDisplay.from_estimator(rf_model, X, features=[0, 1])

File ~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:707, in PartialDependenceDisplay.from_estimator(cls, estimator, X, features, sample_weight, categorical_features, feature_names, target, response_method, n_cols, grid_resolution, percentiles, method, n_jobs, verbose, line_kw, ice_lines_kw, pd_line_kw, contour_kw, ax, kind, centered, subsample, random_state)
    [701](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:701)         raise ValueError(
    [702](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:702)             f"When a floating-point, subsample={subsample} should be in "
    [703](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:703)             "the (0, 1) range."
    [704](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:704)         )
    [706](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:706) # compute predictions and/or averaged predictions
--> [707](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:707) pd_results = Parallel(n_jobs=n_jobs, verbose=verbose)(
    [708](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:708)     delayed(partial_dependence)(
    [709](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:709)         estimator,
    [710](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:710)         X,
    [711](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:711)         fxs,
    [712](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:712)         sample_weight=sample_weight,
    [713](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:713)         feature_names=feature_names,
    [714](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:714)         categorical_features=categorical_features,
    [715](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:715)         response_method=response_method,
    [716](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:716)         method=method,
    [717](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:717)         grid_resolution=grid_resolution,
    [718](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:718)         percentiles=percentiles,
    [719](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:719)         kind=kind_plot,
    [720](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:720)     )
    [721](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:721)     for kind_plot, fxs in zip(kind_, features)
    [722](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:722) )
    [724](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:724) # For multioutput regression, we can only check the validity of target
    [725](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:725) # now that we have the predictions.
    [726](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:726) # Also note: as multiclass-multioutput classifiers are not supported,
    [727](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:727) # multiclass and multioutput scenario are mutually exclusive. So there is
    [728](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:728) # no risk of overwriting target_idx here.
    [729](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_plot/partial_dependence.py:729) pd_result = pd_results[0]  # checking the first result is enough

File ~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:77, in Parallel.__call__(self, iterable)
     [72](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:72) config = get_config()
     [73](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:73) iterable_with_config = (
     [74](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:74)     (_with_config(delayed_func, config), args, kwargs)
     [75](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:75)     for delayed_func, args, kwargs in iterable
     [76](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:76) )
---> [77](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:77) return super().__call__(iterable_with_config)

File ~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1918, in Parallel.__call__(self, iterable)
   [1916](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1916)     output = self._get_sequential_output(iterable)
   [1917](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1917)     next(output)
-> [1918](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1918)     return output if self.return_generator else list(output)
   [1920](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1920) # Let's create an ID that uniquely identifies the current call. If the
   [1921](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1921) # call is interrupted early and that the same instance is immediately
   [1922](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1922) # re-used, this id will be used to prevent workers that were
   [1923](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1923) # concurrently finalizing a task from the previous call to run the
   [1924](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1924) # callback.
   [1925](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1925) with self._lock:

File ~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1847, in Parallel._get_sequential_output(self, iterable)
   [1845](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1845) self.n_dispatched_batches += 1
   [1846](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1846) self.n_dispatched_tasks += 1
-> [1847](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1847) res = func(*args, **kwargs)
   [1848](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1848) self.n_completed_tasks += 1
   [1849](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/joblib/parallel.py:1849) self.print_progress()

File ~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:139, in _FuncWrapper.__call__(self, *args, **kwargs)
    [137](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:137)     config = {}
    [138](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:138) with config_context(**config):
--> [139](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/parallel.py:139)     return self.function(*args, **kwargs)

File ~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:216, in validate_params.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    [210](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:210) try:
    [211](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:211)     with config_context(
    [212](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:212)         skip_parameter_validation=(
    [213](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:213)             prefer_skip_nested_validation or global_skip_validation
    [214](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:214)         )
    [215](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:215)     ):
--> [216](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:216)         return func(*args, **kwargs)
    [217](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:217) except InvalidParameterError as e:
    [218](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:218)     # When the function is just a wrapper around an estimator, we allow
    [219](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:219)     # the function to delegate validation to the estimator, but we replace
    [220](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:220)     # the name of the estimator by the name of the function in the error
    [221](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:221)     # message to avoid confusion.
    [222](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:222)     msg = re.sub(
    [223](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:223)         r"parameter of \w+ must be",
    [224](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:224)         f"parameter of {func.__qualname__} must be",
    [225](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:225)         str(e),
    [226](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/utils/_param_validation.py:226)     )

File ~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:682, in partial_dependence(estimator, X, features, sample_weight, categorical_features, feature_names, response_method, percentiles, grid_resolution, method, kind)
    [676](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:676)     averaged_predictions = _partial_dependence_recursion(
    [677](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:677)         estimator, grid, features_indices
    [678](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:678)     )
    [680](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:680) # reshape averaged_predictions to
    [681](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:681) # (n_outputs, n_values_feature_0, n_values_feature_1, ...)
--> [682](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:682) averaged_predictions = averaged_predictions.reshape(
    [683](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:683)     -1, *[val.shape[0] for val in values]
    [684](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:684) )
    [685](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:685) pdp_results = Bunch(grid_values=values)
    [687](https://file+.vscode-resource.vscode-cdn.net/Users/vnijs/gh/pyrsm/examples/model/~/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/inspection/_partial_dependence.py:687) if kind == "average":

ValueError: cannot reshape array of size 1 into shape (2)
```
### Versions

```shell
System:
    python: 3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 08:22:19) [Clang 14.0.6 ]
executable: /Users/vnijs/miniconda/envs/msba/bin/python
   machine: macOS-14.2.1-arm64-arm-64bit

Python dependencies:
      sklearn: 1.6.1
          pip: 24.3.1
   setuptools: 75.1.0
        numpy: 2.2.1
        scipy: 1.15.1
       Cython: None
       pandas: 2.2.3
   matplotlib: 3.10.0
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: libomp
       filepath: /Users/vnijs/miniconda/envs/msba/lib/python3.12/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
```

COMMENT:
@lesteve Thanks for following up. If I am the only one reporting then maybe this is not so urgent. I'm using a docker container with my 150 students and have fixed usage to 1.5.2 for now.

Labels: Bug, Regression