9951 explained code solutions for 126 technologies


python-scikit-learnUsing OneClassSVM for outliers detection example


from sklearn import svm

X = [[0.32], [0.31], [0], [0.32], [0.31], [1], [0.32], [0.31]]

m = svm.OneClassSVM(gamma='auto').fit(X)
detected = m.predict(X)ctrl + c
from sklearn import

import module from scikit-learn

X =

example values set to detect outliers for

.OneClassSVM(

creates unsupervised outlier detection model

.fit(

train transformation model

.predict(

predict target variable based on given features dataset

detected

will contain a list of attributed outliers (-1) and values that are ok (1)


Usage example

from sklearn import svm

X = [[0.32], [0.31], [0], [0.32], [0.31], [1], [0.32], [0.31]]

m = svm.OneClassSVM(gamma='auto').fit(X)
detected = m.predict(X)

print(detected)
output
[ 1  1 -1  1  1 -1  1  1]