use sample weights fit model multiclass 1

use sample weights fit model multiclass

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)

Here is what the above code is Doing:
1. We’re using the class_weight.compute_class_weight() function to compute the weights for each class.
2. We’re passing the class_weight dictionary to the fit() function.

Similar Posts