composite kernel
Closed this issue · 4 comments
First of all, thank you for such useful tool!
I wonder that if I have multiple training and testing feature sets, how can I get the composite kernel of all sets to be used in model training and prediction?
Thank you in advance for your reply :)
Hi there,
so, you're in a multiview/information fusion setting, right?
In this case, there is not a specific tool, you just need to compute the kernel for each view (i.e. each feature set).
For instance, let's assume we're working with a sentence classification task, and multiple features consist of grammar rules, embedding, and pos. We can do something like this
X1 = [grammar_features(sent) for sent in sentences]
X2 = [contextual_word_embedding(sent) for sent in sentences]
X3 = [part_of_speech(sent) for sent in sentences]
Be sure that X1[i] corresponds to the same sentence of X2[i] and X3[i]. Then, we can just create a kernel for each view
from sklearn.metrics.pairwise import linear_kernel as lin_k
KL = [lin_k(X1), lin_k(X2), lin_k(X3)]
and combine them with MKL
from MKLpy.algorithms import EasyMKL
clf = EasyMKL().fit(KL, Y)
Does this example answer your question?
Hi, thank you for your reply. I was wrong passing only one kernel into the function, thus it gave an error. When I ran with 2+ kernels, it was totally fine.
Copy.
Of course, MKL algorithms need a list of kernels instead of a single one.
However, thanks for your feedback, we'll improve the error messages to simplify the usage!