How can I interpret the scores generated by the function score_samples(X) from a scikit-learn OneClassSVM model? Is there a way to tell when one sample is "more anomalous" than other? The predict() and decision_function() functions have sign information, yet the score_samples function does not have this.

from sklearn.svm import OneClassSVM

X = [[0], [0.44], [0.45], [0.46], [1]]
clf = OneClassSVM(gamma='auto').fit(X)

# array([-1,  1,  1,  1, -1])

# array([1.7798..., 2.0547..., 2.0556..., 2.0561..., 1.7332...])

The sample_scores values, along with a cutoff threshold value, are used to determine whether a value is an outlier or not. You should be careful if you try to compare these sample_score values to see which values may be more anomalous than others. If you are looking to eliminate outliers solely to eliminate them from your data-set, using this value alone on a outlier would not be reason enough to eliminate it.

  • 1
    $\begingroup$ Are these values used for the end outlier/not-outlier results that the predict method outputs? if so, how are these used? $\endgroup$ – ElBrocas Jun 22 '20 at 15:56
  • 1
    $\begingroup$ Yes to your first question. If the sample_score is outside the cutoff threshold, they will be flagged as an outlier. $\endgroup$ – Donald S Jun 22 '20 at 23:27
  • $\begingroup$ Thanks for the response. In that case, how does the algorithm determines the cutoff threshold automatically? $\endgroup$ – ElBrocas Jun 23 '20 at 0:41
  • $\begingroup$ The algorithm is computing a decision boundary with minimal volume. Not sure of the exact mathematics used to determine this. If you want to change the threshold, you could look at the sample_scores values and create your own prediction based on a < or > threshold value of your own. Or you can look at this website for some ideas on how to add this threshold to the algorithm. pyod.readthedocs.io/en/latest/_modules/pyod/models/ocsvm.html $\endgroup$ – Donald S Jun 23 '20 at 1:29
  • $\begingroup$ Do you know if I can use these score values for calculating the rocauc score? This should be a good indicator if high values are corresponding to anomalies without the need for calculating a threshold? $\endgroup$ – user3352632 Mar 22 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.