Random Forest Feature Importance

Tree Models & Ensembles DS practice problem on Onlearn.

Difficulty: medium.

Topics: Understanding Random Forest Feature Importance Mechanisms, Gini Impurity, Mean Decrease in Impurity (MDI), Feature Importance Attribute, Random Forest Hyperparameters, Bias-Variance Tradeoff, Supervised Learning, Ensemble Methods, Statistical Inference, Feature Engineering, Model Interpretability, Decision Trees, Bagging Algorithms, Impurity Measures, Feature Selection, Variable Attribution.

Given a trained RandomForestClassifier from scikit learn, implement a function that calculates the Gini importance of each feature and returns a dictionary mapping feature names to their importance scores. You should handle the case where feature names are provided as a list.