Model Pipeline - Feature importance in regression
This pipeline shows how a regression model learns to predict a number from data and how we find which features matter most for the prediction.
This pipeline shows how a regression model learns to predict a number from data and how we find which features matter most for the prediction.
Loss 15.0 |***** 10.5 |**** 7.8 |*** 6.0 |** 5.2 |*
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 15.0 | N/A | Initial loss is high as model starts learning |
| 2 | 10.5 | N/A | Loss decreases as model fits data better |
| 3 | 7.8 | N/A | Loss continues to decrease steadily |
| 4 | 6.0 | N/A | Model is converging with lower loss |
| 5 | 5.2 | N/A | Loss stabilizes, model has learned key patterns |
feature importance tell us in a regression model?feature_importances_.predict() makes predictions, fit() trains the model, and score() evaluates performance, none return feature importance.from sklearn.ensemble import RandomForestRegressor import numpy as np X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]]) y = np.array([10, 20, 30, 40]) model = RandomForestRegressor(random_state=0) model.fit(X, y) print(model.feature_importances_)
from sklearn.ensemble import RandomForestRegressor model = RandomForestRegressor() print(model.feature_importances_)What is the problem?
feature_importances_ before training causes an AttributeError because the model has no learned features yet.fit() on training data before accessing feature_importances_.Pass the test and this pattern moves unknown