Why doesn't class_weight.compute_weight() work?

Viewed 1705

Hello I am using the class_wight.compute_class_weight() function from the sklearn utils module.

I have an ImageDataGenerator().flow_from_directory() variable that is train_gen.

here is the code:

from sklearn.utils import class_weight  import numpy as np

class_weights = class_weight.compute_class_weight(
           'balanced',
            np.unique(train_gen.classes), 
            train_gen.classes)

# train_class_weights = dict(enumerate(class_weights))
# model.fit_generator(..., class_weight=train_class_weights)

and i obtain this error:

TypeError                                 Traceback (most recent call last)
<ipython-input-50-d468c4be76b8> in <module>()
      5            'balanced',
      6             np.unique(train_gen.classes),
----> 7             train_gen.classes)
      8 
      9 # train_class_weights = dict(enumerate(class_weights))

TypeError: compute_class_weight() takes 1 positional argument but 3 were given

Does anybody know what the problem could be? thank you

0 Answers
Related