So... I have been trying to make a radial basis kernel for hours but I am not sure of what my final matrix should look like. I have 30 features and 200000 data points. Should my matrix K be 200000*200000 or 30*30 ?
My code so far produces 30*30:
def build_kernel(x, func, option):
x = x.T
K = np.zeros([x.shape[0], x.shape[0]])
for i in range(x.shape[0]):
xi = x[i,:]
for j in range (x.shape[0]):
xj = x[j,:]
K[i,j] = func(xi, xj, option)
return K
def radial_basis(xi, xj, gamma):
r = (np.exp(-gamma*(np.linalg.norm(xi-xj)**2)))
return r
My goal is to use the kernel trick in ridge regression, like it is explained here: http://www.ics.uci.edu/~welling/classnotes/papers_class/Kernel-Ridge.pdf
But I have no idea how to implement this manually (I have to do it manually for school !)
Somebody knows how to do such a thing ? :)
Thanks !