1
votes

I want to implement SVM RBF kernel for my non-linearly separable data. I have defined my kernel as:

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

It is showing error:

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

How to resolve it?

1
can you print the shape of va and vb ? - Gambit1614
va is 100x2 and vb is 100x1 - kashf34Kashf

1 Answers

1
votes

Your shapes for va and vb are mismatching. They need to be of same shape. The syntax for rbf kernel should be of the following form:

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

va and vb are not features and labels.

You can check this link on Github for similar implementation. You can see that he is passing all pairs of samples to the rbf kernel and not the features and labels of a sample. Go to line no. 95.