Feature Engineering & Selection
Turning raw data into model-ready inputs, and choosing which ones actually help.
- Minutes to read
- 4
- Practice MCQs
- 25
- Interview Q&A
- 25
- Edition
- v5
- Editorial status
- Reviewed
Scope: scikit-learn stable preprocessing, composition, selection, and inspection guidance and Google ML Crash Course feature guidance accessed 2026-08-31..
Curated: · Written: · Reviewed:
MCQ-1A fraud model scores transactions inside the authorization path, using only data present in the request or already recorded. Which training feature must be dropped because it is not available at scoring time?
Answer to see the discussion.
MCQ-2An offline feature store keeps every version of the `spend_30d` feature for entity `u1`, each row stamped with the time the value was true (`event_time`) and the time the row landed in the store (`ingestion_time`): | event_time | ingestion_time | value | | --- | --- | --- | | 2024-03-01 | 2024-03-02 | 120 | | 2024-03-04 | 2024-03-04 | 90 | | 2024-03-05 | 2024-03-09 | 200 | | 2024-03-07 | 2024-03-08 | 150 | The team is backfilling training rows for two prediction events on `u1`: P1 at 2024-03-06 and P2 at 2024-03-10. Each row must carry the feature value that was current at its prediction time, computed only from rows that had already been ingested by then. What does the point-in-time join produce?
Answer to see the discussion.
MCQ-3A team has one feature missing in 20% of its rows. They run 5-fold cross-validation to choose between two models, then refit the winner on the full training set and report one held-out test score. They need the CV score to estimate that test score. Where should the imputer's fill values be computed?
Answer to see the discussion.
MCQ-4A feature pipeline reads two columns from the same events table. `refund_amount` is documented as 'amount refunded; NULL means no refund was issued, i.e. 0.00'. `sensor_reading` is documented as 'last sensor value; NULL means the sensor failed to report'. Both are 8% NULL in the training window, and the team wants one imputation rule for both columns. Which rule is correct?
Answer to see the discussion.
MCQ-5A readmission model imputes serum lactate with the median. Lactate is missing for 28% of admissions because it is drawn only when infection is suspected. Adding a binary 'lactate drawn' flag beside the imputed column raises validation AUC from 0.79 to 0.83. Dropping the imputed column and keeping only the flag still gives 0.82. Which explanation fits?
Answer to see the discussion.
MCQ-6A team fits several models on one table where `annual_income` spans 20,000–400,000 and `years_at_job` spans 0–30, and they skip feature scaling. Which model's predictions are most distorted by that unit mismatch?
Answer to see the discussion.
MCQ-7A fraud-detection model trains on a split where feature amount takes the values [2, 4, 6]. The team fits scikit-learn's StandardScaler on that split, then transforms a validation row whose amount is 6. What value does the scaler output for that feature?
Answer to see the discussion.
MCQ-15A training pipeline applies `np.log(amount)` to an `amount` column of 1,000,000 orders. 32,000 orders are exactly 0.00 (refunds) and 4,000 are negative (chargebacks, e.g. −12.50). The transformed column comes out with `-inf` in 32,000 rows and `nan` in 4,000 rows. The team replaces the transform with `np.log(amount + 1e-9)`. For a refund row (amount = 0.00) and a chargeback row (amount = −12.50), what does the replacement produce?
Answer to see the discussion.
MCQ-14A demand model encodes hour h as the pair (sin(2πh/24), cos(2πh/24)). An engineer wants to confirm the encoding keeps 23:00 closer to 00:00 than to 20:00, so she measures Euclidean distance in the two-feature space. What two distances does she get?
Answer to see the discussion.
MCQ-9A linear model predicts delivery time and uses `city` as a feature. Training covers 12 cities, and the team has to report a separate coefficient for each one. About 3% of production requests carry a city that never appeared in training, and the scoring pipeline must not fail on them. Which encoding should the pipeline use?
Answer to see the discussion.
MCQ-10A team trains a logistic regression on a one-hot encoded `country` feature with scikit-learn 1.x: `OneHotEncoder(drop='first', handle_unknown='ignore')` fit on `['US', 'DE', 'JP', 'BR']`, so the encoder emits three columns (DE, JP, BR) and US is the dropped reference. In production a request arrives with `country='KR'`, a value that never appeared in training. How is that row's country block encoded, and how does the model score it?
Answer to see the discussion.
MCQ-8A pipeline one-hot encodes a 5,000-category column for 200,000 rows into a CSR matrix with one stored value per row, then subtracts the column means before fitting a linear model. The centered matrix no longer fits in memory. Which mechanism explains the blow-up?
Answer to see the discussion.
MCQ-11A team replaces a one-hot `publisher_id` feature (1.8M distinct values) with the hashing trick into 2^16 = 65,536 buckets. The global CTR is 0.05. After training, a publisher with 40 impressions and a historical CTR of 0.02 is scored at 0.31. The bucket it hashes to is also used by a publisher with 900,000 impressions and a historical CTR of 0.32. What is the most likely explanation?
Answer to see the discussion.
MCQ-12A fraud model target-encodes a high-cardinality `merchant_id` column with 5-fold out-of-fold encoding: rows in fold k are encoded using statistics from the other four folds only. The encoding is smoothed toward the global prior as `(positives + prior × α) / (rows + α)`, with prior = 0.10 and α = 20. Merchant `M-4471` appears in every fold. In fold 3 it has 15 rows, 9 of them fraud. Across the other four folds it has 60 rows, 12 of them fraud. What encoded value should the fold-3 rows of `M-4471` receive?
Answer to see the discussion.
MCQ-13A team trains a logistic regression on 3M ad impressions. Features are one-hot user_id (2M distinct users), one-hot ad_id (50k distinct ads), and a user_id × ad_id cross materialized over the full vocabulary: no hashing. Main effects are kept and the same L2 penalty applies to every feature. Training log loss falls every epoch, but held-out log loss rises after the first. What explains the held-out degradation?
Answer to see the discussion.
MCQ-18A fraud team has 1,000 labelled transactions, 20 of them fraudulent. Column `is_new_device` is 1 for 4 transactions, all four fraudulent, and 0 for the other 996. Column `amount_rounded` is 1 for 500 transactions, 10 fraudulent and 490 non-fraudulent. The team fits `VarianceThreshold(threshold=0.01)` on the raw binary matrix and trains a classifier on the surviving columns. What happens?
Answer to see the discussion.
MCQ-21A random forest (500 trees) is fit to 500 rows with a binary label, 20 real features, and one extra column `row_id` that is unique per row. Mean-decrease-in-impurity importance ranks `row_id` third of 21, above `tenure_months`, which permutation importance and a logistic regression both rank first. Dropping `row_id` leaves holdout AUC at 0.81, unchanged. What explains `row_id`'s rank?
Answer to see the discussion.
MCQ-20A team trains a gradient-boosted model on 400 features. Two of them, `sqft` and `rooms`, correlate at r = 0.94. Permutation importance on a held-out set scores each at a 0.002 AUC drop, yet removing both drops AUC from 0.91 to 0.72. What explains the low individual scores?
Answer to see the discussion.
MCQ-22A gradient-boosted churn model scores AUC 0.84 on a 20,000-row held-out set. Two of its inputs, `days_since_last_login` and `sessions_last_30d`, correlate at r = 0.97. Permuting `days_since_last_login` alone drops AUC to 0.839; permuting `sessions_last_30d` alone drops it to 0.838; permuting both together drops it to 0.71. What should the team conclude?
Answer to see the discussion.
MCQ-19A team has 400 labeled samples and 30,000 gene-expression features. Their pipeline ranks features by mutual information with the label, keeps the top k, and fits logistic regression. k is not fixed yet, and the team wants the reported score to cover the choice of k. Five-fold cross-validation gives AUC 0.93; a separate 400-row holdout gives 0.64. Where must the ranking step run for the CV number to estimate the whole pipeline on new samples?
Answer to see the discussion.
MCQ-17A team has 400 numeric features and 50k rows. It must pick 40 features once, before deciding which of three model families (linear, tree ensemble, small MLP) to ship, and the same 40 must be reused unchanged while all three are benchmarked. Selection reruns on every weekly data refresh and has to finish in under a minute. The team must also report which of the original named features were kept. Which approach fits?
Answer to see the discussion.
MCQ-23A model scores 0.91 AUC offline and 0.78 online. Training computes 40 features in Spark from daily Parquet snapshots; serving recomputes them in Python from raw request JSON. The two input streams have different distributions, offline AUC varies by ±0.02 across retrains, and the snapshot stores raw events and labels but not the computed feature vectors. Which test most directly detects training-serving transformation skew?
Answer to see the discussion.
MCQ-24A feature contract draft defines `avg_session_secs_7d` as "average session duration over the last 7 days". The training pipeline averages the 7 calendar days ending at the label date and drops sessions with duration 0; the serving pipeline averages the trailing 168 hours and keeps them. For one user, both windows cover the same 10 sessions, 4 of which have duration 0; the 6 non-zero sessions average 300 s. Training computes 300 s, serving computes 180 s. Which change to the contract removes the gap?
Answer to see the discussion.
MCQ-16A fraud model scores transactions with one numeric feature, `amount`, clipped to the training p99 of $400. In training, 1% of rows sat at the cap. Three weeks after launch, 18% of production rows sit at exactly $400 and the model's AUC has fallen from 0.91 to 0.78. What does the at-cap rate tell you?
Answer to see the discussion.
MCQ-25`user_7d_ctr` is written nightly at 02:00 into the online feature store with a 24-hour TTL, read online by `rank_v7` and offline by a nightly batch scorer. On Monday, after the 02:00 run, the team retires the feature by deleting the batch job. On Tuesday, `rank_v7`'s online NDCG@10 drops from 0.42 to 0.31, an offline replay over the training table still reports 0.42 for the same day, and the batch scorer is unchanged. What is the correct next step?
Answer to see the discussion.