sherpa-ai/sherpa

Dashboard not supported on Windows. Disable the dashboard and save the finalized study instead.How do I tackle this prblem

michaelGK92 opened this issue · 5 comments

Dashboard not supported on Windows. Disable the dashboard and save the finalized study instead.How do I tackle this prblem

Hi @michaelGK92 ,

Could you post your code? Then I will modify it accordingly.

Thanks,
Lars

the code is from your wiki.I test it on my python.when I use it in windows, it does not work.
the random forest.py
`from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
import time
import sherpa
import sherpa.algorithms.bayesian_optimization as bayesian_optimization

parameters = [sherpa.Discrete('n_estimators', [2, 50]),
sherpa.Choice('criterion', ['gini', 'entropy']),
sherpa.Continuous('max_features', [0.1, 0.9])]

algorithm = bayesian_optimization.GPyOpt(max_concurrent=1,
model_type='GP_MCMC',
acquisition_type='EI_MCMC',
max_num_trials=100)

X, y = load_breast_cancer(return_X_y=True)
study = sherpa.Study(parameters=parameters,
algorithm=algorithm,
lower_is_better=False)

for trial in study:
print("Trial ", trial.id, " with parameters ", trial.parameters)
clf = RandomForestClassifier(criterion=trial.parameters['criterion'],
max_features=trial.parameters['max_features'],
n_estimators=trial.parameters['n_estimators'],
random_state=0)
scores = cross_val_score(clf, X, y, cv=5)
print("Score: ", scores.mean())
study.add_observation(trial, iteration=1, objective=scores.mean())
study.finalize(trial)
print(study.get_best_result())

Hi @michaelGK92 ,

Try this code (inside sherpa.Study I added disable_dashboard=True).

from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
import time
import sherpa
import sherpa.algorithms.bayesian_optimization as bayesian_optimization

parameters = [sherpa.Discrete('n_estimators', [2, 50]),
sherpa.Choice('criterion', ['gini', 'entropy']),
sherpa.Continuous('max_features', [0.1, 0.9])]

algorithm = bayesian_optimization.GPyOpt(max_concurrent=1,
model_type='GP_MCMC',
acquisition_type='EI_MCMC',
max_num_trials=100)

X, y = load_breast_cancer(return_X_y=True)
study = sherpa.Study(parameters=parameters,
algorithm=algorithm,
disable_dashboard=True,
lower_is_better=False)

for trial in study:
    print("Trial ", trial.id, " with parameters ", trial.parameters)
    clf = RandomForestClassifier(criterion=trial.parameters['criterion'],
    max_features=trial.parameters['max_features'],
    n_estimators=trial.parameters['n_estimators'],
    random_state=0)
    scores = cross_val_score(clf, X, y, cv=5)
    print("Score: ", scores.mean())
    study.add_observation(trial, iteration=1, objective=scores.mean())
    study.finalize(trial)
    print(study.get_best_result())

study.save(".")

Then later you can do

import sherpa
sherpa.Study.load_dashboard(".")

from the same directory.

I installed ubuntu app on my windows, installed python and copied the file:
sudo cp -i /mnt/c/Users/.... /xyz.py

I run the code from ubuntu.
python3 xyz.py

my file includes:
import tempfile

model_dir = tempfile.mkdtemp()
...
study.save(model_dir)
print (model_dir)

opening the file e.g.:
import sherpa
sherpa.Study.load_dashboard("/tmp/tmpja_m1w61")

removing all tmp files:
cd /tmp
find . -type d -name 'tmp*' -exec rm -r {} ; -prune