我想为我的非线性可分离数据实现 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
如何解决?
最佳答案
您的 va
和 vb
形状不匹配。它们需要具有相同的形状。
rbf 内核的语法应采用以下形式:
def rbf(va,vb) , where
va
are the feature of sample,say X andvb
are the features of sample say X`.
va 和 vb 不是特征和标签。
您可以查看this link on Github用于类似的实现。您可以看到他将所有样本对传递给 rbf 内核,而不是样本的特征和标签。转到第 1 行。 95.
关于python - SVM 自定义 RBF 内核 IndexError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46426693/