When would you use an ANOVA F-test versus a chi-squared test for univariate feature selection?

Quick Overview

A feature engineering question on choosing between the ANOVA F-test and the chi-squared test for univariate feature selection. It tests whether you can match each test to feature and target types, state its input requirements in practice, and explain what univariate filters miss.

When would you use an ANOVA F-test versus a chi-squared test for univariate feature selection?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

When would you use an ANOVA F-test versus a chi-squared test for univariate feature selection? Assume you are scoring each feature on its own against the target, for example with scikit-learn's `SelectKBest`, and keeping the top-scoring ones. ```hint Start from the data types Look at the type of the feature and the type of the target, then ask what each test actually compares. ``` ```hint Check the inputs Look at what scikit-learn's `chi2` does with the raw feature values, and what that implies for negative or label-encoded columns. ``` ### What a Strong Answer Covers - What each test measures and the feature and target types each one fits. - The input requirements in practice, including the non-negativity requirement for chi-squared in scikit-learn. - What each test cannot detect, including dependence that leaves the class means unchanged. - The shared limits of univariate selection and an alternative for non-linear dependence. ### Follow-up Questions - Why can't you pass a label-encoded categorical column with values 0 to 9 straight into scikit-learn's `chi2`? - How would you choose `k` in `SelectKBest` without leaking information from the validation folds? - Your continuous feature is heavily skewed with large outliers. Is the F-test still a good choice? - When would you prefer model-based selection, such as L1 regularization or tree importance, over any univariate test?

Overview: A feature engineering question on choosing between the ANOVA F-test and the chi-squared test for univariate feature selection. It tests whether you can match each test to feature and target types, state its input requirements in practice, and explain what univariate filters miss.

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

When would you use an ANOVA F-test versus a chi-squared test for univariate feature selection?

Assume you are scoring each feature on its own against the target, for example with scikit-learn's SelectKBest, and keeping the top-scoring ones.

What a Strong Answer Covers Guidance

  • What each test measures and the feature and target types each one fits.
  • The input requirements in practice, including the non-negativity requirement for chi-squared in scikit-learn.
  • What each test cannot detect, including dependence that leaves the class means unchanged.
  • The shared limits of univariate selection and an alternative for non-linear dependence.

Follow-up Questions Guidance

  • Why can't you pass a label-encoded categorical column with values 0 to 9 straight into scikit-learn's chi2 ?
  • How would you choose k in SelectKBest without leaking information from the validation folds?
  • Your continuous feature is heavily skewed with large outliers. Is the F-test still a good choice?
  • When would you prefer model-based selection, such as L1 regularization or tree importance, over any univariate test?