8000 list of numeric categories of length 2 is considered as Real or Integer dimensions · Issue #1064 · scikit-optimize/scikit-optimize · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

list of numeric categories of length 2 is considered as Real or Integer dimensions #1064

Open
Abdelgha-4 opened this issue Sep 29, 2021 · 1 comment

Comments

@Abdelgha-4
Copy link

In skopt.Optimizer docs it said:

  • a (lower_bound, upper_bound) tuple (for Real or Integer dimensions) ...
  • as a list of categories (for Categorical dimensions) ...

however a list of length 2 is considered the same as a tuple.
a reproduceable example:

 from skopt import BayesSearchCV
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

X, y = load_iris(return_X_y=True)

searchcv = BayesSearchCV(
    RandomForestClassifier(),
    search_spaces={'n_estimators': [250, 500], 'max_features': (0.3, 0.95, 'uniform')},
    n_iter=10,
    cv=5,
    scoring='f1_macro',
    random_state=42
)

searchcv.fit(X, y)
print(searchcv.cv_results_['param_n_estimators'])

it shows that the optimizer tries many values between 250 and 500 and not just both values.

@QuentinSoubeyran
Copy link
Contributor

With the current code, there is no way to short-hand a Categorical of two numbers: even list or numpy.ndarray object go through the inference that is described for tuple objects.
To have the code do what you want, pass an explicit Categorical object:

import skop
from sklearn import datasets, ensemble
from skopt import space

X, y = datasets.load_iris(return_X_y=True)

searchcv = skopt.BayesSearchCV(
    ensemble.RandomForestClassifier(),
    search_spaces={
        "n_estimators": space.Categorical([250, 500]),
        "max_features": (0.3, 0.95, 'uniform')
    },
    n_iter=10,
    cv=5,
    scoring='f1_macro',
    random_state=42
)

searchcv.fit(X, y)
print(searchcv.cv_results_['param_n_estimators'])

I made #1067 to fix this issue, as well as #1065 which is related.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0