SVM 自定义 RBF 内核 IndexError

SVM custom RBF kernel IndexError

我想为我的非线性可分数据实现 SVM RBF 内核。我将我的内核定义为:

def rbf(va, vb):
    gamma = 0.7
    return exp(-gamma * linalg.norm(va - vb) ** 2)
clf = svm.SVC(kernel=rbf)
clf.fit(va, vb)

显示错误:

if X.shape[0] != X.shape[1]: IndexError: tuple index out of range

如何解决?

vavb 的形状不匹配。它们需要具有相同的形状。 rbf 内核的语法应为以下形式:

def rbf(va,vb) , where va are the feature of sample,say X and vb are the features of sample say X`.

va 和 vb 不是特征和标签。

您可以检查 this link on Github 以了解类似的实现。你可以看到他将所有样本对传递给 rbf 内核,而不是样本的特征和标签。转到第 1 行95.