如何在python的sklearn中减少OneClassSVM中的异常值数量?

2024-04-24 20:56:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用oneclasssvm如下。你知道吗

from sklearn.svm import OneClassSVM

clf = OneClassSVM(random_state=42)
clf.fit(X)
y_pred_train = clf.predict(X)

print(len(np.where(y_pred_train == -1)[0]))

然而,我得到了超过50%的数据作为异常值。我想知道是否有一种方法可以减少一类svm中异常值的数量。你知道吗

我试过contamination。然而,似乎oneclasssvm不支持污染。你知道吗

我还有别的方法可以用吗?你知道吗

如果需要,我很乐意提供更多细节。你知道吗


Tags: 方法fromimporttrainrandomsklearnpredictfit
2条回答

我很想了解您使用的样本点的方差、维度和数量,但我的第一个建议是:

clf = OneClassSVM(random_state=42, gamma='scale')

Docs

Current default is ‘auto’ which uses 1 / n_features, if gamma='scale' is passed then it uses 1 / (n_features * X.var()) as value of gamma. The current default of gamma, ‘auto’, will change to ‘scale’ in version 0.22. ‘auto_deprecated’, a deprecated version of ‘auto’ is used as a default indicating that no explicit value of gamma was passed.

通过控制OneClassSVM的nu参数,可以控制训练数据中有多少数据点被标记为异常值。你知道吗

在API文档中,nu是,An upper bound on the fraction of training errors and a lower bound of the fraction of support vectors. Should be in the interval (0, 1]. By default 0.5 will be taken.

我建议您使用一个带标签的验证集,然后调整SVM超参数,比如nukernel等,以便在标记的验证集上获得最佳性能。你知道吗

相关问题 更多 >