← Capital One Interview Insights

Capital One·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

Capital One data scientist interview that was basically one long coding problem about imputation pipelines. The whole thing revolved around leakage prevention which sounds straightforward but the requirements kept stacking up until it wasn't.

Questions Asked (4)

Q1

Given a user activity DataFrame with numeric, categorical, and time-ordered features plus a binary label, implement fit_imputers() and transform_impute() functions that handle all missing value imputation with strict train/validation leakage prevention.

Data ModelingTechnical Trade-offsAlgorithms & Data Structures
Author's notes

This is the kind of question that sounds like a clean engineering task until you actually read the spec.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: the functions must fit imputers on training data only and apply them to validation/test data without leakage. Then outline a modular design that handles numeric, categorical, and time-ordered features separately, using appropriate imputation strategies for each. Finally, discuss how to store the fitted imputers and ensure they are used consistently during transformation.

Pro tip: Emphasize that imputation parameters (e.g., mean, median, mode) must be learned solely from the training set and then applied to validation/test sets to prevent data leakage. Also, mention that for time-ordered features, forward-fill or backward-fill should be done within each dataset separately to avoid using future information.

1. Clarify Requirements and Data Types

Identify the types of features (numeric, categorical, time-ordered) and the binary label. Confirm that the functions must prevent leakage by fitting imputers only on training data.

2. Design fit_imputers()

For each feature type, compute imputation values from the training data: mean/median for numeric, mode or constant for categorical, and forward/backward fill for time-ordered. Store these values in a dictionary or object.

3. Design transform_impute()

Apply the stored imputation values to the validation/test data. For time-ordered features, apply fill within the validation set only, not using training data beyond the last value if appropriate.

4. Handle Edge Cases and Validation

Consider missing values in validation that were not present in training, and ensure imputation values are applied consistently. Validate that no leakage occurs by checking that imputation statistics are identical for train and validation.

5. Discuss Trade-offs and Alternatives

Mention alternative imputation methods (e.g., KNN, iterative imputer) and why simple methods might be preferred for leakage prevention and simplicity. Discuss how to handle time-ordered features without introducing future information.

Key Points to Mention

  • Train/validation leakage prevention: fit imputers only on training data, then apply to validation/test.
  • Different imputation strategies for numeric (mean/median), categorical (mode/constant), and time-ordered (forward/backward fill) features.
  • Storage of imputation parameters (e.g., in a dictionary) for consistent transformation.
  • Handling of time-ordered features: avoid using future data by filling within each dataset separately.
  • Edge cases: missing values in validation that were not seen in training, and how to handle them.
  • Trade-offs between simple imputation and more complex methods (e.g., KNN, iterative imputer) in terms of leakage risk and performance.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

For numeric features, how would you impute age using country-level medians and income using a regression model, without using the target label or any validation data?

Data ModelingTechnical Trade-offs
Author's notes

The age part is fine, group by country on train rows, store the medians, apply them.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the goal: impute missing age and income without leakage from the target or validation data. For age, use country-level medians computed only from the training data; for income, build a regression model using features other than the target, trained on complete cases within the training set. Emphasize that all imputation must be done within cross-validation folds to avoid data leakage.

Pro tip: When imputing income with regression, include the imputed age as a feature—but ensure the age imputation itself is done within the same fold to prevent leakage. Also, consider adding a missingness indicator for age and income, as missingness itself can be informative.

1. Clarify constraints and data split

Confirm that imputation must not use the target label or validation data, and that all statistics/models should be learned only from the training set. Emphasize the importance of avoiding leakage by performing imputation within cross-validation folds.

2. Impute age using country-level medians

Compute the median age per country using only the training data. For missing age values, fill them with the median of the corresponding country. If a country has no training data, fall back to the global median.

3. Build a regression model for income

Select features (excluding the target) that are predictive of income, such as age (now imputed), education, occupation, etc. Train a regression model (e.g., linear regression, random forest) on complete cases in the training set where income is observed.

4. Impute missing income using the model

Use the trained regression model to predict income for rows with missing income. Apply the same model within each cross-validation fold to avoid leakage.

5. Validate and iterate

Assess imputation quality using holdout data or cross-validation, but without using the target. Consider adding missingness indicators and compare different imputation strategies.

