Katkat

Fit logistic regression and return top features

RobloxData Scientist · Online Assessment

Last updated

This question evaluates understanding of binary logistic regression, coefficient-based feature importance, and practical model-fitting considerations such as intercept inclusion and input shape handling.

You are given:

  • X: a 2D numeric array where each row is a feature and each column is an observation (shape: n_features x n_samples).
  • feature_names: a list of length n_features.
  • y: a binary outcome array of length n_samples with values in {0, 1}.

Task:

  1. Fit a (binary) logistic regression model to predict y from X.
  • Include an intercept.
  • No regularization unless explicitly stated.
  1. Rank features by the absolute value of their fitted coefficients (exclude the intercept).
  2. Return the top 3 feature names by |coef| (break ties by lexicographic order of feature_names).

Output:

  • A list of 3 strings (feature names).