KatInterview

Reviewing Machine Learning Data Cleaning Code and Pipeline Design

Machine LearningModel answer
MediumModel answerMachine Learningdata-preprocessingscikit-learncode-review

Last updated

Evaluate an ML preprocessing codebase for design decisions, sklearn API conventions, data leakage prevention, code quality issues, and critical unit testing strategy.

You are conducting a code review of a team's feature engineering and data cleaning module. The codebase contains an OutlierHandler class along with three custom missing-value imputation classes (MeanImputer, MedianImputer, and ModeImputer).

Please provide a comprehensive review covering the following points:

  1. Functional Summary & Interface Design: Explain the core responsibility of OutlierHandler. Why is separating fit and transform critical for this functionality, especially within a production ML workflow?
  2. Code Maintainability & API Best Practices: Identify key maintainability, naming, and architectural issues commonly found in custom preprocessors (e.g., sklearn API compliance, state management, magic numbers).
  3. Critical Testing Strategy: Describe and write out the single most important unit test you would implement for OutlierHandler. Explain what specific failure mode it guards against.
  4. Imputation Modules Review: Explain the purpose of the three imputation classes, identify at least two significant code quality issues (such as from numpy import *), and suggest a cleaner design pattern.

Hints

Hint 1

Consider how data leakage occurs when test set statistics influence feature scaling or clipping.

Hint 2

Think about scikit-learn's estimator conventions, such as trailing underscores on learned attributes and returning self in fit.

Hint 3

Avoid testing implementation details: your primary unit test should verify that test data is transformed strictly using bounds calculated from training data.