How would you explore categorical variables, including cardinality, rare categories, and class imbalance?

Quick Overview

Asks how to explore categorical variables during exploratory analysis, covering cardinality, rare categories and class imbalance. Tests practical pandas habits, data quality checks, and how these findings shape encoding, sampling and metric choices.

How would you explore categorical variables, including cardinality, rare categories, and class imbalance?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

How would you explore categorical variables, including identifying cardinality, rare categories, and potential class imbalance? ```hint Counts first Start from frequency counts, then look at them as a share of rows and as a cumulative share. ``` ```hint Small groups mislead When you compare the target across levels, check how many rows sit behind each number. ``` ### What a Strong Answer Covers - How to measure cardinality and what high cardinality means for encoding - How to find rare levels and what to do with them, including which data that decision should be based on - How to check the target's class balance and what imbalance changes downstream - Data quality problems inside a categorical column, including missing values and inconsistent labels - How to relate levels to the target without over-reading small groups ### Follow-up Questions - How would you encode a feature with 50,000 levels for a gradient-boosted model? - How do you avoid target leakage when you use target encoding? - How would you handle a level that appears in production but never appeared in training? - With a 1% positive rate, how would you set up the train and test split and choose an evaluation metric?

Overview: Asks how to explore categorical variables during exploratory analysis, covering cardinality, rare categories and class imbalance. Tests practical pandas habits, data quality checks, and how these findings shape encoding, sampling and metric choices.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

How would you explore categorical variables, including identifying cardinality, rare categories, and potential class imbalance?

What a Strong Answer Covers Guidance

  • How to measure cardinality and what high cardinality means for encoding
  • How to find rare levels and what to do with them, including which data that decision should be based on
  • How to check the target's class balance and what imbalance changes downstream
  • Data quality problems inside a categorical column, including missing values and inconsistent labels
  • How to relate levels to the target without over-reading small groups

Follow-up Questions Guidance

  • How would you encode a feature with 50,000 levels for a gradient-boosted model?
  • How do you avoid target leakage when you use target encoding?
  • How would you handle a level that appears in production but never appeared in training?
  • With a 1% positive rate, how would you set up the train and test split and choose an evaluation metric?