将SMV"ovo"与随机进样器一起使用



我正在使用不平衡数据集进行分类。我了解sklearn的SVM确实有一个decision_function_shape超参数,可以设置为"一对一"的'ovo'(尽管SVM默认设置为'ovo')。

因为我选择用欠采样做'ovo',所以我有兴趣在拟合每个'ovo'模型之前,将'ovo'参与类中的多数类降采样到少数类的大小。为了让自己更清楚,假设我有以下4个类的数据集:

from sklearn.datasets import make_classification
from collections import Counter
X, y = make_classification(n_samples=1000,  n_classes=4, 
weights=[.1, .15, .2], n_informative=3, random_state=11)
Counter(y)
Counter({0: 103, 1: 151, 2: 200, 3: 546})

SVM 'ovo'决策函数中,将存在nC24C2 = 6模型。因此,在每个'ovo'模型中,大多数类欠采样应该是这样的:

Model 1 = Class 0 Vs Class 1 # maj:1=151; RUS to 103, -> 0:103, 1:103 
Model 2 = Class 0 Vs Class 2 # maj:2=200; RUS to 103  -> 0:103, 2:103
Model 3 = Class 0 Vs Class 3 # maj:3=546; RUS to 103, -> 0:103, 3:103
Model 4 = Class 1 Vs Class 2 # maj:2=200; RUS to 151  -> 1:151, 2:151
Model 5 = Class 1 Vs Class 3 # maj:3=546; RUS to 151  -> 1:151, 3:151
Model 6 = Class 2 Vs Class 3 # maj:3=546; RUS to 200  -> 2:200, 3:200

确切地说,每个参与类的样本数量(平衡)取决于哪个是少数派的样本数量。

我如何将此与sklearn的SVC()和imblearn的RUS()的策略集成?

我怀疑使用SVC的多类处理会很容易完成,因为这似乎是委托给libsvm

您可能会使用OneVsOneClassifier,其中estimator是包含采样器和SVC(现在只会看到二进制问题)的imblearn管道。

最新更新