Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Preprocessing for Model Ingestion

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Preprocessing for Model Ingestion. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement a preprocessing function for the Randstad Digital Belgium model-ingestion pipeline. Given raw records, convert selected numeric and categorical features into deterministic numeric vectors suitable for model input.

For numeric columns, replace None with the column median, then apply min-max normalization. If a column has the same value for every record, its normalized value must be 0.0. For categorical columns, replace None with the string "UNKNOWN", discover categories from the input batch, sort them lexicographically, and one-hot encode each value.

Return one vector per input record. Each vector must contain normalized numeric values first, followed by one-hot values for each categorical column in the order supplied by categorical_columns. Do not mutate the input records.

Formal Specification

  • rows is a non-empty list of dictionaries whose values are numbers, strings, or None.
  • numeric_columns and categorical_columns are lists of column names with no duplicates.
  • Every numeric column has at least one non-None value.
  • Return a list of lists containing only float values.
  • Median for an even number of values is the arithmetic mean of the two middle values.

Constraints

  • 1 <= len(rows) <= 10^4
  • 0 <= len(numeric_columns), len(categorical_columns) <= 50
  • The combined feature count is at most 500
  • Every numeric column has at least one non-None value
  • Column names within each column list are unique

Function Signature

def preprocess_dataset(rows, numeric_columns, categorical_columns):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output