How would you cluster a dataset that mixes numeric and categorical features?

Quick Overview

Asks how to cluster tabular data that mixes numeric and categorical columns. Tests whether a candidate can pick a distance or algorithm that treats each feature type sensibly, weigh its cost at different data sizes, handle scaling and feature weights, and validate the clusters.

How would you cluster a dataset that mixes numeric and categorical features?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How would you cluster a dataset that mixes numeric and categorical features? For example, a customer table with age and tenure next to plan type and region. ```hint Start from the distance A clustering method is only as good as its notion of distance. Ask what a sensible distance between two rows looks like when one feature is a number and another is a category. ``` ```hint Check what a centroid means Think about what the mean of a set of one-hot columns represents, and which algorithms need a mean at all. ``` ### Clarifying Questions to Ask - Roughly how many rows are there? Some methods store every pairwise distance. - How many categorical features are there, and how many levels does the largest one have? - Will people read and act on the clusters as segments, or are they an input to another model? - Are there missing values, and are any of the categoricals ordered? ### What a Strong Answer Covers - Why one-hot encoding plus plain k-means gives distances and centroids that are hard to interpret - At least one distance or algorithm built for mixed types, and how it treats each feature type - The cost of each option and the dataset sizes it suits - How scaling and feature weights change the clusters - How to validate the resulting clusters ### Follow-up Questions - How would you choose the weight $\gamma$ in k-prototypes, and what happens when it is very small or very large? - How does Gower distance handle missing values and ordinal features? - The table grows to 5 million rows. Which of these options still work, and what would you change? - Why can't you run Ward linkage on a Gower distance matrix?

Overview: Asks how to cluster tabular data that mixes numeric and categorical columns. Tests whether a candidate can pick a distance or algorithm that treats each feature type sensibly, weigh its cost at different data sizes, handle scaling and feature weights, and validate the clusters.

General logo
General
Nov 24, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How would you cluster a dataset that mixes numeric and categorical features? For example, a customer table with age and tenure next to plan type and region.

Clarifying Questions to Ask Guidance

  • Roughly how many rows are there? Some methods store every pairwise distance.
  • How many categorical features are there, and how many levels does the largest one have?
  • Will people read and act on the clusters as segments, or are they an input to another model?
  • Are there missing values, and are any of the categoricals ordered?

What a Strong Answer Covers Guidance

  • Why one-hot encoding plus plain k-means gives distances and centroids that are hard to interpret
  • At least one distance or algorithm built for mixed types, and how it treats each feature type
  • The cost of each option and the dataset sizes it suits
  • How scaling and feature weights change the clusters
  • How to validate the resulting clusters

Follow-up Questions Guidance

  • How would you choose the weight γ\gamma in k-prototypes, and what happens when it is very small or very large?
  • How does Gower distance handle missing values and ordinal features?
  • The table grows to 5 million rows. Which of these options still work, and what would you change?
  • Why can't you run Ward linkage on a Gower distance matrix?