-
-
Save Tob-iee/04b2e714f45f3f25cce08d11df3aa796 to your computer and use it in GitHub Desktop.
Class Weighting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import class weights function | |
from sklearn.utils.class_weight import compute_class_weight | |
# Calculate class weights | |
class_weights = compute_class_weight('balanced', np.unique(y_train), y_train) | |
# Create a dictionary to map class indices to their respective weights | |
class_weight_dict = dict(zip(np.unique(y_train), class_weights)) | |
# Define and train a classifier with class weights | |
classifier = RandomForestClassifier(class_weight=class_weight_dict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment