mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-12 12:40:33 +08:00
Use optuna-fast-fanova if available
This commit is contained in:
@@ -11,33 +11,23 @@ Code files were originally taken from [Goptuna](https://github.com/c-bata/goptun
|
||||
You can install optuna-dashboard via [PyPI](https://pypi.org/project/optuna-dashboard/) or [Anaconda Cloud](https://anaconda.org/conda-forge/optuna-dashboard).
|
||||
|
||||
```
|
||||
# PyPI
|
||||
$ pip install optuna-dashboard
|
||||
```
|
||||
|
||||
```
|
||||
# Anaconda Cloud
|
||||
$ conda install -c conda-forge optuna-dashboard
|
||||
And you can also install following optional dependencies to make optuna-dashboard faster.
|
||||
|
||||
```console
|
||||
$ pip install optuna-fast-fanova gunicorn
|
||||
```
|
||||
|
||||
Then please execute `optuna-dashboard` command with Optuna storage URL.
|
||||
|
||||
```
|
||||
$ optuna-dashboard sqlite:///db.sqlite3
|
||||
Bottle v0.12.18 server starting up (using WSGIRefServer())...
|
||||
Listening on http://localhost:8080/
|
||||
Hit Ctrl-C to quit.
|
||||
```
|
||||
|
||||
Note that optuna-dashboard uses [wsgiref](https://docs.python.org/3/library/wsgiref.html) module by default.
|
||||
Although it requires no additional dependencies, it is NOT suitable for the production use.
|
||||
You can use [Gunicorn](https://gunicorn.org/) via "--server gunicorn" option.
|
||||
|
||||
```console
|
||||
$ pip install gunicorn
|
||||
$ optuna-dashboard sqlite:///db.sqlite3 --server gunicorn
|
||||
```
|
||||
|
||||
<details>
|
||||
|
||||
<summary>More command line options</summary>
|
||||
@@ -56,7 +46,7 @@ optional arguments:
|
||||
--port PORT port number (default: 8080)
|
||||
--host HOST hostname (default: 127.0.0.1)
|
||||
--server {wsgiref,gunicorn}
|
||||
server (default: wsgiref)
|
||||
server (default: auto)
|
||||
--version, -v show program's version number and exit
|
||||
--quiet, -q quiet
|
||||
```
|
||||
|
||||
@@ -3,17 +3,26 @@ from typing import Dict
|
||||
from typing import List
|
||||
from typing import Tuple
|
||||
|
||||
from optuna.importance import BaseImportanceEvaluator
|
||||
from optuna.importance import FanovaImportanceEvaluator
|
||||
from optuna.importance import get_param_importances
|
||||
from optuna.storages import BaseStorage
|
||||
from optuna.study import Study
|
||||
from optuna.trial import FrozenTrial
|
||||
from optuna.trial import TrialState
|
||||
|
||||
|
||||
try:
|
||||
from typing import TypedDict
|
||||
except ImportError:
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
import optuna
|
||||
from optuna.storages import BaseStorage
|
||||
from optuna.study import Study
|
||||
from optuna.trial import FrozenTrial
|
||||
from optuna.trial import TrialState
|
||||
try:
|
||||
from optuna_fast_fanova import (
|
||||
FanovaImportanceEvaluator as FastFanovaImportanceEvaluator,
|
||||
)
|
||||
except ImportError:
|
||||
FastFanovaImportanceEvaluator = None # type: ignore
|
||||
|
||||
|
||||
ImportanceItemType = TypedDict(
|
||||
@@ -54,7 +63,8 @@ class StudyWrapper(Study):
|
||||
def get_param_importance_from_trials_cache(
|
||||
storage: BaseStorage, study_id: int, objective_id: int, trials: List[FrozenTrial]
|
||||
) -> ImportanceType:
|
||||
n_completed_trials = len([t for t in trials if t.state == TrialState.COMPLETE])
|
||||
completed_trials = [t for t in trials if t.state == TrialState.COMPLETE]
|
||||
n_completed_trials = len(completed_trials)
|
||||
if n_completed_trials == 0:
|
||||
return {"target_name": target_name, "param_importances": []}
|
||||
|
||||
@@ -67,8 +77,16 @@ def get_param_importance_from_trials_cache(
|
||||
return cache_importance
|
||||
|
||||
study = StudyWrapper(storage, study_id, trials)
|
||||
importance = optuna.importance.get_param_importances(
|
||||
study, target=lambda t: t.values[objective_id]
|
||||
|
||||
evaluator: BaseImportanceEvaluator
|
||||
if FastFanovaImportanceEvaluator is not None:
|
||||
evaluator = FastFanovaImportanceEvaluator(completed_trials=completed_trials)
|
||||
else:
|
||||
evaluator = FanovaImportanceEvaluator()
|
||||
importance = get_param_importances(
|
||||
study,
|
||||
target=lambda t: t.values[objective_id],
|
||||
evaluator=evaluator,
|
||||
)
|
||||
converted = convert_to_importance_type(importance, trials)
|
||||
param_importance_cache[cache_key] = (n_completed_trials, converted)
|
||||
|
||||
@@ -80,11 +80,6 @@ def serialize_study_detail(
|
||||
if summary.datetime_start is not None:
|
||||
serialized["datetime_start"] = summary.datetime_start.isoformat()
|
||||
|
||||
if summary.best_trial is not None:
|
||||
serialized["best_trial"] = serialize_frozen_trial(
|
||||
summary._study_id, summary.best_trial
|
||||
)
|
||||
|
||||
serialized["trials"] = [
|
||||
serialize_frozen_trial(summary._study_id, trial) for trial in trials
|
||||
]
|
||||
|
||||
@@ -28,11 +28,11 @@ python_requires = >=3.6
|
||||
include_package_data = False
|
||||
packages = find:
|
||||
install_requires =
|
||||
bottle
|
||||
optuna>=2.4
|
||||
packaging
|
||||
bottle
|
||||
typing-extensions;python_version<'3.8'
|
||||
scikit-learn
|
||||
typing-extensions;python_version<'3.8'
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
|
||||
Reference in New Issue
Block a user