raamana / kernelmethods

Foundational library for Kernel methods in pattern analysis and machine learning

Home Page:https://raamana.github.io/kernelmethods/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use kernelset to add test sets

klingsly opened this issue · comments

  • kernelmethods version:
  • Python version:
  • Operating System:

Description

I am using kernelset for multi-core learning. How should I add test set data to kernelset and apply the learned weight data
image

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

Thank you @klingsly for the reporting the issue. I will respond to you shortly, with a solution/code.

Thank you @klingsly for the reporting the issue. I will respond to you shortly, with a solution/code.

I am sorry to get back to you late.Your method is very useful to me. I hope you can solve my problem.Looking forward to your reply soon!

Hi @klingsly , sorry for the delayed reply, but here it is:

Applying the kernel functions to test datasets requires an additional step of computing inner products between the test and train sample feature matrices, as illustrated below:

# create same kernel matrices as before
lin = KernelMatrix(LinearKernel())
rbf = KernelMatrix(GaussianKernel(sigma=10))
poly = KernelMatrix(PolyKernel(degree=2))
lap = KernelMatrix(LaplacianKernel(gamma=2))

test_kSet = KernelSet()
for km in [lin, rbf, poly, lap]:
    # notice that this is an inner product between test AND train sample feature matrices
    # this is required in kernel methods to make predictions
    km.attach_to(X_test, name_one='test_X', 
                 sample_two=X_train, name_two='train_X')
    test_kSet.append(km)

# compute the weighted linear combination
fused_test_X = linear_combination(test_kSet, weight_vec)

# now make predictions
mkl.predict(fused_test_X)

hope that helps? let me know if you have more questions.

we hope to release a MultipleKernelLearning() class soon, and would appreciate others contributing to it if they have the necessary skills and time. (see #9 )

Thanks for your response. I have a problem with this solution about how to fit train datasets?

What do you mean? You already did train the MKL with:

mkl.fit(X=X_train, y=y_train)

Sorry, I misunderstood what you meant. It's OK now

Great. please feel free to open another issue if you run into any issues.