You train a classifier and get 97% accuracy, but the business is unhappy because the model rarely catches the fraud cases it was built for. Fraud is 3% of all transactions. What is the most likely explanation?
- A. The model is overfitting the training data
- B. The dataset is imbalanced, so high accuracy reflects mostly predicting the majority class ✓
- C. The learning rate was set too high
- D. You need a larger neural network
Correct answer: B. With 3% fraud, a model predicting 'not fraud' every time scores 97% accuracy, so accuracy is misleading on imbalanced data and metrics like recall or precision-recall AUC are needed.
You fit a StandardScaler on your entire dataset and then split into train and test sets to evaluate a model. What is the problem with this workflow?
- A. StandardScaler should only be used on tree-based models
- B. It causes data leakage because test-set statistics inform the scaling applied to training data ✓
- C. Scaling must always be done after model training
- D. There is no problem; scaling before splitting is the recommended approach
Correct answer: B. Fitting the scaler on all data lets test-set information (mean/variance) leak into training, inflating performance; the scaler must be fit on the train set only and applied to the test set.
In pandas, you want to compute the average purchase amount per customer from a transactions DataFrame. Which approach is correct?
- A. df.groupby('customer_id')['amount'].mean() ✓
- B. df.sort_values('customer_id')['amount'].mean()
- C. df['amount'].mean().groupby('customer_id')
- D. df.pivot('customer_id')['amount']
Correct answer: A. groupby on customer_id followed by selecting the amount column and calling mean() produces the per-customer average, which is the standard pandas aggregation pattern.
Your Random Forest achieves near-perfect accuracy on training data but performs poorly on the validation set. Which action is most likely to help?
- A. Increase the maximum tree depth further
- B. Remove the validation set and train on all data
- C. Limit tree depth or increase min_samples_leaf to reduce overfitting ✓
- D. Switch the evaluation metric to training accuracy
Correct answer: C. The large train/validation gap indicates overfitting, and constraining tree complexity (shallower depth, larger leaf size) regularizes the forest and improves generalization.
You are running an A/B test comparing conversion rates between a control and a variant. After one day the variant looks better with p=0.04, so a colleague wants to ship it immediately. What is the best response?
- A. Ship it; p<0.05 means the result is definitely real
- B. Wait until the pre-determined sample size or duration is reached to avoid peeking-induced false positives ✓
- C. Re-run the test 10 times and average the p-values
- D. Switch to a one-tailed test to get a smaller p-value
Correct answer: B. Stopping a test early the moment significance appears (peeking) dramatically inflates the false-positive rate, so you should reach the pre-planned sample size before deciding.
You need to encode a categorical feature 'city' with about 500 unique values for a gradient-boosting model. Which approach is generally most practical?
- A. One-hot encode all 500 values, creating 500 new columns
- B. Drop the feature because it has too many categories
- C. Use target/mean encoding or group rare categories, being careful to avoid leakage ✓
- D. Convert the city names to their string length
Correct answer: C. For high-cardinality categoricals, target encoding or grouping rare levels is more practical than exploding into 500 sparse one-hot columns, provided encoding is computed within cross-validation folds to prevent leakage.
A stakeholder asks whether an outlier customer with a spend of 5,000,000 (versus a typical 200) should be summarized using the mean or the median for a 'typical customer spend' report. What do you advise?
- A. The mean, because it uses all data points
- B. The median, because it is robust to the extreme outlier ✓
- C. Neither; report only the maximum value
- D. The mean, but only after multiplying it by the outlier
Correct answer: B. The median is resistant to extreme values, so it better represents a 'typical' customer when a large outlier would drag the mean far above most observations.
You run a SQL query joining orders to customers and notice the result has more rows than the orders table. What is the most likely cause?
- A. You used a LEFT JOIN instead of an INNER JOIN
- B. The customers table has duplicate rows for the join key, causing row multiplication ✓
- C. SQL always returns extra rows after a join
- D. The ORDER BY clause duplicated the rows
Correct answer: B. When the join key is not unique on the joined side, each order matches multiple customer rows, multiplying the output row count, which is a common fan-out bug.
You are choosing between L1 (Lasso) and L2 (Ridge) regularization for a linear model with many features, and you also want automatic feature selection. Which is the better fit and why?
- A. L2, because it drives many coefficients exactly to zero
- B. L1, because it can shrink some coefficients exactly to zero, effectively selecting features ✓
- C. Neither affects coefficients; both only change the intercept
- D. L2, because it always yields sparser models than L1
Correct answer: B. L1's penalty can set coefficients exactly to zero, producing sparse models and built-in feature selection, whereas L2 shrinks coefficients toward but not exactly to zero.
During cross-validation on time-series data (predicting next month's sales), a teammate uses standard k-fold with random shuffling. Why is this problematic?
- A. k-fold is only valid for classification, not regression
- B. Random shuffling lets the model train on future data to predict the past, leaking temporal information ✓
- C. Time-series data cannot be cross-validated at all
- D. Shuffling reduces the number of folds automatically
Correct answer: B. Random k-fold ignores time order, so future observations end up in the training folds used to predict earlier points, leaking information; a forward-chaining/time-series split is required.