← Freddie Mac Interview Insights

Freddie Mac·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
Jul 2026Remote

Summary

Technical screen for a data scientist role at Freddie Mac. One question, but it was a beast. Basically a full take-home crammed into a live session covering pandas at scale, feature engineering with leakage constraints, and complexity analysis.

Questions Asked (1)

Q1

Given a 50-million-row monthly loan panel with columns for loan ID, MSA, month, property type, a 90-day delinquency flag, and unpaid balance, write pandas code to generate three leakage-safe features per loan-month: (a) a 12-month rolling delinquency rate by MSA and property type that excludes the current month, (b) a target-encoded property type delinquency rate per MSA using only data strictly before the current month, and (c) an exponentially weighted default intensity per loan with a 6-month half-life. Then explain how you'd keep memory under 16 GB, guarantee time-order correctness after any shuffles, and unit test edge cases like missing months or single-observation groups. What are the big-O tradeoffs?

Data ModelingTechnical Trade-offsSystem Design
Author's notes

This one took me a second to even parse fully.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the data schema and leakage constraints, then outline a vectorized pandas solution using groupby with shift and rolling/ewm operations. Emphasize time-order correctness, memory efficiency, and testing, and discuss computational trade-offs.

Pro tip: Use `groupby` with `shift(1)` before rolling/ewm to exclude the current month, and consider `pd.Series.rolling` with `closed='left'` for rolling windows to avoid leakage. For memory, downcast dtypes and use categoricals for MSA and property type.

1. Clarify requirements and data schema

Confirm the panel structure, time granularity, and definitions of delinquency and default. Ask about data size, memory constraints, and whether loans can have missing months.

2. Design leakage-safe feature engineering

For (a) and (b), use groupby with shift(1) to exclude current month, then rolling mean or expanding mean. For (c), use groupby ewm with halflife=6 after shifting.

3. Implement memory and performance optimizations

Downcast numeric types, convert MSA and property type to categorical, and process in chunks if needed. Use efficient groupby operations and avoid unnecessary copies.

4. Ensure time-order correctness and testing

Sort by loan and month before operations. After any shuffle, re-sort. Write unit tests for edge cases: missing months, single-observation groups, and leakage checks.

5. Analyze big-O tradeoffs

Discuss time complexity of groupby-rolling (O(n) per group) vs. expanding (O(n^2) worst-case) and memory tradeoffs of storing intermediate results.

Key Points to Mention

  • Leakage prevention: shift(1) before rolling/expanding/ewm to exclude current month.
  • Memory optimization: downcasting, categoricals, chunking, and avoiding full copies.
  • Time-order correctness: sorting by loan and month, and re-sorting after shuffles.
  • Unit testing: edge cases like missing months, single-observation groups, and verifying no leakage.
  • Big-O tradeoffs: rolling vs. expanding, groupby overhead, and ewm complexity.
  • Alternative approaches: using numpy for speed, or libraries like featuretools or tsfresh for time-series features.

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