eloquentarduino / micromlgen

Generate C code for microcontrollers from Python's sklearn classifiers
MIT License
188 stars 35 forks source link

ZeroDivisionError: integer division or modulo by zero #10

Open KerenHalperin opened 3 years ago

KerenHalperin commented 3 years ago

Hi, I'm using XGBClassifier and getting this error: ~/anaconda3/envs/kando/lib/python3.8/site-packages/micromlgen/templates/xgboost/xgboost.jinja in block 'predict'() 4 float votes[{{ n_classes }}] = { 0.0f }; 5 ----> 6 {% for k, tree in f.enumerate(trees) %} 7 {% with i = 0, class_idx = k % n_classes %} 8 // tree #{{ k + 1 }}

ZeroDivisionError: integer division or modulo by zero Can you please explain why this is happening?

eloquentarduino commented 3 years ago

It looks like n_classes is 0. What dataset are you trying to classify?

KerenHalperin commented 3 years ago

It's a binary classification problem, y- is a series of 1/0, x- dataframe with 40 features. Do you have an example of using micromlgen with xgboost? perhaps that would help me. Using SVC for example, works for me.

eloquentarduino commented 3 years ago

Xgboost is the same as any other classifier from the micromlgen perspective. I remember having troubles with binary classification with xgboost, too. Can you please try a different dataset with more than 2 classes? I'm sure it will work.

If this is the case and you need a "fast" solution, ry to create a "dummy" class to your dataset.