将带有 rbf 内核的 sklearn SVC 移植到 java

Porting sklearn SVC with rbf kernel to java

我已经使用 sklearn 在 python 中训练了一个 rbf 核 SVM,现在我将它移植到 java 用于生产。

在阅读 SVC documentation 时,我遇到了决策函数:

这似乎表明我必须知道每个训练样本的权重才能评估 SVC,但是 SVC 仅通过 dual_coef_ 属性公开支持向量的权重。

有没有办法解决这个问题?

你不需要知道每个训练样本的权重。您只需要支持向量的权重。

原因是如果向量 x_i 不是支持向量,则 alpha_i=0(参见第 5 页 here),因此 y_i*alpha_i=0 也是如此。因此你永远不会在分类过程中使用这样的x_i(一旦你安装了支持向量机)。

其余参数可通过 svm 属性访问,如 documentation:

中所述

This parameters can be accessed through the members dual_coef_ which holds the product y_i*alpha_i, support_vectors_ which holds the support vectors, and intercept_ which holds the independent term rho.