---
title: "Leveraging PyFixest for High-Cardinality Marketplace Modeling at Instacart"
description: "Controlling for high-cardinality fixed effects (e.g. thousands of regions, shoppers or customers) makes standard OLS intractable, because each dummy variable expands the Gram matrix and matrix inversion scales as O(k³)."
url: "https://swe.quest/articles/leveraging-pyfixest-for-high-cardinality-marketplace-modeling-at-instacart-51b7ebdb06241104"
canonical: "https://tech.instacart.com/leveraging-pyfixest-for-high-cardinality-marketplace-modeling-at-instacart-3913df91a04b"
source: "Instacart Tech"
published: "2026-06-29"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 13
tags: ["python","algorithms","performance","scientific-computing"]
---

# Leveraging PyFixest for High-Cardinality Marketplace Modeling at Instacart

A post on [Instacart Tech](https://swe.quest/sources/instacart.md), published 2026-06-29, 13 min read, Deep dive. Original: [https://tech.instacart.com/leveraging-pyfixest-for-high-cardinality-marketplace-modeling-at-instacart-3913df91a04b](https://tech.instacart.com/leveraging-pyfixest-for-high-cardinality-marketplace-modeling-at-instacart-3913df91a04b)

## Summary

Controlling for high-cardinality fixed effects (e.g. thousands of regions, shoppers or customers) makes standard OLS intractable, because each dummy variable expands the Gram matrix and matrix inversion scales as O(k³). The Frisch-Waugh-Lovell theorem removes the dummy variables by demeaning, and the method of alternating projections handles multiple fixed effects by iteratively demeaning until the residual falls below a tolerance. A worked example shows convergence at a geometric rate. The post covers Instacart Marketplace's geo:time switchback and static-geo experiment designs. Benchmarks up to 20k categories show pyfixest consistently fastest with trivial memory use, compared with statsmodels (pinv dummies and mixedlm) and scikit-learn's sparse LSQR solver.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Python](https://swe.quest/tags/python.md) (Languages)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Scientific computing](https://swe.quest/tags/scientific-computing.md) (Domains)

## Prerequisites

- linear regression / OLS
- fixed effects models
- linear algebra basics
- A/B experiment design

## Keywords

PyFixest, fixest, Frisch-Waugh-Lovell theorem, method of alternating projections, statsmodels, scikit-learn, switchback experiments, Instacart

## Related posts

- [Variance Reduction Below the Randomization Grain](https://swe.quest/articles/variance-reduction-below-the-randomization-grain-0cacd97bb1a5531d.md): Instacart Tech · 2026-07-01 · Hard · 7 min read · Machine learning, E-commerce
  Instacart improves CUPED variance reduction for region-day switchback experiments by training an order-level model (gradient boosted trees) on pre-treatment features and aggregating its predictions to the region-day grain as the CUPED covariate.
- [TimesFM-3: A zero-shot foundation model for multivariate forecasting](https://swe.quest/articles/timesfm-3-a-zero-shot-foundation-model-for-multivariate-forecasting-c2421e383bcd85af.md): Google Research · 2026-08-31 · Hard · 6 min read · Machine learning, Model training, Inference & serving
  TimesFM-3 is a 330M-parameter decoder-only transformer pre-trained on over 1 trillion real and synthetic time points that does zero-shot multivariate forecasting, supporting multiple targets, past-only covariates and known-future covariates.
- [Introducing TabFM: A zero-shot foundation model for tabular data](https://swe.quest/articles/introducing-tabfm-a-zero-shot-foundation-model-for-tabular-data-3b60f0bd6faee92a.md): Google Research · 2026-06-30 · Easy · 5 min read · Machine learning, Model training, Analytics & OLAP
  TabFM is a foundation model that treats tabular classification and regression as in-context learning, so it predicts on an unseen table in a single forward pass with no training, hyperparameter tuning or feature engineering.
- [Building a dynamic inventory optimisation system: A deep dive](https://swe.quest/articles/building-a-dynamic-inventory-optimisation-system-a-deep-dive-21c9077c3e05644d.md): Zalando Engineering · 2025-06-29 · Medium · 9 min read · ML platforms, Machine learning, E-commerce, Data pipelines, Scaling
  Zalando's ZEOS builds replenishment recommendations by minimising a cost function that combines storage, lost sales, overstock, operations and inbound costs.
- [Forecasting Using ClickHouse Machine Learning Functions](https://swe.quest/articles/forecasting-using-clickhouse-machine-learning-functions-69c536e4a757b31c.md): ClickHouse · 2023-10-26 · Medium · 9 min read · Analytics & OLAP, Machine learning, SQL
  ClickHouse's built-in stochasticLinearRegression and evalMLMethod functions can fit and apply time-series forecasting models entirely in SQL, with no Python or R. Using monthly flight passenger data, a log-transformed target is regressed on a linear trend plus 12 month dummy variables, with no intercept to avoid the dummy variable trap.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
