Thanks to visit codestin.com
Credit goes to github.com

Skip to content

incompatible HTML representation for RandomizedSearchCV #20971

@Abdelgha-4

Description

@Abdelgha-4

Describe the bug

I don't know if this is intended, but for now the HTML representation of a RandomizedSearchCV or GridSearchCV shows the estimators and parameters of the initialized pipeline instead of the 'optimized' one found in the search (best_estimator_).

Steps/Code to Reproduce

A simple setup

from sklearn.datasets import load_iris
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression, RidgeClassifier
from sklearn.svm import SVC
from sklearn.model_selection import RandomizedSearchCV
from sklearn.utils.fixes import loguniform
iris = load_iris()
pipeline = Pipeline([('clf', SVC())])
search_dists = [
    {'clf': [LogisticRegression(random_state=42)],
     'clf__C': loguniform(1e-2, 1e1),
     'clf__penalty': ['l1', 'l2']
    },
    {'clf': [RidgeClassifier(random_state=42)],
     'clf__alpha': loguniform(1e-2, 1e0)
    },
    {'clf': [SVC(random_state=42)],
     'clf__C': loguniform(1e-2, 1e2), 
     'clf__gamma': loguniform(1e-3, 1e0),
    }]
rand_search_cv = RandomizedSearchCV(pipeline, search_dists, n_jobs=-1, random_state=42)
rand_res = rand_search_cv.fit(iris.data, iris.target)

Try to view the HTML representation of the fitted RandomizedSearchCV

from sklearn import set_config
set_config(display='diagram')
# diplays HTML representation in a jupyter context of the initial `pipeline`
rand_res

image

Expected Results

I expected to see the same results as

from sklearn import set_config
set_config(display='diagram')
# diplays HTML representation in a jupyter context of the initial `pipeline`
rand_res.best_estimator_

image

Actual Results

I found the actual presentation irrelevant and doesn't make sense to have initial pipeline as result of visualizing a fitted GridSearch.

Versions

System:
python: 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37) [GCC 9.3.0]
executable: /opt/conda/bin/python
machine: Linux-5.4.120+-x86_64-with-debian-buster-sid

Python dependencies:
pip: 21.1.2
setuptools: 49.6.0.post20210108
sklearn: 0.24.2
numpy: 1.19.5
scipy: 1.6.3
Cython: 0.29.23
pandas: 1.2.4
matplotlib: 3.4.2
joblib: 1.0.1
threadpoolctl: 2.1.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions