-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve user interface #195
Changes from 4 commits
b488761
75d5ae6
6dab835
daec70f
c0504de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
import pandas as pd | ||
|
||
from autoemulate.utils import get_mean_scores | ||
from autoemulate.utils import get_model_name | ||
from autoemulate.utils import get_model_scores | ||
|
||
try: | ||
__IPYTHON__ | ||
_in_ipython_session = True | ||
except NameError: | ||
_in_ipython_session = False | ||
|
||
if _in_ipython_session: | ||
from IPython.display import display, HTML | ||
|
||
|
||
def _print_cv_results(models, scores_df, model=None, sort_by="r2"): | ||
"""Print cv results. | ||
|
@@ -34,3 +45,84 @@ def _print_cv_results(models, scores_df, model=None, sort_by="r2"): | |
scores = get_model_scores(scores_df, model) | ||
print(f"Scores for {model} across all folds:") | ||
print(scores) | ||
|
||
|
||
def _print_setup(cls): | ||
"""Print the setup of the AutoEmulate object. | ||
|
||
If in an IPython session, the setup will be displayed as an HTML table. | ||
|
||
Parameters | ||
---------- | ||
cls : AutoEmulate | ||
The AutoEmulate object. | ||
""" | ||
if not cls.is_set_up: | ||
raise RuntimeError("Must run setup() before print_setup()") | ||
|
||
models = "\n- " + "\n- ".join( | ||
[ | ||
x[1].__class__.__name__ | ||
for pipeline in cls.models | ||
for x in pipeline.steps | ||
if x[0] == "model" | ||
] | ||
) | ||
metrics = "\n- " + "\n- ".join([metric.__name__ for metric in cls.metrics]) | ||
|
||
settings = pd.DataFrame( | ||
[ | ||
str(cls.X.shape), | ||
str(cls.y.shape), | ||
str(cls.train_idxs.shape[0]), | ||
str(cls.test_idxs.shape[0]), | ||
str(cls.param_search), | ||
str(cls.search_type), | ||
str(cls.param_search_iters), | ||
str(cls.scale), | ||
str(cls.scaler.__class__.__name__ if cls.scaler is not None else "None"), | ||
str(cls.reduce_dim), | ||
str( | ||
cls.dim_reducer.__class__.__name__ | ||
if cls.dim_reducer is not None | ||
else "None" | ||
), | ||
str(cls.cv.__class__.__name__ if cls.cv is not None else "None"), | ||
str(cls.folds), | ||
str(cls.n_jobs if cls.n_jobs is not None else "1"), | ||
], | ||
index=[ | ||
"Simulation input shape (X)", | ||
"Simulation output shape (y)", | ||
"# training set samples (train_idxs)", | ||
"# test set samples (test_idxs)", | ||
"Do hyperparameter search (param_search)", | ||
"Type of hyperparameter search (search_type)", | ||
"# sampled parameter settings (param_search_iters)", | ||
"Scale data before fitting (scale)", | ||
"Scaler (scaler)", | ||
"Dimensionality reduction before fitting (reduce_dim)", | ||
"Dimensionality reduction method (dim_reducer)", | ||
"Cross-validation strategy (cv)", | ||
"# folds (folds)", | ||
"# parallel jobs (n_jobs)", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one after thought here: Maybe this would be most useful if the argument names (rather than attribute names) would be in brackets. Would you agree? If so, the two things to change are:
to and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that makes sense. I was thinking that these should refer to any properties that exist on the object (hence, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See: c0504de There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, thanks @kallewesterling ! Feel free to merge! |
||
], | ||
columns=["Values"], | ||
) | ||
|
||
settings_str = settings.to_string(index=True, header=False) | ||
width = len(settings_str.split("\n")[0]) | ||
|
||
if _in_ipython_session: | ||
display(HTML("<p>AutoEmulate is set up with the following settings:</p>")) | ||
display(HTML(settings.to_html())) | ||
return | ||
|
||
print("AutoEmulate is set up with the following settings:") | ||
print("-" * width) | ||
print(settings_str) | ||
print("-" * width) | ||
print("Models:" + models) | ||
print("-" * width) | ||
print("Metrics:" + metrics) | ||
print("-" * width) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works well for me