Interview Query
~1 hrs
Machine Learning

Preprocessing Parity

Repair a preprocessing pipeline so training, validation, and inference agree. Includes Python starter code, CSV data, and tests. A focused practice adaptation of a reported Capital One Data Scientist assessment.

Capital OneCapital One
Data Scientist
Updated 16 days agoReviewed byIQIQ Team

Preprocessing Parity

A model's preprocessing looks reasonable in a notebook, but its assessment outputs differ from the expected values by a consistent factor. Repair the implementation, then make sure the same fitted transformation works on validation files and individual inference requests.

Format: focused take-home assignment. Suggested time: 60 minutes. Use Python 3.10 or later; no third-party packages or cloud services are required. You may use an AI assistant, but explain and test the code you submit.

This is a practice adaptation of the preprocessing portion of a candidate-reported Capital One Data Scientist assessment dated August 30, 2026. The report describes training-only fitting and a sample-standard-deviation convention. IQ created the data, starter code, missing-value contract, and tests below. This is not the complete assessment or official company material.

Your assignment

Repair solution.py without changing the required interfaces:

FunctionRequired behavior
fit(values)Learn a mean and sample standard deviation from observed training values only. Return a JSON-serializable dictionary with mean and scale.
transform(values, state)Return standardized values in the original order using the supplied state. Never fit on this batch.

The contract for this exercise is deliberately explicit:

  • Inputs are lists containing finite numbers or None. None means missing. Compute the training mean and sample variance over observed values only, before imputation. The variance denominator is the number of observed values minus one.
  • Reject training sets with fewer than two observed values by raising ValueError.
  • For a constant observed training feature, store scale=1.0. Its training values map to zero; future values can still express a deviation from its training mean.
  • Impute missing values with the stored training mean during transformation, so their standardized value is zero.
  • Empty inference batches return an empty list. Single-row batches must work. Transforming a row alone or alongside other rows must produce the same result.
  • Neither function may modify its input. transform must not modify the stored state. Saving that state to JSON and reloading it must preserve predictions within floating-point tolerance.
  • CSV files contain id,value; a blank value becomes None. Preserve row IDs and row order. The provided run_pipeline.py handles CSV input and output for you.

For a nonmissing value, the required transformation is (value - training_mean) / training_scale. Do not assume your preferred library uses the required variance convention by default.

Files and commands

FilePurpose
solution.pyIntentionally flawed implementation to repair.
run_pipeline.pyFits on training data, saves/reloads state, and writes transformed validation rows.
data/train.csvFour observed training values and one missing value.
data/validation.csvValues outside the training range and one missing value.
test_contracts.pyPublic acceptance tests. Add at least one meaningful test of your own.

From the extracted directory, run:

python3 -m unittest -v test_contracts
python3 run_pipeline.py

The starter is intentionally incorrect; its test failures are part of the exercise. The pipeline writes state.json and validation_transformed.csv. Inspect their contents after repairing the implementation. Do not weaken the supplied assertions to make the suite pass.

Explain the discrepancy

Use the observed training values [10, 20, 30, 40] to calculate the mean, sample standard deviation, and transformed value for 30. Compare that result with an implementation that divides the sum of squared deviations by n. Explain the multiplicative difference. Then calculate the transformed value for validation value 100 using the same training state.

Explain why refitting on a validation batch can hide this mismatch and make an individual prediction depend on unrelated rows. Distinguish a single-row inference request from a single-observation training set. Finally, describe one limitation of the constant-feature policy and one additional production check you would add.

Submit

Upload one PDF through this take-home's submission form. Include:

  1. Your repaired solution.py and the additional test, as readable code.
  2. Test output, the saved state, and the transformed validation CSV contents.
  3. Your worked calculations and a concise explanation of the defects, fixes, and remaining limitations.

Keep the explanation to roughly two pages, with code and test output in an appendix. No model training, external dataset, or presentation deck is required.

Review criteria

CriterionWeight
Correct training statistics, missing-value behavior, and edge cases40%
Consistent transformation without validation leakage or state mutation30%
Useful tests and reproducible artifacts20%
Clear reasoning about the discrepancy and limitations10%

Refitting during transformation or using the wrong variance convention is a correctness failure even if a small example happens to pass. Passing the public suite is supporting evidence, not a substitute for checking the contract.

Download project files