ray-project / tune-sklearn

A drop-in replacement for Scikit-Learn’s GridSearchCV / RandomizedSearchCV -- but with cutting edge hyperparameter tuning techniques.
https://docs.ray.io/en/master/tune/api_docs/sklearn.html
Apache License 2.0
465 stars 52 forks source link

[bug] Random search algorithm perform only 1 trial regardless of the actual n_trials value given to TuneSearchCV #190

Closed mariesosa closed 3 years ago

mariesosa commented 3 years ago

Describe the bug

The random search algorithm perform only one trial regardless of the actual n_trials value given to TuneSearchCV.

Steps/Code to Reproduce

from tune_sklearn import TuneSearchCV
from ray import tune
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_blobs

# Create a test dataset
X, y = make_blobs(n_samples=1000, centers=2, n_features=5)

# Define the algorithm to optimize
clf = RandomForestClassifier()
params = {'max_depth': tune.randint(5, 20)}

# Perform hyperparameter optimization
tune_search = TuneSearchCV(
    clf, params, cv=5, scoring='roc_auc', random_state=0,
    search_optimization="random", n_trials=4
)
tune_search = tune_search.fit(X, y)
print("n_trials = %d" % tune_search.n_trials)

Expected Results

n_trials = 4

Actual Results

n_trials = 1

Versions

numpy==1.18.4 ray==1.2.0 scikit-learn==0.24.1 tune_sklearn==0.2.1

Yard1 commented 3 years ago

I believe this was fixed on master already. Could you install the development version with pip install -U git+https://github.com/ray-project/tune-sklearn.git and try again?

mariesosa commented 3 years ago

Indeed it works, and it was probably fixed by pull-request #180.