[PYTHON] One Class SVM implementation

0 Introduction

This article is written as a personal memo when implementing One Class SVM with sklearn. The points that I understood by reading other articles and the points that I want to remember are summarized using figures.

1 Preparation

The function to read is as follows. image.png

2 Data definition

This time, we define the following as training data, test data, and outlier data.

image.png

The graphs of X_train, X_test and X_outliers are as follows, respectively.

image.png

image.png

image.png

3 Data learning

image.png

The parameters used for training are displayed in clf.get_params image.png

In clf.decision_function (X_test), the distance from the discrimination boundary at each distribution point is shown, and a positive value means within the classification and a negative value means outside the classification. image.png

clf.predict (X_test) returns 1 or -1 to see if each given point is an outlier. image.png

The following is a table of predict and decision_function to check the range of X_outliers given as outliers.

image.png

Since there are many outliers, there are many data that are -1, but there are some that are 1, and it can be seen that they are within the learning data range.

image.png

4 Result display

image.png

sample_set_1 is a set of outlier data sets that were within the learning range, and sample_set_mina1 is a set of outlier data sets that were outliers.

The two points that are OK below are the points 1.

image.png

This is a simple implementation memo.

Recommended Posts

One Class SVM implementation
Outlier detection using One Class SVM
Outlier detection using One Class SVM
One Class SVM implementation
SVM implementation in python
class
class