Code Monkey home page Code Monkey logo

Comments (5)

LarsHH avatar LarsHH commented on May 26, 2024

Hi @michaelGK92 ,

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

Thanks,
Lars

from sherpa.

michaelGK92 avatar michaelGK92 commented on May 26, 2024

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())

from sherpa.

LarsHH avatar LarsHH commented on May 26, 2024

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.

from sherpa.

michaelGK92 avatar michaelGK92 commented on May 26, 2024

from sherpa.

AJster avatar AJster commented on May 26, 2024

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

from sherpa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.