I have a question about Calculating anomaly score for Anomaly detection using One-Class SVM. My question is that: How can I calculate it using decision_function(X), just the way I calculate anomaly score in Isolation forest? Thanks a lot,
3 Answers
In Isolation Forests, anomaly score is a measure of the deviation of average length of the path required to single out a particular observation from the average length of path required to single out a "normal" observation
The average here is taken over all the different trees that are used. Since SVM is not an ensemble method - this notion of anomaly score does not directly apply.
One way, and I don't know how statistically/scientifically sound this is, of measuring an anomaly score is to build multiple SVM classifiers based on a subset of predictors. You could then use the percentage of times a particular point is classified as an outlier as a proxy for an anomaly score.

- 4,654
- 1
- 19
- 35
Yes, you have to use decision_function()
as the measure of anomaly score in one class SVM.
Have a look at this example, you might get better understanding.
clf.decision_function(X_test)
# returns the signed distance to the separating hyperplane.
# Signed distance is positive for an inlier and negative for an outlier.

- 16,288
- 9
- 49
- 77
-
Thanks a lot for your reply, but any example on how to calculate anomaly score from calculating the decision_function()? – N T Dec 30 '18 at 11:50
-
I have given sample command in my answer, but go through the example link, which has more explanation about `OneClassSVM`. – Venkatachalam Dec 30 '18 at 13:42
This is a know issue by default scikit implementation does NOT provide an anomally score.
A way to tackle the issue is to use the decision_function (https://scikit-learn.org/stable/modules/generated/sklearn.svm.OneClassSVM.html#sklearn.svm.OneClassSVM.decision_function) but with the following way :
anomaly_metric[i] = max_value_decision_fn - decision_fn[i]
where i is the i-th data point.

- 1,064
- 12
- 22