[scikit-learn] Malformed input for SVC(kernel='precomputed').predict()
Sam Barnett
sambarnett95 at gmail.com
Thu Aug 17 13:21:24 EDT 2017
Hi Andy,
Please find attached a Jupyter notebook showing exactly where the problem
appears.
Best,
Sam
On Thu, Aug 17, 2017 at 4:03 PM, Andreas Mueller <t3kcit at gmail.com> wrote:
> Hi Sam.
>
> Can you say which test fails exactly and where (i.e. give traceback)?
> The estimator checks are currently quite strict with respect to raising
> helpful error messages.
> That doesn't mean your estimator is broken (necessarily).
> With a precomputed gram matrix, I expect the shape of X in predict to be
> (n_samples_test, n_samples_train), right?
> Does you estimator have a _pairwise attribute? (It should to work with
> cross-validation, I'm not sure if it's
> used in the estimator checks right now, but it should).
>
> Your feedback will help making check_estimator be more robust. I don't
> think it's tested with anything that requires
> "precomputed" kernels.
>
> Thanks
>
> Andy
>
>
> On 08/17/2017 05:22 AM, Sam Barnett wrote:
>
> 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:
>
>
> def predict(self, X):
> """Run the predict method of the previously-instantiated SVM
> classifier, returning the predicted classes for test set X."""
>
> # Check is fit had been called
> check_is_fitted(self, ['X_', 'y_'])
>
> # Input validation
> X = check_array(X)
>
> cut_off = self.cut_ord_pair[0]
> order = self.cut_ord_pair[1]
>
> X_gram = seq_kernel_free(X, self.X_, \
> pri_kernel=kernselect(self.kernel, self.coef0, self.gamma,
> self.degree, self.scale), \
> cut_off=cut_off, order=order)
>
> X_gram = np.nan_to_num(X_gram)
>
> return self.ord_svc_.predict(X_gram)
>
> 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.
>
> How do I resolve both issues simultaneously?
>
>
>
> _______________________________________________
> scikit-learn mailing listscikit-learn at python.orghttps://mail.python.org/mailman/listinfo/scikit-learn
>
>
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20170817/ac538adf/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kernelsqizer.py
Type: text/x-python-script
Size: 5142 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20170817/ac538adf/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SeqSVC Check Estimator Test.ipynb
Type: application/octet-stream
Size: 9321 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20170817/ac538adf/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seqsvc_v2.py
Type: text/x-python-script
Size: 10890 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20170817/ac538adf/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timeseriestools.py
Type: text/x-python-script
Size: 1419 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20170817/ac538adf/attachment-0005.bin>
More information about the scikit-learn
mailing list