One-Class Classification (OCC) 算法

原文:One-Class Classification Alogrithms for Imbalanced Datasets

In this tutorial, you will discover how to use one-class classification algorithms for datasets with severely skewed class distribution.

After completing this tutorial, you will know:

  • One-class classification is a field of machine learning that provides techniques for outlier and anomaly detection.
  • How to adapt one-class classification algorithms for imbalanced classification with a severely skewed class distribution.
  • How to fit and evaluate one-class classification algorithms such as SVM, isolation forest, elliptic envelope, and local outlier factor.

目录

  1. One-Class classification for Imbalanced Data;
  2. One-Class Support Vector Machines;

1. One-Class classification for Imbalanced Data;

The presence of outliers can cause problems. For example, a single variable may have an outlier far from the mass of examples, which can skew summary statistics such as the mean and variance.

One-Class classification (OCC) involves fitting a model on the “normal” data and predicting whether new data is normal or an anomaly.

“A one-class classifier aims at caputring characteristics of training instances, in order to be able to distinguish between them and potential outliers to appera.” — Page 139, Learning from Imbalanced Data Sets, 2018.

We will use the make_classification() function to create 9990 examples in majority class and 10 in the minority class.

# Generate and plot a synthetic imbalanced classification dataset
from collections import Counter
from sklearn.datasets import make_classification
from matplotlib import pyplot
from numpy import where
# define dataset
X, y = make_classification(n_samples=10000, n_features=2, n_redundant=0,
	n_clusters_per_class=1, weights=[0.999], flip_y=0, random_state=4)
# summarize class distribution
counter = Counter(y)
print(counter)
# scatter plot of examples by class label
for label, _ in counter.items():
	row_ix = where(y == label)[0]
	pyplot.scatter(X[row_ix, 0], X[row_ix, 1], label=str(label))
pyplot.legend()
pyplot.show()

在这里插入图片描述

2. One-Class Support Vector Machines

The main difference from a standard SVM is that it is fit in an unsupervised manner and does not provide the normal hyperparameters for tuning the margin.

from sklearn.svm import OneClassSVM
model = OneClassSVM(gamma='scale', nu=0.01)
trainX = X[y==0]
model.git(trainX)

testX = X[y==1]
print(model.predict(testX)

array([-1, -1, -1, -1, 1, -1, -1, 1, -1, -1])
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值