Fit logistic regression and return top features
RobloxData Scientist · Online AssessmentLast 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 lengthn_features.y: a binary outcome array of lengthn_sampleswith values in {0, 1}.
Task:
- Fit a (binary) logistic regression model to predict
yfromX.
- Include an intercept.
- No regularization unless explicitly stated.
- Rank features by the absolute value of their fitted coefficients (exclude the intercept).
- Return the top 3 feature names by
|coef|(break ties by lexicographic order offeature_names).
Output:
- A list of 3 strings (feature names).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.