Porting old MLPY KRR model to scikit-learn
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
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_ridg... ). 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@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@python.org https://mail.python.org/mailman/listinfo/scikit-learn
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@python.org> on behalf of Michael Eickenberg <michael.eickenberg@gmail.com> Reply-To: Scikit-learn mailing list <scikit-learn@python.org> Date: Thursday, September 19, 2019 at 3:53 PM To: Scikit-learn mailing list <scikit-learn@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_ridg...). 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@gatech.edu<mailto:jchapman48@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@python.org<mailto:scikit-learn@python.org> https://mail.python.org/mailman/listinfo/scikit-learn
participants (2)
-
Chapman, James E -
Michael Eickenberg