Search code examples
scikit-learnxgboost

XGboost python - classifier class weight option?


Is there a way to set different class weights for xgboost classifier? For example in sklearn RandomForestClassifier this is done by the "class_weight" parameter.


Solution

  • when using the sklearn wrapper, there is a parameter for weight.

    example:

    import xgboost as xgb
    exgb_classifier = xgboost.XGBClassifier()
    exgb_classifier.fit(X, y, sample_weight=sample_weights_data)
    

    where the parameter shld be array like, length N, equal to the target length