Skip to content

Commit b0c7ed5

Browse files
author
Test User
committed
Day 74 (20:00): auto-format backend
1 parent 9cb920f commit b0c7ed5

3 files changed

Lines changed: 48 additions & 12 deletions

File tree

src/backend/api/chat.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4974,7 +4974,12 @@ def send_message(
49744974
_q_pt = (
49754975
"classification"
49764976
if _q_algo.endswith("_classifier")
4977-
or _q_algo in {"logistic_regression", "voting_classifier", "stacking_classifier"}
4977+
or _q_algo
4978+
in {
4979+
"logistic_regression",
4980+
"voting_classifier",
4981+
"stacking_classifier",
4982+
}
49784983
else "regression"
49794984
)
49804985
_q_rows = 0

src/backend/core/advisor.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,9 @@ def compute_model_quality_score(
13631363
"""
13641364
primary_metric, metric_name = _primary_metric(metrics, problem_type)
13651365

1366-
thresholds = _QUALITY_THRESHOLDS.get(problem_type, _QUALITY_THRESHOLDS["classification"])
1366+
thresholds = _QUALITY_THRESHOLDS.get(
1367+
problem_type, _QUALITY_THRESHOLDS["classification"]
1368+
)
13671369

13681370
# Determine base quality band
13691371
quality_label = "Needs Work"
@@ -1430,7 +1432,11 @@ def compute_model_quality_score(
14301432
cv_pct_std = round(cv_std * 100, 1)
14311433
reasoning.append(
14321434
f"5-fold cross-validation: {cv_pct_mean}% ± {cv_pct_std}% — "
1433-
+ ("consistent across splits." if is_stable else "results vary across splits.")
1435+
+ (
1436+
"consistent across splits."
1437+
if is_stable
1438+
else "results vary across splits."
1439+
)
14341440
)
14351441

14361442
if stability_note:
@@ -1442,7 +1448,9 @@ def compute_model_quality_score(
14421448
recommendation = _quality_recommendation(quality_label, problem_type, algorithm)
14431449

14441450
# Final quality_score: interpolate within band
1445-
quality_score = _compute_quality_score(primary_metric, problem_type, base_score, quality_label)
1451+
quality_score = _compute_quality_score(
1452+
primary_metric, problem_type, base_score, quality_label
1453+
)
14461454

14471455
return {
14481456
"quality_label": quality_label,
@@ -1474,7 +1482,9 @@ def _compute_quality_score(
14741482
quality_label: str,
14751483
) -> int:
14761484
"""Interpolate a 0–100 score within the quality band."""
1477-
thresholds = _QUALITY_THRESHOLDS.get(problem_type, _QUALITY_THRESHOLDS["classification"])
1485+
thresholds = _QUALITY_THRESHOLDS.get(
1486+
problem_type, _QUALITY_THRESHOLDS["classification"]
1487+
)
14781488
# Find band boundaries
14791489
band_min = 0.0
14801490
band_max = 1.0
@@ -1513,7 +1523,15 @@ def _quality_recommendation(
15131523
if quality_label == "Acceptable":
15141524
is_nonlinear = any(
15151525
kw in algorithm
1516-
for kw in ("forest", "gradient", "xgboost", "lgbm", "ensemble", "stacking", "voting")
1526+
for kw in (
1527+
"forest",
1528+
"gradient",
1529+
"xgboost",
1530+
"lgbm",
1531+
"ensemble",
1532+
"stacking",
1533+
"voting",
1534+
)
15171535
)
15181536
if not is_nonlinear:
15191537
return (

src/backend/tests/test_model_quality_score.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def test_cv_instability_downgrades_label():
9898
from core.advisor import compute_model_quality_score
9999

100100
# R²=0.90 would normally be Excellent; with cv_std=0.15 → Good
101-
r = compute_model_quality_score({"r2": 0.90, "cv_std": 0.15, "cv_mean": 0.85}, "regression")
101+
r = compute_model_quality_score(
102+
{"r2": 0.90, "cv_std": 0.15, "cv_mean": 0.85}, "regression"
103+
)
102104
assert r["quality_label"] == "Good"
103105
assert r["is_stable"] is False
104106

@@ -107,18 +109,24 @@ def test_cv_stability_no_downgrade_when_low():
107109
"""Low cv_std (≤ 0.10) does not downgrade."""
108110
from core.advisor import compute_model_quality_score
109111

110-
r = compute_model_quality_score({"r2": 0.90, "cv_std": 0.05, "cv_mean": 0.88}, "regression")
112+
r = compute_model_quality_score(
113+
{"r2": 0.90, "cv_std": 0.05, "cv_mean": 0.88}, "regression"
114+
)
111115
assert r["quality_label"] == "Excellent"
112116
assert r["is_stable"] is True
113117

114118

115119
def test_reasoning_bullets_present():
116120
from core.advisor import compute_model_quality_score
117121

118-
r = compute_model_quality_score({"r2": 0.73, "cv_mean": 0.71, "cv_std": 0.04}, "regression")
122+
r = compute_model_quality_score(
123+
{"r2": 0.73, "cv_mean": 0.71, "cv_std": 0.04}, "regression"
124+
)
119125
assert len(r["reasoning"]) >= 2
120126
assert any("R²" in b or "73" in b for b in r["reasoning"])
121-
assert any("cross-validation" in b.lower() or "cv" in b.lower() for b in r["reasoning"])
127+
assert any(
128+
"cross-validation" in b.lower() or "cv" in b.lower() for b in r["reasoning"]
129+
)
122130

123131

124132
def test_recommendation_populated():
@@ -143,7 +151,10 @@ def test_nonlinear_recommendation_for_linear_algo():
143151
{"accuracy": 0.72}, "classification", algorithm="logistic_regression"
144152
)
145153
# Acceptable + linear algo → suggest nonlinear algorithm
146-
assert "random" in r["recommendation"].lower() or "xgboost" in r["recommendation"].lower()
154+
assert (
155+
"random" in r["recommendation"].lower()
156+
or "xgboost" in r["recommendation"].lower()
157+
)
147158

148159

149160
def test_nonlinear_recommendation_skipped_for_ensemble():
@@ -167,7 +178,9 @@ def test_quality_score_within_range():
167178
def test_cv_fields_returned():
168179
from core.advisor import compute_model_quality_score
169180

170-
r = compute_model_quality_score({"r2": 0.80, "cv_mean": 0.78, "cv_std": 0.03}, "regression")
181+
r = compute_model_quality_score(
182+
{"r2": 0.80, "cv_mean": 0.78, "cv_std": 0.03}, "regression"
183+
)
171184
assert r["cv_mean"] == pytest.approx(0.78)
172185
assert r["cv_std"] == pytest.approx(0.03)
173186

0 commit comments

Comments
 (0)