<div dir="ltr">Hi Andy,<div><br></div><div>Please find attached a Jupyter notebook showing exactly where the problem appears.<br><br>Best,</div><div>Sam</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 4:03 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>
<br>
Can you say which test fails exactly and where (i.e. give
traceback)?<br>
The estimator checks are currently quite strict with respect to
raising helpful error messages.<br>
That doesn't mean your estimator is broken (necessarily).<br>
With a precomputed gram matrix, I expect the shape of X in predict
to be (n_samples_test, n_samples_train), right?<br>
Does you estimator have a _pairwise attribute? (It should to work
with cross-validation, I'm not sure if it's<br>
used in the estimator checks right now, but it should).<br>
<br>
Your feedback will help making check_estimator be more robust. I
don't think it's tested with anything that requires<br>
"precomputed" kernels.<br>
<br>
Thanks<br>
<br>
Andy<div><div class="h5"><br>
<br>
<div class="m_-5508942987678868181moz-cite-prefix">On 08/17/2017 05:22 AM, Sam Barnett
wrote:<br>
</div>
</div></div><blockquote type="cite"><div><div class="h5">
<div dir="ltr">I am rolling classifier based on SVC which computes
a custom Gram matrix and runs this through the SVC classifier
with kernel = 'precomputed'. While this works fine with the fit
method, I face a dilemma with the predict method, shown here:
<div><br>
</div>
<div><br>
<div>
<div class="m_-5508942987678868181hljs m_-5508942987678868181python" 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_-5508942987678868181hljs-function"><span class="m_-5508942987678868181hljs-keyword" style="font-weight:bold">def</span>
<span class="m_-5508942987678868181hljs-title" style="color:rgb(136,0,0);font-weight:bold">predict</span><span class="m_-5508942987678868181hljs-params">(self, X)</span>:</span></div>
<div> <span class="m_-5508942987678868181hljs-string" style="color:rgb(136,0,0)">"""Run the predict method
of the previously-instantiated SVM</span></div>
<div><span class="m_-5508942987678868181hljs-string" style="color:rgb(136,0,0)">
classifier, returning the predicted classes for
test set X."""</span></div>
<div><br>
</div>
<div> <span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)"># Check is fit had been
called</span></div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)">
check_is_fitted(self, ['X_', 'y_'])</span></div>
<div><br>
</div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)"> # Input
validation</span></div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)"> X =
check_array(X)</span></div>
<div><br>
</div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)"> cut_off =
self.cut_ord_pair[0]</span></div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)"> order =
self.cut_ord_pair[1]</span></div>
<div><br>
</div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)"> X_gram =
seq_kernel_free(X, self.X_, \</span></div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)">
pri_kernel=kernselect(self.<wbr>kernel, self.coef0,
self.gamma, self.degree, self.scale), \</span></div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)">
cut_off=cut_off, order=order)</span></div>
<div><br>
</div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)"> X_gram =
np.nan_to_num(X_gram)</span></div>
<div><br>
</div>
<div><span class="m_-5508942987678868181hljs-comment" style="color:rgb(136,136,136)"> return
self.ord_svc_.predict(X_gram)</span></div>
</div>
</div>
<br>
</div>
<div>This will run on any dataset just fine. However, it fails
the check_estimator test. Specifically, when trying to raise
an error for malformed input on predict (in
check_classifiers_train), it says that a ValueError is not
raised. Yet if I change the order of X and self.X_ in
seq_kernel_free (which computes the [n_samples_train,
n_samples_test] Gram matrix), it passes the check_estimator
test yet fails to run the predict method.</div>
<div><br>
</div>
<div>How do I resolve both issues simultaneously?<br>
<br>
</div>
</div>
<br>
<fieldset class="m_-5508942987678868181mimeAttachmentHeader"></fieldset>
<br>
</div></div><pre>______________________________<wbr>_________________
scikit-learn mailing list
<a class="m_-5508942987678868181moz-txt-link-abbreviated" href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a>
<a class="m_-5508942987678868181moz-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>