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

Can you please write worked code example to convert to python ? E.g.on same random forest model to python #8

Closed IrinaFikh closed 2 years ago

IrinaFikh commented 2 years ago

... expr = skompile(estimator.predict, random_forest_pars) func_python_2 = expr.to('python') print(func_python_2)

Result: <_ast.Call object at 0x0000024E39D1BE20> =======================.. expr = skompile(estimator.predict, random_forest_pars, True/False)

Traceback (most recent call last): File "C:\Users\irina\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in runfile('C:/Users/irina/PycharmProjects/pythonProject/test_models.py', wdir='C:/Users/irina/PycharmProjects/pythonProject') File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.1\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_umd.py", line 198, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/irina/PycharmProjects/pythonProject/test_models.py", line 62, in expr = skompile(estimator.predict, random_forest_pars, False) File "C:\Users\irina\anaconda3\lib\site-packages\skompiler\api.py", line 76, in skompile

IrinaFikh commented 2 years ago

right literal is 'python/code'