You are on page 1of 1

You could simply implement the class_weight from sklearn:

from sklearn.utils import class_weight


class_weights = class_weight.compute_class_weight('balanced',
np.unique(y_train),
y_train)
model.fit(X_train, y_train, class_weight=class_weights)

Attention: I edited this post and changed the variable name from class_weight to
class_weights in order to not to overwrite the imported module. Adjust accordingly
when copying code from the comments