Comments (2)
@nzw0301 Thank you for your reply. #5118 seems to have a confusing objective, and the answers seem to solve the issue using features already implemented in Optuna.
The proposed feature here might also help in #5118 , but I would consider this as an independent issue. See below a diagram of the proposed structure. The role of Parent Wrapper is to allow the comparison between different runs of nested cross-validation, keeping the study database table organized and the optuna-dashboard tidy. Maybe we can adopt the term "Experiment" for this new class?
The results of individual Studies are irrelevant when assessing the results of nested cross-validation, as we are interested in the overall performance of all studies (i.e mean accuracy of the best model of each Study). The "Experiment" class could implement a method set_metric()
or equivalent to manually set the overall performance metric of the experiment. This Parent Wrapper could be used for different uses than nested cross-validation, allowing users to organize studies into groups.
I think users should not be forced to create an Experiment to be able to create Studies, as this would alter current implementations with Optuna and many users won't need Experiments at all. Instead, an Experiment object could be created and passed when creating Study objects. The Study database table could then store a Foreign Key to the parent Experiment. See below an example usage:
import optuna
import numpy as np
from sklearn.model_selection import KFold, cross_val_score
'''
Suppose that `X` and `y` are the input features and
input labels, respectively.
Suppose that `pipeline` is an sklearn Pipeline.
'''
search_spaces = {
'param_1': optuna.distributions.FloatDistribution(0.001, 0.4, log=True),
'param_2': optuna.distributions.IntDistribution(10, 500),
}
storage = 'sqlite:///example-storage.db'
# Here, we create the new Experiment object
experiment = Experiment(
experiment_name = 'nestedCV-1',
storage = storage
)
outer_scores = []
cv_outer = KFold()
for split, (train_idx, test_idx) in enumerate(cv_outer.split(X, y)):
study = optuna.create_study(
study_name=f'study_{split}',
storage=storage,
direction='maximize',
experiment=experiment # We assign this study to the experiment object we defined
)
X_train, X_test = X[train_idx], X[test_idx]
y_train, y_test = y[train_idx], y[test_idx]
def objective(trial):
trial_params = {key: trial._suggest(key, dist) for key, dist in search_spaces.items()}
pipeline.set_params(**trial_params)
cv_inner = KFold()
scores = cross_val_score(pipeline, X_train, y_train, cv=cv_inner)
return scores.mean()
study.optimize(objective, n_trials=100)
best_params = study.best_params
pipeline.set_params(**best_params)
pipeline.fit(X_train, y_train)
test_score = pipeline.score(X_test, y_test)
outer_scores.append(test_score)
experiment.set_metric('Mean Accuracy', np.mean(outer_scores)) # We add the overall performance metric (similar to `set_user_attr()`)
from optuna.
Thank you for feature request. Do you think #5118 is the same as this request?
from optuna.
Related Issues (20)
- Multi-criteria decision making
- Introduce lazy greedy algorithm to `_solve_hssp` HOT 3
- Add examples of newly added feature to the documents
- Support curved line parallel coordinate plot
- How optuna suggests parameters?
- TPESampler constant_liar=True with constrained optimization spams "Trial does not have constraint values. It will be treated as a lower priority than other trials." HOT 6
- Not executing the code
- AssertionError in _FanovaTree.get_marginal_variance(self, features) HOT 4
- Pandas Package import is not reinforced HOT 1
- Add a way to make the behavior of Optuna Terminator deterministic.
- Improvement to multivariate TPESampler when the union search space is different from the intersection search space
- Add a new class called `StudyJoblib` HOT 1
- Redis after Mar 10 2024 causes an error
- Intermediate values can take a different type from objective value HOT 1
- The reuse of optimal hyperparameters
- Early stopping with PyTorchLightningPruningCallback fails with OSError: [Errno 24] Too many open files HOT 5
- Replace the hyperlinks of integration files to ones in `optuna-integration` or move them to integration docs
- Support for duckdb HOT 3
- Implement Delta Lake as storage backend HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from optuna.