Key Points to Mention

  • Avoid data leakage: compute medians and train regression models only on training data, and within cross-validation folds.
  • Use country-level medians for age, with fallback to global median if a country has no data.
  • For income regression, exclude the target label and any validation data; use only features available at prediction time.
  • Consider including imputed age as a feature in the income regression, but ensure it's imputed within the same fold.
  • Add missingness indicators for age and income to capture potential informative missingness.
  • Evaluate imputation quality using cross-validation without the target, and consider multiple imputation if uncertainty matters.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

How do you implement time-ordered forward-fill for last_purchase_days_ago and session_length within each user, where propagation stops if the gap between consecutive event dates exceeds 14 days?

Data ModelingAlgorithms & Data Structures
Author's notes

This tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the data structure and requirements, then outline a window-function-based solution that partitions by user and orders by event date, using conditional logic to propagate values only when the date gap is ≤14 days. Emphasize handling edge cases like multiple events on the same day and the first event per user.

Pro tip: Mention that in production, you'd validate the 14-day gap logic with a quick sanity check on a sample of users to ensure the fill stops correctly, and consider performance implications for large datasets by using efficient window functions or iterative approaches if needed.

1. Clarify requirements and data schema

Confirm the input table structure (e.g., user_id, event_date, last_purchase_days_ago, session_length) and define what 'time-ordered forward-fill' means: fill missing values with the most recent non-null value within the same user, but only if the gap between consecutive event dates is ≤14 days.

2. Identify gaps and create groups

Use window functions to compute the date difference between consecutive events per user. Create a flag or group identifier that increments when the gap exceeds 14 days, effectively segmenting the user's timeline into blocks where forward-fill is allowed.

3. Apply forward-fill within groups

Within each user and group, use LAST_VALUE or FIRST_VALUE with IGNORE NULLS (or equivalent) to propagate the last non-null value forward. Ensure ordering by event_date and handle ties (same date) appropriately.

4. Handle edge cases and validate

Address cases like the first event having null values (no fill), multiple events on the same day (order by a secondary key if needed), and verify that propagation stops correctly after a >14-day gap. Test with sample data.

5. Discuss performance and alternatives

Mention that window functions are efficient for large datasets, but if the database lacks IGNORE NULLS support, an iterative approach or self-join may be needed. Also note the importance of indexing on (user_id, event_date).

Key Points to Mention

  • Partitioning by user_id and ordering by event_date to ensure per-user processing.
  • Using LAG to compute the gap between consecutive event dates and flagging gaps >14 days.
  • Creating a group identifier (e.g., cumulative sum of gap flags) to segment the timeline.
  • Applying forward-fill with LAST_VALUE IGNORE NULLS or equivalent within each group.
  • Handling ties (same event_date) by adding a secondary ordering column if necessary.
  • Validating the solution with edge cases: first event null, gap exactly 14 days, multiple gaps.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

For categorical columns like device_type and country, how would you impute missing values using per-user mode with a global train mode as a tiebreaker?

Data Modeling
Author's notes

Easier than the other parts but the tiebreaker detail is easy to skip.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain a two-level imputation strategy: first compute each user's most frequent category (mode) for the column, then fill missing values with that user-specific mode. For users with no non-missing values or ties, fall back to the global mode computed from the training set. Emphasize that the global mode must be derived only from training data to avoid leakage.

Pro tip: Mention that you would store the global mode as a fitted parameter and apply it consistently to validation/test sets, and consider adding a binary indicator for imputed values to preserve missingness information.

1. Compute per-user mode

Group the training data by user_id and calculate the mode of the categorical column for each user, ignoring missing values. This captures individual user preferences.

2. Compute global train mode

Calculate the overall mode of the categorical column across the entire training set. This serves as a fallback for users with no observed values or ambiguous modes.

3. Impute with per-user mode, fallback to global

For each missing value, fill it with the user's mode if available; otherwise use the global mode. Handle ties in per-user mode by using the global mode as a tiebreaker.

4. Apply to validation/test sets

Use the same per-user modes and global mode computed from the training set to impute missing values in validation and test sets, ensuring consistency and preventing data leakage.

Key Points to Mention

  • Data leakage prevention: compute global mode only on training data
  • Handling ties in per-user mode: use global mode as tiebreaker
  • Users with no non-missing values: fallback to global mode
  • Consistency: apply the same imputation logic to validation/test sets
  • Optional: add a missing indicator flag to preserve information
  • Scalability: consider efficient computation for large datasets (e.g., using groupby and mode)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.