Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error 'RandomForestClassifier' object has no attribute 'target_type_'

when I run this piece of code:

from yellowbrick.classifier import ROCAUC
from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(**{"max_features": 0.4, "n_estimators":15,"min_samples_leaf": 0.1,"random_state":42})
rf.fit(X_train, y_train)
roc_viz = ROCAUC(rf)
roc_viz.score(X_test, y_test)

I have this error

'RandomForestClassifier' object has no attribute 'target_type_'

Somebody has an idea ? Thank you

And when I debug, at the instruction roc_viz = ROCAUC(rf)

I get the error:

unable to get repr for <class 'yellowbrick.classifier.rocauc.ROCAUC'

like image 910
mab66 Avatar asked Sep 05 '26 10:09

mab66


1 Answers

A couple of things

  1. You always need to fit the visualizer

  2. If you have already fitted your model then you must set the param is_fitted to True

    rf = RandomForestClassifier(**{"max_features": 0.4, "n_estimators":15,"min_samples_leaf": 0.1,"random_state":42})

    rf.fit(X_train, y_train)

    roc_viz = ROCAUC(rf, is_fitted=True)

    roc_viz.fit(X_train, y_train)

    roc_viz.score(X_test, y_test)

like image 51
larrywgray Avatar answered Sep 09 '26 05:09

larrywgray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!