[scikit-learn] Porting old MLPY KRR model to scikit-learn

Chapman, James E jchapman48 at gatech.edu
Thu Sep 19 21:20:39 EDT 2019


Hello,
Thank you for your comments. I had actually initially tried your first suggestion, but the predicted values just wouldn’t line up between the two models. As I dug into the source code of the two, I realized that they don’t appear to be the same. MLPY adds a bias term to both the training and prediction process, whereas, correct me if I’m wrong, scikit-learn does not. This results in two fundamentally different sets of codes:

MLPY (prediction):
np.dot(self._alpha, Kt_arr.T) + self._b

Scikit-learn(prediction):
                np.dot(K, self.dual_coef_)

Here, MLPY’s alphas correspond to scikit-learn’s dual_coef_, and the kernel values are just stored differently, so one has to be transposed. If I just try and add MLPY’s bias term to scikit-learn’s prediction (model.predict), the values don’t match those predicted by MLPY (they’re close but they are not off by a constant value). Am I missing something obvious, or is there really a fundamental difference here?

From: scikit-learn <scikit-learn-bounces+jchapman48=gatech.edu at python.org> on behalf of Michael Eickenberg <michael.eickenberg at gmail.com>
Reply-To: Scikit-learn mailing list <scikit-learn at python.org>
Date: Thursday, September 19, 2019 at 3:53 PM
To: Scikit-learn mailing list <scikit-learn at python.org>
Subject: Re: [scikit-learn] Porting old MLPY KRR model to scikit-learn

What exactly do you mean by "port"? Put already fitted models into a sklearn estimator object? You can do this as follows:

You should be able to create a `estimator = sklearn.kernel_ridge.KernelRidge(...)` object, call `fit` to some random data of the appropriate shape, and then set `estimator.dual_coef_` to the ones from your MLPY model (the sklearn version sets them here: https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/kernel_ridge.py#L165).

If this is not what you mean, then maybe you just want to refit them using the appropriate KernelRidge kernel?

Hope this helps!

Michael


On Thu, Sep 19, 2019 at 12:43 PM Chapman, James E <jchapman48 at gatech.edu<mailto:jchapman48 at gatech.edu>> wrote:
Hello,
I have some old KRR models from MLPY and I need to port those models over to a new code written with scikit-learn (transfer MLPY KRR data to a scikit-learn KernelRidge instance). Does anyone know if this is even possible, and if so, could you give me some suggestions as to how to accomplish it?

Thanks and regards,
James
_______________________________________________
scikit-learn mailing list
scikit-learn at python.org<mailto: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/20190920/c019ba19/attachment-0001.html>


More information about the scikit-learn mailing list