<div dir="ltr">Hi Andy,<div><br></div><div>The purpose of the transformer is to take an ordinary kernel (in this case I have taken 'rbf' as a default) and return a 'sequentialised' kernel using a few extra parameters. Hence, the transformer takes an ordinary data-target pair X, y as its input, and the fit_transform(X, y) method will output the Gram matrix for X that is associated with this sequentialised kernel. In the pipeline, this Gram matrix is passed into an SVC classifier with the kernel parameter set to 'precomputed'.</div><div><br></div><div>Therefore, I do not think your hacky solution would be possible. However, I am still unsure how to implement your first solution: won't the Gram matrix from the transformer contain all the necessary kernel values? Could you elaborate further?</div><div><br></div><div><br></div><div>Best,<br>Sam</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 2, 2017 at 5:05 PM, Andreas Mueller <span dir="ltr"><<a href="mailto:t3kcit@gmail.com" target="_blank">t3kcit@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
Hi Sam.<br>
GridSearchCV will do cross-validation, which requires to "transform"
the test data.<br>
The shape of the test-data will be different from the shape of the
training data.<br>
You need to have the ability to compute the kernel between the
training data and new test data.<br>
<br>
A more hacky solution would be to compute the full kernel matrix in
advance and pass that to GridSearchCV.<br>
<br>
You probably don't need it here, but you should also checkout what
the _pairwise attribute does in cross-validation,<br>
because that it likely to come up when playing with kernels.<br>
<br>
Hth,<br>
Andy<div><div class="h5"><br>
<br>
<div class="m_4888106697904469459moz-cite-prefix">On 08/02/2017 08:38 AM, Sam Barnett
wrote:<br>
</div>
</div></div><blockquote type="cite"><div><div class="h5">
<div dir="ltr">Dear all,
<div><br>
</div>
<div>
<div>I have created a 2-step pipeline with a custom
transformer followed by a simple SVC classifier, and I wish
to run a grid-search over it. I am able to successfully
create the transformer and the pipeline, and each of these
elements work fine. However, when I try to use the fit()
method on my GridSearchCV object, I get the following error:</div>
</div>
<div><br>
</div>
<div>
<div>
<div class="m_4888106697904469459hljs m_4888106697904469459cs" style="display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248);font-family:monospace">
<div> <span class="m_4888106697904469459hljs-number" style="color:rgb(136,0,0)">57</span> <span class="m_4888106697904469459hljs-meta" style="color:rgb(31,113,153)">#
during fit.</span></div>
<div><span class="m_4888106697904469459hljs-meta" style="color:rgb(31,113,153)">
58 <span class="m_4888106697904469459hljs-meta-keyword" style="font-weight:bold">if</span> X.shape !=
self.input_shape_:</span></div>
<div><span class="m_4888106697904469459hljs-meta" style="color:rgb(31,113,153)">--->
59 raise ValueError('Shape of input is
different from what was seen '</span></div>
<div><span class="m_4888106697904469459hljs-meta" style="color:rgb(31,113,153)">
60 'in `fit`')</span></div>
<div><span class="m_4888106697904469459hljs-meta" style="color:rgb(31,113,153)">
61 </span></div>
<div><br>
</div>
<div><span class="m_4888106697904469459hljs-meta" style="color:rgb(31,113,153)">ValueError:
Shape of input is different from what was seen in
`fit`</span></div>
</div>
</div>
<br>
</div>
<div>For a full breakdown of the problem, I have written a
Jupyter notebook showing exactly how the error occurs (this
also contains all .py files necessary to run the notebook).
Can anybody see how to work through this?</div>
<div><br>
</div>
<div>Many thanks,</div>
<div>Sam Barnett</div>
<div><br>
</div>
</div>
<br>
<fieldset class="m_4888106697904469459mimeAttachmentHeader"></fieldset>
<br>
</div></div><pre>______________________________<wbr>_________________
scikit-learn mailing list
<a class="m_4888106697904469459moz-txt-link-abbreviated" href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a>
<a class="m_4888106697904469459moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/scikit-learn" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scikit-learn</a>
</pre>
</blockquote>
<br>
</div>
<br>______________________________<wbr>_________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scikit-learn</a><br>
<br></blockquote></div><br></div>