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$
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)


| improve this answer | |
$\endgroup$
1
$\begingroup$

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

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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