April 2018
Beginner to intermediate
282 pages
6h 52m
English
The tree-based feature selection strategies used by random forests naturally rank by how well they improve the purity of the node. First, we need to construct a random forest model. We have already discussed the process to create a random forest model in Chapter 2, Introduction to Machine Learning using Python:
# Feature Importancefrom sklearn.ensemble import RandomForestClassifier# fit a RandomForest model to the datamodel = RandomForestClassifier()model.fit(X, Y)# display the relative importance of each attributeprint(model.feature_importances_)print(sorted(zip(map(lambda x: round(x, 4), model.feature_importances_),X)))
Once the model is constructed successfully, the model's feature_importance_ attribute ...