How does Gower's distance enable nearest-neighbor computation on mixed numeric and categorical datasets?

Quick Overview

Asks how Gower's distance lets nearest-neighbor methods work on tables that mix numeric, categorical and ordinal columns. Tests whether you can explain per-feature scaling, weighting and missing values in a distance, and the cost and weaknesses of using it in KNN.

How does Gower's distance enable nearest-neighbor computation on mixed numeric and categorical datasets?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Nearest-neighbor methods need one distance between any two rows, but a table with ages, incomes, cities and product tiers has no natural shared unit. How does Gower's distance enable nearest-neighbor computation on mixed numeric and categorical datasets? ```hint One scale for every feature Ask what a per-feature dissimilarity would need to satisfy so that an age difference and a city mismatch can be averaged together. ``` ```hint From a distance to neighbors Once you have a pairwise distance that is not Euclidean, check which parts of a standard KNN implementation still work and which do not. ``` ### What a Strong Answer Covers - The per-feature dissimilarity for numeric, categorical, ordinal and binary features, and why each lands in [0, 1] - How the per-feature terms are combined, including weights and missing values - How to use the distance in a KNN implementation, and what it costs in time and memory - The weaknesses of the scaling choices and how to address them ### Follow-up Questions - A single extreme value stretches the range of a numeric feature. How would you change the numeric term? - How would you choose the feature weights instead of leaving them equal? - The dataset has 5 million rows. How would you find nearest neighbors with a mixed-type distance at that size? - How does Gower's distance compare with one-hot encoding plus Euclidean distance on standardized features?

Overview: Asks how Gower's distance lets nearest-neighbor methods work on tables that mix numeric, categorical and ordinal columns. Tests whether you can explain per-feature scaling, weighting and missing values in a distance, and the cost and weaknesses of using it in KNN.

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

Nearest-neighbor methods need one distance between any two rows, but a table with ages, incomes, cities and product tiers has no natural shared unit. How does Gower's distance enable nearest-neighbor computation on mixed numeric and categorical datasets?

What a Strong Answer Covers Guidance

  • The per-feature dissimilarity for numeric, categorical, ordinal and binary features, and why each lands in [0, 1]
  • How the per-feature terms are combined, including weights and missing values
  • How to use the distance in a KNN implementation, and what it costs in time and memory
  • The weaknesses of the scaling choices and how to address them

Follow-up Questions Guidance

  • A single extreme value stretches the range of a numeric feature. How would you change the numeric term?
  • How would you choose the feature weights instead of leaving them equal?
  • The dataset has 5 million rows. How would you find nearest neighbors with a mixed-type distance at that size?
  • How does Gower's distance compare with one-hot encoding plus Euclidean distance on standardized features?