GridSearchCV does not seem to recognize whether estimators from StackingClassifier are fitted or not

### Describe the bug

There seems to be a bug with the combination of `GridSearchCV` and `StackingClassifier` when the parameter `cv` of  `StackingClassifier` is set to 'prefit'. With this option, the estimators of the `StackingClassifier` should be fitted before fitting the stacked model, and only the final_estimator would then be fitted. When including the `StackingClassifier` within `GridSearchCV` however, the fact that estimators have already been fitted does not seem to be recognized.



### Steps/Code to Reproduce

```python
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import GradientBoostingClassifier, StackingClassifier
from sklearn.model_selection import GridSearchCV

# Creating toy data set
n_features = 3
n_instances = 40
train = np.random.rand(n_instances, n_features)
label = np.random.randint(0,2,n_instances)

# Declaring estimators
log_clf = LogisticRegression()
gau_clf = GaussianNB()

# Fitting estimators
log_clf.fit(train, label)
gau_clf.fit(train, label)

# Creating stacked model
estimators = [
    ("log", log_clf),
    ("gau", gau_clf)
]

boost = GradientBoostingClassifier()
stack = StackingClassifier(estimators=estimators,
                          final_estimator=boost,
                          cv = 'prefit')

# Creating the Grid CV
param_search = {
    'final_estimator__max_depth': [1]
    }

gridcv = GridSearchCV(stack, 
                      param_grid=param_search)

# Fitting the stack and gridcv models
stack.fit(train, label) # works fine 
gridcv.fit(train, label) # sklearn.exceptions.NotFittedError: This LogisticRegression instance is not fitted yet. 
                         # Call 'fit' with appropriate arguments before using this estimator

```

### Expected Results

In the above code, the `stack` model works fine and no error related to the estimators' previous fitting is thrown.

However, when included in the GridSearchCV, the fact that estimator models have been fitted already does not seem to be recognized and a `sklearn.exceptions.NotFittedError` error is prompted. 



### Actual Results

```
Traceback (most recent call last):
  File "c:\Users\levesque\Documents\Python\AMEX\errorExample.py", line 39, in <module>
    gridcv.fit(train, label) # sklearn.exceptions.NotFittedError: This LogisticRegression instance is not fitted yet. Call 'fit' with appropriate
arguments before using this estimator
  File "C:\Users\levesque\Documents\Python\AMEX\env\lib\site-packages\sklearn\model_selection\_search.py", line 875, in fit
    self._run_search(evaluate_candidates)
  File "C:\Users\levesque\Documents\Python\AMEX\env\lib\site-packages\sklearn\model_selection\_search.py", line 1379, in _run_search
    evaluate_candidates(ParameterGrid(self.param_grid))
  File "C:\Users\levesque\Documents\Python\AMEX\env\lib\site-packages\sklearn\model_selection\_search.py", line 852, in evaluate_candidates
    _warn_or_raise_about_fit_failures(out, self.error_score)
  File "C:\Users\levesque\Documents\Python\AMEX\env\lib\site-packages\sklearn\model_selection\_validation.py", line 367, in _warn_or_raise_about_fit_failures
    raise ValueError(all_fits_failed_message)
ValueError:
All the 5 fits failed.
It is very likely that your model is misconfigured.
You can try to debug the error by setting error_score='raise'.

Below are more details about the failures:
--------------------------------------------------------------------------------
5 fits failed with the following error:
Traceback (most recent call last):
  File "C:\Users\levesque\Documents\Python\AMEX\env\lib\site-packages\sklearn\model_selection\_validation.py", line 686, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File "C:\Users\levesque\Documents\Python\AMEX\env\lib\site-packages\sklearn\ensemble\_stacking.py", line 584, in fit
    return super().fit(X, self._le.transform(y), sample_weight)
  File "C:\Users\levesque\Documents\Python\AMEX\env\lib\site-packages\sklearn\ensemble\_stacking.py", line 183, in fit
    check_is_fitted(estimator)
  File "C:\Users\levesque\Documents\Python\AMEX\env\lib\site-packages\sklearn\utils\validation.py", line 1345, in check_is_fitted
    raise NotFittedError(msg % {"name": type(estimator).__name__})
sklearn.exceptions.NotFittedError: This LogisticRegression instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
```

### Versions

```shell
System:
    python: 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
executable: C:\Users\levesque\Documents\Python\AMEX\env\Scripts\python.exe
   machine: Windows-10-10.0.17763-SP0

Python dependencies:
      sklearn: 1.1.2
          pip: 22.2.2
   setuptools: 57.4.0
        numpy: 1.23.1
        scipy: 1.9.0
       Cython: None
       pandas: 1.4.3
   matplotlib: 3.5.2
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
         prefix: vcomp
       filepath: C:\Users\levesque\Documents\Python\AMEX\env\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: C:\Users\levesque\Documents\Python\AMEX\env\Lib\site-packages\numpy\.libs\libopenblas.FB5AE2TYXYH2IJRDKGDGQ3XBKLKTF43H.gfortran-win_amd64.dll
        version: 0.3.20
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: C:\Users\levesque\Documents\Python\AMEX\env\Lib\site-packages\scipy\.libs\libopenblas.PZA5WNOTOH6FZLB2KBVKAURAKVTFSNNU.gfortran-win_amd64.dll
        version: 0.3.18
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8
```

COMMENT:
I believe this is because the search clones its estimator `stack`, and that in turn clones the base `stack.estimators` so that indeed they are not fitted when each hyperparameter setting attempts to fit.  This is called out (indirectly) in the [Glossary entry for metaestimators](https://scikit-learn.org/stable/glossary.html#term-metaestimators):

> In a meta-estimator’s [fit](https://scikit-learn.org/stable/glossary.html#term-fit) method, any contained estimators should be [cloned](https://scikit-learn.org/stable/glossary.html#term-cloned) before they are fit (although FIXME: Pipeline and FeatureUnion do not do this currently). An exception to this is that an estimator may explicitly document that it accepts a pre-fitted estimator (e.g. using `prefit=True` in [feature_selection.SelectFromModel](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectFromModel.html#sklearn.feature_selection.SelectFromModel)). One known issue with this is that the pre-fitted estimator will lose its model if the meta-estimator is cloned.

See also the broader issue #8370.

Is there precedent for overriding `clone` behavior by estimator, or would `clone` itself need a tweak to accommodate leaving base estimators along when `cv='prefit'`?  There are other `prefit` options around: `CalibratedClassifierCV` (not a likely candidate for prefit and cloning/searching, I'd guess) and `SelectFromModel` (where the parameter is `prefit [bool]` as opposed to `cv='prefit'` as here).

Labels: Bug, module:model_selection, module:base