I am using a simple XGBoost model to classify 2 classes (0 and 1) in a binary context. In case of the original data, the 0 is the majority class and 1 the minority class. The thing which is happening is that in case of classification, most 0s are being classified correctly, with many going into 1s, but most 1s are being misclassified into 0s.
I am fairly new to this, and having looked at various documentations and questions on SE, am really confused as to how I can specify my XGBoost model to favour class 1 (to be precise, if most 0s are misclassified into 1s, that is not a problem, but I want that most 1s are correctly classified as 1s (to increase the true positives, if there are false positives that is something which isn't much of a problem). The segment of code I am presently using to train and test the XGBoost are as follows (afterwards I use the confusion matrix in which the true positives (1s) are highly misclassified into 0s).
from xgboost import XGBClassifier # fit model on training data model = XGBClassifier() model.fit(X_train, labels) # where labels are either 1s or 0s # make predictions for test data y_pred = model.predict(X_test) y_pred = y_pred > 0.70 # account for > 0.70 probability y_pred = y_pred.astype(int) print(y_pred)
I just want to know if there is a simple way to specify to the XGBoost model any parameter in my code, so that the true positive rate can be increased? I can compromise of false positives being high, but I want the number of 1s to be correctly classified as 1s, instead of most of them going into 0s. Any help in this regard is appreciated.
I have now tried to use
scale_pos_weight in the XGBoost, with its value set to
0.70 (a random figure), but it is still landing most samples to 0, instead of 1.