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

Issues using skompiler #1

Closed mario-tux closed 5 years ago

mario-tux commented 5 years ago

I'm trying to make your skompiler to work with the former examples:

I tested this code using different environments:

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
X, y = load_iris(True)
m = RandomForestClassifier(n_estimators=3, max_depth=3).fit(X, y)
from skompiler import skompile
expr = skompile(m.predict)
sql = expr.to('python/code')

I get the following error using Python 3.5 with skompiler 0.5.1:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    expr = skompile(m.predict)
  File "/home/mario/.virtualenvs/skompiler2/lib/python3.5/site-packages/skompiler/api.py", line 76, in skompile
    return _translate(model, inputs, method)
  File "/home/mario/.virtualenvs/skompiler2/lib/python3.5/site-packages/skompiler/api.py", line 86, in _translate
    from .toskast.sklearn import translate as from_sklearn
  File "/home/mario/.virtualenvs/skompiler2/lib/python3.5/site-packages/skompiler/toskast/sklearn/__init__.py", line 22, in <module>
    from skompiler.dsl import ident, vector
  File "/home/mario/.virtualenvs/skompiler2/lib/python3.5/site-packages/skompiler/dsl.py", line 6, in <module>
    from . import ast
  File "/home/mario/.virtualenvs/skompiler2/lib/python3.5/site-packages/skompiler/ast.py", line 73, in <module>
    class ASTNode(object, metaclass=ASTNodeCreator, fields=None):
TypeError: type.__init__() takes no keyword arguments

I get a different error using Python 3.7 on a different machine:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    expr = skompile(m.predict)
  File "/home/mario/.virtualenvs/skompiler/lib/python3.7/site-packages/skompiler/api.py", line 76, in skompile
    return _translate(model, inputs, method)
  File "/home/mario/.virtualenvs/skompiler/lib/python3.7/site-packages/skompiler/api.py", line 86, in _translate
    from .toskast.sklearn import translate as from_sklearn
  File "/home/mario/.virtualenvs/skompiler/lib/python3.7/site-packages/skompiler/toskast/sklearn/__init__.py", line 87, in <module>
    @register(SVC, ['decision_function', 'predict'])
  File "/home/mario/.virtualenvs/skompiler/lib/python3.7/site-packages/skompiler/toskast/sklearn/__init__.py", line 64, in decorator
    def new_fn(model, inputs='x', method='predict'):
  File "/home/mario/.virtualenvs/skompiler/lib/python3.7/site-packages/singledispatch.py", line 202, in <lambda>
    return lambda f: register(cls, f)
  File "/home/mario/.virtualenvs/skompiler/lib/python3.7/site-packages/singledispatch.py", line 205, in register
    ns.cache_token = get_cache_token()
  File "/home/mario/.virtualenvs/skompiler/lib/python3.7/site-packages/singledispatch_helpers.py", line 159, in get_cache_token
    return ABCMeta._abc_invalidation_counter
AttributeError: type object 'ABCMeta' has no attribute '_abc_invalidation_counter'
konstantint commented 5 years ago

Most often libraries developed on Linux would have to be fixed-up to work on Windows, and not so much vice-versa. Here we have a rare chance to observe the opposite case - for some reason the singledispatch "back-filler" library works fine on Windows in 3.7, but is broken on Linux. The problem is trivial to fix, though.

I'll push the fixed version 0.5.2 to PyPI in a minute.