Skip to content

Commit

Permalink
add data-sort-value attr to metrics table cells in "model params" and
Browse files Browse the repository at this point in the history
"training size" cols + bump [email protected]

closes Improper sorting on "Model Params" #124
  • Loading branch information
janosh committed Aug 19, 2024
1 parent 442abf9 commit c989f48
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 96 deletions.
27 changes: 14 additions & 13 deletions scripts/model_figs/metrics_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from matbench_discovery import PDF_FIGS, SCRIPTS, SITE_FIGS
from matbench_discovery.data import DataFiles, df_wbm
from matbench_discovery.enums import MbdKey, ModelType, Open
from matbench_discovery.enums import MbdKey, Open
from matbench_discovery.metrics import stable_metrics
from matbench_discovery.models import MODEL_METADATA
from matbench_discovery.preds import df_metrics, df_metrics_10k, df_metrics_uniq_protos
Expand Down Expand Up @@ -60,12 +60,16 @@
n_structs = train_set_meta["n_structures"]
n_materials = train_set_meta.get("n_materials", n_structs)
title = "Number of materials in training set"
train_size_str = f"<span {title=}>{si_fmt(n_materials, fmt='.0f')}</span>"
train_size_str = (
f"<span {title=} data-sort-value={n_materials}>"
f"{si_fmt(n_materials, fmt='.0f')}</span>"
)

if n_materials != n_structs:
title = "Number of materials (and structures) in training set"
train_size_str = (
f"<span {title=}>{si_fmt(n_materials, fmt='.1f')}</span> "
f"<span {title=} data-sort-value={n_materials}>"
f"{si_fmt(n_materials, fmt='.0f')}</span>"
f"<small {title=}>({si_fmt(n_structs, fmt='.1f')})</small>"
)

Expand All @@ -76,23 +80,20 @@
)

df_met.loc[Key.train_set.label, model] = train_size_str
model_params = model_data.get(Key.model_params, "")
model_params = model_data.get(Key.model_params, 0)
n_estimators = model_data.get(Key.n_estimators, -1)
title = "Number of models in ensemble"
n_estimators_str = (
f" <small {title=}>(N={n_estimators})</small>" if n_estimators > 1 else ""
)

model_type = model_data.get(Key.model_type, "")
title = ModelType.val_label_dict().get(model_type) or ""
df_met.loc[Key.model_type.label, model] = f"<span {title=}>{model_type}</span>"

title = "Number of trainable model parameters"
formatted_params = si_fmt(model_params)
df_met.loc[Key.model_params.label.replace("eter", ""), model] = (
f"<span {title=}>{si_fmt(model_params)}</span>{n_estimators_str}"
if isinstance(model_params, int)
else model_params
f'<span {title=} data-sort-value="{model_params}">{formatted_params}'
f"</span>{n_estimators_str}"
)

for key in (
MbdKey.openness,
Key.train_task,
Expand Down Expand Up @@ -194,10 +195,10 @@
na_rep="", # render NaNs as empty string
)
.background_gradient(
cmap="viridis", subset=list(higher_is_better & {*df_table}), axis=0
cmap="viridis", subset=list(higher_is_better & {*df_table}), axis="index"
)
.background_gradient( # reverse color map if lower=better
cmap="viridis_r", subset=list(lower_is_better & {*df_table}), axis=0
cmap="viridis_r", subset=list(lower_is_better & {*df_table}), axis="index"
)
)
# add up/down arrows to indicate which metrics are better when higher/lower
Expand Down
4 changes: 2 additions & 2 deletions scripts/wbm_umap_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def features_to_drop(df_in: pd.DataFrame, threshold: float = 0.95) -> list[str]:
df_wbm = pd.read_csv(wbm_matminer_feat_path).set_index(Key.mat_id)

# Drop all rows containing NaN values
df_wbm = df_wbm.dropna(axis=0)
df_mp = df_mp.dropna(axis=0)
df_wbm = df_wbm.dropna(axis="index")
df_mp = df_mp.dropna(axis="index")

# Drop highly correlated features
cols_to_drop = features_to_drop(df_mp, threshold=0.95)
Expand Down
2 changes: 1 addition & 1 deletion site/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default [
`error`,
{ argsIgnorePattern: `^_`, varsIgnorePattern: `^_` },
],
'@typescript-eslint/quotes': [`error`, `backtick`, { avoidEscape: true }],
'@/quotes': [`error`, `backtick`, { avoidEscape: true }],
'svelte/no-at-html-tags': `off`,
},
},
Expand Down
14 changes: 7 additions & 7 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
"devDependencies": {
"@iconify/svelte": "^4.0.2",
"@rollup/plugin-yaml": "^4.1.2",
"@sveltejs/adapter-static": "^3.0.2",
"@sveltejs/kit": "^2.5.20",
"@sveltejs/adapter-static": "^3.0.4",
"@sveltejs/kit": "^2.5.24",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"d3-scale-chromatic": "^3.1.0",
"elementari": "^0.2.3",
"eslint": "^9.8.0",
"eslint": "^9.9.0",
"eslint-plugin-svelte": "^2.43.0",
"hastscript": "^9.0.0",
"highlight.js": "^11.10.0",
"js-yaml": "^4.1.0",
"json-schema-to-typescript": "^15.0.0",
"katex": "^0.16.11",
"mdsvex": "^0.11.2",
"mdsvex": "^0.12.3",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.6",
"rehype-autolink-headings": "^7.1.0",
Expand All @@ -43,12 +43,12 @@
"svelte-multiselect": "^10.3.0",
"svelte-preprocess": "^6.0.2",
"svelte-toc": "^0.5.9",
"svelte-zoo": "^0.4.10",
"svelte-zoo": "^0.4.11",
"svelte2tsx": "^0.7.15",
"tslib": "^2.6.3",
"typescript": "5.5.4",
"typescript-eslint": "^8.0.1",
"vite": "^5.3.5"
"typescript-eslint": "^8.1.0",
"vite": "^5.4.1"
},
"prettier": {
"semi": false,
Expand Down
Loading

0 comments on commit c989f48

Please sign in to comment.