← Capital One Interview Insights

Capital One·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Capital One data scientist interview that was basically a live code review session. They handed me Python preprocessing code and asked me to tear it apart, explain design decisions, and write a unit test on paper. More software-engineering-flavored than I expected for a DS role.

Questions Asked (3)

Q1

What does the OutlierHandler class do at a high level, and why is it beneficial to keep fit and transform as separate methods rather than combining them?

Technical Trade-offsSystem Design
Author's notes

I knew the scikit-learn pattern well enough to talk through it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the OutlierHandler class in simple terms: it's a preprocessing component that detects and handles outliers in data. Then explain the benefits of separating fit and transform, focusing on avoiding data leakage, enabling consistent application to new data, and supporting scikit-learn pipelines.

Pro tip: Emphasize that separating fit and transform is crucial for production ML systems because it ensures the same outlier handling logic is applied to training and inference data, preventing data leakage and maintaining model performance.

1. Define the OutlierHandler class

Explain that OutlierHandler is a custom transformer that identifies outliers (e.g., using IQR or z-score) and either removes, caps, or imputes them. Mention it follows the scikit-learn API with fit and transform methods.

2. Explain the fit method

Describe that fit learns the parameters needed for outlier detection (e.g., quartiles, mean, std) from the training data only. It does not modify the data.

3. Explain the transform method

Describe that transform applies the learned parameters to actually handle outliers in the data, such as clipping values beyond thresholds or removing outlier rows.

4. Discuss benefits of separation

Highlight that separating fit and transform prevents data leakage by ensuring parameters are learned only from training data. It also allows consistent application to validation, test, and production data, and integrates seamlessly with pipelines and cross-validation.

5. Connect to real-world impact

Relate this to Capital One's context: robust preprocessing is essential for reliable models, regulatory compliance, and scalable deployment. Mention that this design supports reproducibility and maintainability.

Key Points to Mention

  • Data leakage prevention: fitting only on training data avoids using information from validation/test sets.
  • Consistency: transform uses the same parameters for all datasets, ensuring uniform preprocessing.
  • Pipeline integration: scikit-learn pipelines rely on fit/transform separation for cross-validation and grid search.
  • Production readiness: fit once on training data, then transform new data in real-time or batch.
  • Modularity and reusability: the class can be easily swapped or combined with other transformers.
  • Statistical validity: outlier thresholds are based on training distribution, not contaminated by test data.

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

Q2

Looking at three provided Imputer classes, what coding style issues or import problems can you identify and critique?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

The wildcard import thing ('from numpy import *') was the obvious one and I caught it fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by systematically scanning each Imputer class for import statements, coding style, and design patterns. Then, group issues by category (imports, style, design) and prioritize the most critical ones. Finally, suggest concrete improvements and explain how they affect maintainability and correctness.

Pro tip: Demonstrate awareness of PEP 8 and common Python pitfalls, but also connect style issues to real-world impact like debugging difficulty or performance. Mention that in a production ML pipeline, consistent style and clean imports reduce integration errors.

1. Check imports

Verify that all necessary modules are imported, no unused imports exist, and imports follow PEP 8 ordering (standard, third-party, local).

2. Review coding style

Look for PEP 8 violations such as inconsistent indentation, line length, naming conventions (snake_case for functions/variables, CamelCase for classes), and missing docstrings.

3. Assess design and structure

Evaluate class design: are methods cohesive? Is there code duplication? Are there proper abstractions (e.g., base class for imputers)?

4. Identify potential bugs

Check for mutable default arguments, improper handling of missing values, or incorrect data type assumptions that could cause runtime errors.

5. Suggest improvements

Propose refactoring steps, such as using scikit-learn's BaseEstimator and TransformerMixin, adding type hints, and writing unit tests.

Key Points to Mention

  • PEP 8 compliance (indentation, line length, naming conventions)
  • Import organization and avoiding circular imports
  • Use of docstrings and comments for clarity
  • Avoiding mutable default arguments (e.g., def __init__(self, strategy='mean'))
  • Leveraging scikit-learn's BaseEstimator and TransformerMixin for consistency
  • Code duplication and opportunities for inheritance or composition

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

Q3

Write a critical unit test by hand for the OutlierHandler class. What would you test and how would you structure the assertion?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Writing code on paper is always a little humiliating.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the OutlierHandler's expected behavior and edge cases, then design a unit test that isolates the handler's logic using mocks or stubs for dependencies. Structure assertions to verify both the detection of outliers and the correct handling (e.g., removal, replacement) with precise expected values.

Pro tip: Demonstrate awareness of test maintainability by using parameterized tests for multiple outlier scenarios and asserting on specific error messages or logs to catch regressions.

1. Understand the Contract

Identify the OutlierHandler's public methods, input/output types, and expected behavior for normal and outlier data. Clarify any assumptions about thresholds or statistical methods.

2. Identify Test Cases

List critical scenarios: no outliers, single outlier, multiple outliers, boundary values (e.g., exactly at threshold), and invalid inputs (e.g., empty array, null).

3. Set Up Test Fixtures

Create sample datasets and mock any external dependencies (e.g., configuration, logging) to isolate the handler. Use a test framework like pytest or unittest.

4. Write Assertions

For each test case, call the handler and assert the output matches expectations. Use assertEqual for exact values, assertTrue/False for flags, and assertRaises for exceptions.

5. Review and Refactor

Ensure tests are readable, independent, and cover edge cases. Consider parameterization to reduce duplication and improve coverage.

Key Points to Mention

  • Boundary testing: values exactly at the outlier threshold to verify inclusive/exclusive behavior.
  • Mocking dependencies to ensure unit test isolation and speed.
  • Assertion specificity: checking both the transformed data and any side effects (e.g., logs, counters).
  • Parameterized tests for multiple outlier detection methods (e.g., Z-score, IQR).
  • Handling of missing or invalid input gracefully (e.g., raising ValueError with clear message).
  • Test naming conventions and documentation for maintainability.

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