Skip to content

Commit 6703f55

Browse files
committed
create app from automl (#803)
1 parent 918f263 commit 6703f55

3 files changed

Lines changed: 74 additions & 6 deletions

File tree

supervised/apps/metadata.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def collect_app_metadata(automl, title=None, selected_models=None):
7474

7575

7676
def _default_title(automl):
77-
task = automl._ml_task.replace("_", " ").title() if automl._ml_task else "AutoML"
78-
return f"MLJAR AutoML {task} App"
77+
return "MLJAR AutoML"
7978

8079

8180
def _load_training_frame(automl):

supervised/apps/templates.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,44 @@ def csv_download_payload(df):
154154
return base64.b64encode(csv_data.encode("utf-8")).decode("ascii")
155155
156156
157+
def render_batch_dashboard(mr, scored_df):
158+
task = manifest()["model_task"]
159+
indicators = [mr.Indicator(value=str(len(scored_df)), label="Scored rows")]
160+
if task == "regression":
161+
prediction_series = pd.to_numeric(scored_df["prediction"], errors="coerce").dropna()
162+
if not prediction_series.empty:
163+
indicators.append(
164+
mr.Indicator(
165+
value=f"{float(prediction_series.mean()):.6g}",
166+
label="Mean prediction",
167+
)
168+
)
169+
indicators.append(
170+
mr.Indicator(
171+
value=f"{float(prediction_series.median()):.6g}",
172+
label="Median prediction",
173+
)
174+
)
175+
else:
176+
label_counts = scored_df["label"].astype(str).value_counts()
177+
if not label_counts.empty:
178+
top_label = str(label_counts.index[0])
179+
top_share = float(label_counts.iloc[0]) / float(len(scored_df))
180+
indicators.append(
181+
mr.Indicator(
182+
value=top_label,
183+
label="Most common label",
184+
)
185+
)
186+
indicators.append(
187+
mr.Indicator(
188+
value=f"{top_share:.1%}",
189+
label="Top label share",
190+
)
191+
)
192+
_ = mr.Indicator(indicators, display_now=True)
193+
194+
157195
def render_single_dashboard(mr, result):
158196
if result["task"] == "regression":
159197
_ = mr.Indicator(
@@ -468,7 +506,12 @@ def batch_notebook_source():
468506
import mercury as mr
469507
APP_IMPORT_ERROR = None
470508
try:
471-
from app_support import batch_predict, csv_download_payload, plot_batch_summary
509+
from app_support import (
510+
batch_predict,
511+
csv_download_payload,
512+
plot_batch_summary,
513+
render_batch_dashboard,
514+
)
472515
except Exception as exc:
473516
APP_IMPORT_ERROR = f"{type(exc).__name__}: {exc}"
474517
_ = mr.Markdown(
@@ -493,8 +536,10 @@ def batch_notebook_source():
493536
if error_message:
494537
_ = mr.Markdown(error_message)
495538
elif scored_df is not None:
496-
_ = mr.Markdown(f"## Scored rows\\n\\n`{len(scored_df)}`")
497-
_ = mr.Table(scored_df.head(20))
539+
_ = mr.Markdown(
540+
"## Batch prediction results\\n\\n"
541+
"Review the scored preview below and download the full predictions CSV."
542+
)
498543
mr.Download(
499544
csv_download_payload(scored_df),
500545
filename="predictions.csv",
@@ -503,12 +548,35 @@ def batch_notebook_source():
503548
label="Download predictions",
504549
position="inline",
505550
)
506-
plot_batch_summary(scored_df)
507551
else:
508552
_ = mr.Markdown("Upload a CSV file to begin batch prediction.")
509553
"""
510554
).strip()
511555
),
556+
code_cell(
557+
dedent(
558+
"""
559+
if scored_df is not None:
560+
render_batch_dashboard(mr, scored_df)
561+
"""
562+
).strip()
563+
),
564+
code_cell(
565+
dedent(
566+
"""
567+
if scored_df is not None:
568+
_ = mr.Table(scored_df.head(20))
569+
"""
570+
).strip()
571+
),
572+
code_cell(
573+
dedent(
574+
"""
575+
if scored_df is not None:
576+
plot_batch_summary(scored_df)
577+
"""
578+
).strip()
579+
),
512580
],
513581
"metadata": notebook_metadata("Batch Prediction"),
514582
"nbformat": 4,

tests/tests_automl/test_automl_app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_app_creates_default_workspace(self):
6262
manifest = json.load(fin)
6363

6464
self.assertEqual(manifest["bundle_type"], "automl_prediction_bundle")
65+
self.assertEqual(manifest["title"], "MLJAR AutoML")
6566
self.assertEqual(manifest["default_notebook"], "predict_single.ipynb")
6667
self.assertEqual(len(manifest["notebooks"]), 2)
6768
self.assertEqual(manifest["model_task"], "multiclass_classification")

0 commit comments

Comments
 (0)