At repair intake, give a customer an estimate of the time until their repair is finished.
Independently estimate a new repair’s completion time at intake. Choose and justify the target, available features, split, metric and simple candidate(s). Build the workflow without viewing the solution first. Use actual numbers to explain baseline, validation, final result and limitations. The rubric is visible; reasoning requires self-review or lecturer review.
Next: Readiness · unfamiliar classification.
The question and data dictionary
At repair intake, give a customer an estimate of the time until their repair is finished.
One independent device per ticket, from a stable workshop period. No devices repeat and there is no time-order field. Either typical absolute error or stronger penalties for large errors can be defended.
| Column | Meaning and availability |
|---|---|
| ticket_id | Administrative identifier, assigned independently of the repair process. |
| jobs_waiting | Jobs already waiting at intake. |
| device_age_years | Device age in years, supplied at intake. |
| repair_hours | Elapsed hours from intake to completion. |
| invoice_labor_hours | Recorded on the completed repair invoice. |
The playground workflow
Use the same data boundary as ML → Workflow: frame, split, explore, prepare, validate against a reference, diagnose, then make the final evaluation. Each step answers one question.
- Question → X / yName the outcome and the inputs available when the prediction is needed. Later outcomes, identifiers and outcome-derived fields are not predictors.
- Split and protectReserve final rows before inspecting distributions or fitting. Independent rows permit a shuffled holdout; repeated entities or future forecasting need different designs.
- Explore training rowsInspect only development rows to identify types, missingness and class balance.
- Prepare → modelPut learned preparation inside a Pipeline so each fold learns it afresh. A numeric linear model can pass the original units through.
- Baseline → validateA dummy establishes what ignoring X achieves. Fit the candidate on matching training folds; these validation rows are not the final test.
- Choose → diagnoseChoose using training evidence, then inspect held-out training predictions. Simplify a model that fails to generalise; do not open the final test to choose.
- Final fit → predict → metricFix the recipe, fit all training rows, predict reserved rows once and calculate the declared metric from those saved predictions.
- Interpret and limitCompare validation with the baseline and final evidence. State units or class error costs, uncertainty from the small sample, and the population to which the claim applies.
Readiness rubric · self-review
For each criterion: 0 = missing or unsafe; 1 = plausible but unsupported; 2 = correct and supported by your actual evidence. Aim for 2 on every criterion. A target leak, test-driven selection or test-row fit means the boundary must be repaired before a readiness claim. Code checks cannot award these reasoning scores.
- Frame and boundaryName prediction time, observation, target and unavailable inputs. Choose a split that matches intended use.
- Preparation and baselineFit learned preparation inside each training fold. Compare the dummy on those same folds.
- Validation and selectionChoose from training-fold scores and error patterns. Explain any gap between training and validation.
- Metric and final testJustify the metric and interpret the reserved-test result. Do not revise the recipe using that result.
- Interpretation and limitsQuote baseline, validation and final results. Explain error units or costs, one failure case and one limit; avoid causal claims.
Use the interpretation field beside your output. After an attempt, Check identifies code evidence and shows reasoning guidance. The optional explained solution is one defensible approach, not the only acceptable answer.
Your inputs · REPAIR96
96 synthetic independent observations. The dataframe df is supplied afresh on each Run. Column availability is described in the question’s dictionary above.
| ticket_id | jobs_waiting | device_age_years | repair_hours | invoice_labor_hours |
|---|---|---|---|---|
| 9000 | 0 | 9.26451 | 10.1403 | 10.3403 |
| 9001 | 11 | 9.81364 | 28.5838 | 28.7838 |
| 9002 | 8 | 5.85919 | 19.8358 | 20.0358 |
| 9003 | 1 | 9.91347 | 13.1736 | 13.3736 |
| 9004 | 11 | 1.95552 | 20.1597 | 20.3597 |
| 9005 | 3 | 5.16693 | 12.8969 | 13.0969 |
| 9006 | 3 | 3.01649 | 11.314 | 11.514 |
| 9007 | 1 | 2.66753 | 8.30931 | 8.50931 |
Supporting concepts: When a good score is misleading → · Learn missing-value replacements safely → · Respect time →
Remember the idea
At repair intake, give a customer an estimate of the time until their repair is finished. Use the dictionary to frame a prediction claim. This dataset has not appeared in the teaching path. A working script is only one part of readiness: each decision also needs an evidence-based explanation.
Required Python variables and evidence
Use these names so Check can inspect your workflow. Each meaning is shown beside its name.
| Variable | Meaning |
|---|---|
| target / feature_names | Your outcome column name and list of legitimate inputs. Choose from the data dictionary. |
| X / y / X_train / X_test / y_train / y_test | Original indexed feature/target data and aligned partitions. A 15–30% holdout is supported; choose and justify its seed/design. |
| folds / metric | A 3–5-fold shuffled KFold or StratifiedKFold object; metric is an sklearn scoring name. Regression: neg_root_mean_squared_error or neg_mean_absolute_error. Classification: f1_macro or balanced_accuracy. |
| reference / reference_results | Dummy estimator and its actual cross_validate result. |
| candidates / cv_results | Named Pipelines and matching cross_validate result dictionaries. Regression supports LinearRegression, Ridge and DecisionTreeRegressor; classification supports LogisticRegression, DecisionTreeClassifier, KNeighborsClassifier, GaussianNB, LinearDiscriminantAnalysis, SVC and MLPClassifier. |
| diagnostic_predictions | Actual cross_val_predict outputs for the chosen candidate on training folds; inspect residuals or a confusion table. |
| chosen_name / final_model | Name of your chosen validated candidate and a clone fitted on all training rows. Defend the choice, including any simplicity trade-off. |
| final_predictions / final_score | One saved final prediction array and its final metric. Positive error units for regression. No further selection after this call. |
Hint 1 — Think
Independently estimate a new repair’s completion time at intake. Choose and justify the target, available features, split, metric and simple candidate(s). Build the workflow without viewing the solution first. Use actual numbers to explain baseline, validation, final result and limitations. The rubric is visible; reasoning requires self-review or lecturer review. At repair intake, give a customer an estimate of the time until their repair is finished. Which fields exist at that moment?
Hint 2 — Tools
Use a dataframe/series pair, train_test_split, Pipeline, cross_validate and a dummy suited to a numeric outcome.
Hint 3 — Approach
Keep final rows outside every fit. Compare matching training-fold evidence before predicting reserved rows in REPAIR96.
Explained solution
from sklearn.model_selection import train_test_split, KFold, cross_validate, cross_val_predict
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LinearRegression
from sklearn.dummy import DummyRegressor
from sklearn.base import clone
from sklearn.metrics import mean_squared_error
# 1. Question, features available now, and later outcome
feature_names = ['jobs_waiting', 'device_age_years']
target = 'repair_hours'
X, y = df[feature_names], df[target]
# 2. Protect the final test; split X and y together
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2, random_state=42)
# 3. Inspect training rows only
print(X_train.describe())
# 4. Define preparation and the candidate; no fitting yet
candidates = {'simple': Pipeline([('prepare', 'passthrough'), ('model', LinearRegression())])}
folds = KFold(n_splits=3, shuffle=True, random_state=42)
metric = 'neg_root_mean_squared_error'
# 5. Compare a reference and candidates on matching training folds
reference = DummyRegressor(strategy="mean")
reference_results = cross_validate(reference, X_train, y_train, cv=folds, scoring=metric)
cv_results = {'simple': cross_validate(candidates['simple'], X_train, y_train, cv=folds, scoring=metric, return_train_score=True)}
print('Reference validation:', reference_results['test_score'])
print('Candidate validation:', cv_results['simple']['test_score'])
print('Candidate minus dummy mean:', cv_results['simple']['test_score'].mean() - reference_results['test_score'].mean())
# 6. Assess the candidate with training evidence; inspect training-only errors
chosen_name = 'simple' # Sole candidate; report if it does not beat the dummy
diagnostic_predictions = cross_val_predict(candidates[chosen_name], X_train, y_train, cv=folds)
print(pd.DataFrame({'actual': y_train, 'predicted': diagnostic_predictions, 'residual': y_train-diagnostic_predictions}))
# 7. Fit the fixed recipe; predict the final rows once
final_model = clone(candidates[chosen_name]).fit(X_train, y_train)
final_predictions = final_model.predict(X_test)
final_score = np.sqrt(mean_squared_error(y_test, final_predictions))
print('Final metric:', final_score)
# 8. Explain the evidence and its limits in the self-review field
At repair intake, give a customer an estimate of the time until their repair is finished. The reference ignores features. Training-fold evidence informs the choice, and the final metric describes only the reserved sample. Excluding later outcomes prevents answering the question with information unavailable at prediction time. The reasoning rubric needs human review.
Helpful prior knowledge: When a good score is misleading · Supervised Workflow checkpoint These links are guidance, not locks.
Sources and API context
Examples run with this Playground’s scikit-learn 1.4.2 / Pyodide 0.26.4 runtime.