micromlgen icon indicating copy to clipboard operation
micromlgen copied to clipboard

ZeroDivisionError: integer division or modulo by zero

Open KerenHalperin opened this issue 3 years ago • 3 comments

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?

KerenHalperin avatar Nov 25 '21 10:11 KerenHalperin

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

eloquentarduino avatar Nov 25 '21 12:11 eloquentarduino

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.

KerenHalperin avatar Nov 25 '21 12:11 KerenHalperin

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.

eloquentarduino avatar Nov 25 '21 18:11 eloquentarduino