As my dataset is unbalanced(class 1: 5%, class 0: 95%) I have used class_weight="balanced" parameter to train a random forest classification model. In this way I penalize the misclassification of a rare positive cases.
rf = RandomForestClassifier(max_depth=m, n_estimators=n_estimator,class_weight = "balanced") rf.fit(X_train, y_train)
The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y))
In my case the classes frequencies are:
fc = len(y_train)/(len(np.unique(y_train))*np.bincount(y_train))
array([ 0.52631579, 10. ])
I apply my model over a test dataset using predict proba function:
y_predicted_proba = rf.predict_proba(X_test)
The second column presents the probabilities of being 1 to the input samples. However I understand this probability must be corrected to be real.
If I divide them by class_weight values these new probabilities don't sum one...
How can this correction be achieved?