Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBlanke committed Nov 26, 2022
1 parent d2cbfc3 commit d8880d0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,31 +288,34 @@ pip install hyperactive
```python
from sklearn.model_selection import cross_val_score
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.datasets import fetch_california_housing
from sklearn.datasets import load_diabetes
from hyperactive import Hyperactive

data = fetch_california_housing()
data = load_diabetes()
X, y = data.data, data.target

# define the model in a function
def model(opt):
# pass the suggested parameter to the machine learning model
gbr = GradientBoostingRegressor(
n_estimators=opt["n_estimators"]
n_estimators=opt["n_estimators"], max_depth=opt["max_depth"]
)
scores = cross_val_score(gbr, X, y, cv=3)
scores = cross_val_score(gbr, X, y, cv=4)

# return a single numerical value, which gets maximized
# return a single numerical value
return scores.mean()


# search space determines the ranges of parameters you want the optimizer to search through
search_space = {"n_estimators": list(range(10, 200, 5))}
search_space = {
"n_estimators": list(range(10, 150, 5)),
"max_depth": list(range(2, 12)),
}

# start the optimization run
hyper = Hyperactive()
hyper.add_search(model, search_space, n_iter=50)
hyper.run()

```

<br>
Expand Down

0 comments on commit d8880d0

Please sign in to comment.