konstantint / SKompiler

A tool for compiling trained SKLearn models into other representations (such as SQL, Sympy or Excel formulas)
MIT License
171 stars 10 forks source link

export to languages not working! #7

Closed Proheeler closed 3 years ago

Proheeler commented 4 years ago

Hi! I'm trying to export RandomForestRegressor to C/C++ (also tried for js). Unfortunately got this exception: unsupported operand type(s) for |=: 'Piecewise' and 'Piecewise'

Can you please help me?

konstantint commented 3 years ago

Translation to C++ or JS is performed via Sympy and the error you are seeing looks like an old Sympy feature.

I'm not sure I could help you much here. Sympy's programming language translation capabilities are somewhat flaky in general, and were added to SKompiler's mainly as a fun proof of concept without hopes that those would be 100% reliable. If you need the translation for serious production use, your best bet is to implement a custom SKAST-to-C++ translator manually (PRs welcome!).

konstantint commented 3 years ago

However, it may still be useful if you could construct a minimal example for reproducing the problem - perhaps the Sympy issue could be hacked around by redefining the way piecewise functions are represented.