简体   繁体   中英

AxisError: axis 1 is out of bounds for array of dimension 1 when calculating roc_auc_score

rf = RandomForestClassifier(max_features=5, n_estimators=500)
rf.fit(d2_train_dataset, Y_train)

nb = GaussianNB()
nb.fit(d2_train_dataset, Y_train)

rf_probs = rf.predict_proba(d2_train_dataset)
nb_probs = nb.predict_proba(d2_train_dataset)

rf_probs = rf_probs[:, 1]
nb_probs = nb_probs[:, 1]

rf_auc = roc_auc_score(Y_test, rf_probs,multi_class="ovo")
nb_auc = roc_auc_score(Y_test, nb_probs,multi_class="ovo")

then this is the error "AxisError: axis 1 is out of bounds for array of dimension 1" in this cell

rf_auc = roc_auc_score(Y_test, rf_probs,multi_class="ovo")
nb_auc = roc_auc_score(Y_test, nb_probs,multi_class="ovo")

got the same problem, but this worked in my case, check my answer once

roc_auc_score(Y_test,rf_probs,multi_cass = "ovo",average= "weighted")

else, try without these two steps

rf_probs = rf_probs[:, 1]
nb_probs = nb_probs[:, 1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM