Hi Nicolas, Thank you for the pointer. Since i didn’t know where to take the value of ‘scoring’ variable, this is what I did (by adapting to the example in scikit-learn web)
… X_test = np.r_[ND, AD] # fit the model clf = svm.OneClassSVM(nu=float(NU), kernel="rbf", gamma=float(GA)) scoring = clf.fit(LD).decision_function(X_test) pred = clf.predict(X_test) y_true = np.array([0]*500+[1]*500) fpr,tpr,thresholds = roc_curve(y_true,scoring) roc_auc = auc(fpr,tpr) plt.figure() plt.plot(fpr, tpr, label='ROC curve (area = %0.2f)' % roc_auc) plt.plot([0, 1], [0, 1], 'k--') plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('Receiver operating characteristic') plt.legend(loc="lower right") plt.show() … this however showed only the axis and diagonal dots without ROC curve (auc=0). How to fix this? Best, Ady On 10/20/15, Nicolas Goix <goix.nico...@gmail.com> wrote: > Hi, > You can do: > > ``` > from sklearn.metrics import roc_curve, auc > > X_test = np.r_[ND, AD] > pred = clf.predict(X_test) > > y_true = np.array([0] * 500 + [1] * 500) > > fpr, tpr, thresholds = roc_curve(y_true, scoring) > > # then you can plot(fpr, tpr) to get the roc curve and compute the AUC > with: > AUC = auc(fpr, tpr) > > ``` > > Best, > Nicolas > > 2015-10-20 3:41 GMT+02:00 Ady Wahyudi Paundu <awpau...@gmail.com>: > >> Hi all, >> >> Can I create ROC curve for one_class_SVM classifier? >> If I can, can you give pointer on how to do this? (or a link?) >> >> for example now i have: >> LD: normal data for learning (100 item) >> ND: normal data for evaluation (500 item) >> AD: abnormal data for evaluation (500 item) >> >> one_class_SVM code for evaluation would be something like this (NU and >> GA is user input): >> >> clf = svm.OneClassSVM(nu=float(NU), kernel="rbf", gamma=float(GA)) >> clf.fit(LD) >> y_pred_train = clf.predict(LD) >> y_pred_test = clf.predict(ND) >> y_pred_outliers = clf.predict(AD) >> n_error_train = y_pred_train[y_pred_train == -1].size >> n_error_test = y_pred_test[y_pred_test == -1].size >> n_error_outliers = y_pred_outliers[y_pred_outliers == 1].size >> >> how to produce ROC curve from there? >> >> Thanks in advance >> ~Ady >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Scikit-learn-general mailing list >> Scikit-learn-general@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general >> > ------------------------------------------------------------------------------ _______________________________________________ Scikit-learn-general mailing list Scikit-learn-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/scikit-learn-general