1
$\begingroup$

I am trying to use XGBoost in python for logistic regression. I am calling it as follows

import numpy as np
from xgboost import XGBClassifier

x_train = np.array([[1], [2], [3], [4]])
y_train = np.array([0, .25, .75, 1])

params = {
    "objective": "reg:logistic"
}

model = XGBClassifier(**params)
model.fit(x_train, y_train)
print(model.objective)

This outputs an objective of "multi:softprob" instead of "reg:logistic." Therefore, it isn't doing a logistic regression. How can I make sure that XGBoost doesn't switch the objective?

$\endgroup$

2 Answers 2

1
$\begingroup$
import numpy as np
from xgboost import XGBRegressor

x_train = np.array([[1], [2], [3], [4]])
y_train = np.array([[0], [0.25], [0.75], [1]])


model = XGBRegressor()
model.fit(x_train, y_train)
print(model.objective)


$\endgroup$
1
$\begingroup$

The solution to the above problem was to use XGBRegressor instead of XGBClassifier. Just swapping it in seems to have worked.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.