[scikit-learn] How to dump a model to txt file?

federico vaggi vaggi.federico at gmail.com
Thu Apr 13 17:27:19 EDT 2017


If you want to use the model from C++ code, the easiest way is to probably
use Boost/Python (
http://www.boost.org/doc/libs/1_62_0/libs/python/doc/html/index.html).
Alternatively, use another gradient boosting library that has a C++ API
(like XGBoost).

Keep in mind, if you want to call Python code from C++ you will have to
bundle a Python interpreter as well as all the dependencies.

On Thu, 13 Apr 2017 at 14:23 Sebastian Raschka <se.raschka at gmail.com> wrote:

> Hi,
>
> not sure how this could generally work. However, you could at least dump
> the model parameters for e.g., linear models and compute the prediction via
>
> w_1 * x1 + w_2 * x_2 + … + w_n * x_n + bias
>
> over the n features.
>
> To write various model attributes to text files, you could use json, e.g.,
> see https://cmry.github.io/notes/serialize
> However, I don’t think that this approach will solve the problem of
> loading the model into C++.
>
> Best,
> Sebastian
>
> > On Apr 13, 2017, at 4:58 PM, 老陈 <26743610 at qq.com> wrote:
> >
> > Hi,
> >
> > I am working on GradientBoostingRegressor these days and I am wondering
> if there is a way to dump the model into txt file, or any other format that
> can be processed by c++
> >
> > My production system is in c++, so I want use the python-trained tree
> model in c++ for production.
> >
> > Has anyone ever done this before?
> >
> > thanks
> > _______________________________________________
> > scikit-learn mailing list
> > scikit-learn at python.org
> > https://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/20170413/320730d2/attachment.html>


More information about the scikit-learn mailing list