Edamame
Edamame

Reputation: 25366

python: how to properly call the feature_importances_() for the RandomForestClassifier

I use the following code to build a random forest model, and then I try to view the importance of each feature as following:

rf = RandomForestClassifier(n_estimators=100)
rf.fit(X, Y)
rf_feature_import = rf.feature_importances_()

but I got the error below:

    rf_feature_import = rf.feature_importances_()
TypeError: 'numpy.ndarray' object is not callable

Does anyone have any idea? Thank you!

Upvotes: 0

Views: 1679

Answers (1)

Matt Messersmith
Matt Messersmith

Reputation: 13747

If you get rid of the parens it should work:

rf_feature_import = rf.feature_importances_

See here: http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html

Upvotes: 3

Related Questions