crflynn / skranger

scikit-learn compatible Python bindings for ranger C++ random forest library
https://skranger.readthedocs.io/en/stable/
GNU General Public License v3.0
52 stars 7 forks source link

Feature importances are all "nan" with 'permutation' importance, and 'oob_error' = False ---- a very simple demonstration #156

Open mikez2333 opened 11 months ago

mikez2333 commented 11 months ago

I was having this problem, so I made a very simple test case.

(Note: I get importance values with 'permutation' if oob_error is True, and with other importance types in general.)

Ubuntu 22.04 LTS; Python 3.10

from skranger.ensemble import RangerForestClassifier
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

data = load_iris()
X = data.data
y = data.target
ranger_classifier = RangerForestClassifier(importance = "permutation")
ranger_classifier.fit(X, y)

rf_classifier = RandomForestClassifier()
rf_classifier.fit(X,y)
Debug Window (PyCharm)

ranger_classifier > feature_importances_ = {list: 4} [nan, nan, nan, nan]
                           > importance = {str} 'permutation'
                           > importance_mode_ = {int} 3

rf_classifier > feature_importances_ = {ndarray: (4,)} [0.10225579 0.02359158 0.45525929 0.41889333]