简体   繁体   中英

In Python sklearn.svm.OneClassSvm, how to calculate ROC and AUC only with predicted label and real label?

I am using Python 3.6,sklearn.svm.OneClassSVM to practice OSVM and I want to

calculate ROC, AUC.

I have used decision_function() to calculate ROC and AUC ,the code is below.

I want to evaluate the value that I calculate by decision_function.

Can I only use predicted label and real label to obtain ROC, AUC value?

     y_score = oneclass.decision_function(testing_data)
     roc_auc = metrics.roc_auc_score(Y_test, y_score)

I am not sure if I get your question complete correctly, but if you do this:

clf = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.1)
clf.fit(X_train)
y_pred_train = clf.predict(X_train)
y_score = clf.predict(X_test)

Then you should be able to use:

from sklearn.metrics import roc_auc_score
roc_auc_score(y_test, y_score)
``

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