This interview question evaluates core ML concepts, assumptions, math intuition, training/evaluation trade-offs, and practical failure modes in a realistic interview setting. A strong answer for Build a baseline linear regression pipeline states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Build a baseline linear regression pipeline in Python without code-completion tools: split the data into train/validation sets with a fixed random seed, impute missing values, one-hot encode categorical features, scale numeric features, train an ordinary least squares model, and evaluate it using RMSE and R^2 on the validation set while avoiding data leakage (fit transformers only on training data). Output the fitted coefficients, key metrics, and a brief interpretation of results.
Quick Answer: This interview question evaluates core ML concepts, assumptions, math intuition, training/evaluation trade-offs, and practical failure modes in a realistic interview setting. A strong answer for Build a baseline linear regression pipeline states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Task: Baseline Linear Regression Pipeline (Python)
Context
You are given a tabular dataset in a pandas DataFrame df. The goal is to predict a continuous target column target. Build a leakage-safe baseline linear regression pipeline and report performance and coefficients.
Requirements
Split the data into train/validation sets (e.g., 80/20) using a fixed random seed.
Avoid data leakage: fit imputers/encoders/scalers only on training data by using a single sklearn Pipeline.
Preprocess features:
Impute missing values: median for numeric, most_frequent for categorical.
One-hot encode categorical features (drop one level to avoid multicollinearity; ignore unknown categories at validation).
Scale numeric features (standardization).
Train an ordinary least squares linear regression model.
Evaluate on the validation set using RMSE and R^2.
Output:
Fitted coefficients with feature names (and intercept).
Key metrics (RMSE, R^2).
A brief interpretation of results.
Assumptions
DataFrame: df with target column named target; all remaining columns are features.
Deliverable
Provide clean, runnable Python code plus a short interpretation of the metrics and coefficients.
Constraints & Assumptions
Preserve the scope, facts, inputs, and requested outputs from the prompt above.
If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.
Clarifying Questions to Ask Guidance
Clarify the task, data shape, labels, constraints, and evaluation metric.
State assumptions behind the math or modeling technique you choose.
Connect theory to practical training, debugging, and deployment implications.
What a Strong Answer Covers Guidance
Correct definitions and formulas where the prompt requires them.
A practical explanation of how the method behaves on real data.
Trade-offs, failure modes, diagnostics, and mitigation strategies.
Evaluation choices that match the product or modeling objective.
Follow-up Questions Guidance
How would noisy labels, class imbalance, or distribution shift affect the answer?