-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using OneClassSVM for outliers detection example #1890
- Loading branch information
1 parent
9cab088
commit f107d00
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
python-scikit-learn/using-oneclasssvm-for-outliers-detection-example.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,34 @@ | ||
# Using OneClassSVM for outliers detection example | ||
|
||
```python | ||
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) | ||
``` | ||
|
||
- `from sklearn import` - import module from [lib:scikit-learn](https://onelinerhub.com/python-scikit-learn/how-to-install-scikit-learn-using-pip) | ||
- `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`) | ||
|
||
## Example: | ||
```python | ||
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) | ||
``` | ||
``` | ||
[ 1 1 -1 1 1 -1 1 1] | ||
``` | ||
|