dmlc / xgboost

Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library, for Python, R, Java, Scala, C++ and more. Runs on single machine, Hadoop, Spark, Dask, Flink and DataFlow
https://xgboost.readthedocs.io/en/stable/
Apache License 2.0
26.15k stars 8.71k forks source link

XGBoost V.2.0.2 does not recognize 'reg:quantileerror' as a valid objective function #9912

Closed georgi72 closed 1 month ago

georgi72 commented 9 months ago

import xgboost as xgb

xgb.version Out[203]: '2.0.2'

booster = xgb.train( {

Use the quantile objective function.

    "objective": "reg:quantileerror",
    "tree_method": "hist",
    "quantile_alpha": alpha,
    # Let's try not to overfit.
    "learning_rate": 0.04,
    "max_depth": 5,
},
Xy,
num_boost_round=32,
early_stopping_rounds=2,
# The evaluation result is a weighted average across multiple quantiles.
evals=[(Xy, "Train"), (Xy_test, "Test")],
evals_result=evals_result,

)

XGBoostError: [11:04:05] C:\buildkite-agent\builds\buildkite-windows-cpu-autoscaling-group-i-08de971ced8a8cdc6-1\xgboost\xgboost-ci-windows\src\objective\objective.cc:26: Unknown objective function: reg:quantileerror

According to the documentation, quantile error is implemented in v.2.0.2. What am I missing? Thank you.

hcho3 commented 9 months ago

How did you install XGBoost? I could not reproduce the error when I installed XGBoost 2.0.3 using pip install xgboost.

georgi72 commented 9 months ago

I used "conda install -c conda-forge py-xgboost".

Now I upgraded to v.2.0.3 using "pip3 install xgboost==2.0.3" and get the same error.

hcho3 commented 9 months ago

Can you install XGBoost again? It appears that your XGBoost installation is somehow corrupted.

georgi72 commented 9 months ago

I uninstalled and reinstalled xgboost using "pip install xgboost". The version is 2.0.3. I get the same result. Not sure what is going on.

trivialfis commented 9 months ago

Could you please print out the XGB version before the training code?

import xgboost
print(xgboost.__version__)

...

booster = xgb.train(
{
# Use the quantile objective function.
"objective": "reg:quantileerror",
"tree_method": "hist",
"quantile_alpha": alpha,
# Let's try not to overfit.
"learning_rate": 0.04,
"max_depth": 5,
},
Xy,
num_boost_round=32,
early_stopping_rounds=2,
# The evaluation result is a weighted average across multiple quantiles.
evals=[(Xy, "Train"), (Xy_test, "Test")],
evals_result=evals_result,
)
georgi72 commented 9 months ago

import xgboost print(xgboost.version) 2.0.3

trivialfis commented 9 months ago

Could you please share the complete error message?

georgi72 commented 9 months ago

XGBoostError: [06:08:55] C:\buildkite-agent\builds\buildkite-windows-cpu-autoscaling-group-i-08de971ced8a8cdc6-1\xgboost\xgboost-ci-windows\src\objective\objective.cc:26: Unknown objective function: reg:quantileerror Objective candidate: survival:aft Objective candidate: binary:hinge Objective candidate: multi:softmax Objective candidate: multi:softprob Objective candidate: rank:pairwise Objective candidate: rank:ndcg Objective candidate: rank:map Objective candidate: survival:cox Objective candidate: reg:gamma Objective candidate: reg:tweedie Objective candidate: reg:squarederror Objective candidate: reg:squaredlogerror Objective candidate: reg:logistic Objective candidate: binary:logistic Objective candidate: binary:logitraw Objective candidate: reg:linear Objective candidate: reg:absoluteerror Objective candidate: reg:pseudohubererror Objective candidate: count:poisson

trivialfis commented 9 months ago

@hcho3 Did you try it on Windows? I don't understand why the objective isn't registered.

georgi72 commented 9 months ago

Yes, I am working in Windows. I don't understand either.

hcho3 commented 9 months ago

I just tried running demo/guide-python/quantile_regression.py on Windows and could not reproduce the error either. I installed XGBoost 2.0.3 using pip install xgboost.

joranE commented 6 months ago

I don't know if they are related, but using the R package (v1.7.7.1 binary from CRAN) when I attempt to use reg:quantileerror I also get an error that it is an unrecognized objective:

library(xgboost)

y <- mtcars$mpg
X <- as.matrix(mtcars[,-1])

res <- xgboost(
  data = X,
  label = y,
  nrounds = 100,
  params = list(objective = "reg:quantileerror",alpha = c(0.1,0.5,0.9))
)

yields this error:

Error in xgb.iter.update(bst$handle, dtrain, iteration - 1, obj) : 
  [15:19:47] src/objective/objective.cc:26: Unknown objective function: `reg:quantileerror`
Objective candidate: reg:squarederror
Objective candidate: reg:squaredlogerror
Objective candidate: reg:logistic
Objective candidate: binary:logistic
Objective candidate: binary:logitraw
Objective candidate: reg:linear
Objective candidate: reg:pseudohubererror
Objective candidate: count:poisson
Objective candidate: survival:cox
Objective candidate: reg:gamma
Objective candidate: reg:tweedie
Objective candidate: reg:absoluteerror
Objective candidate: multi:softmax
Objective candidate: multi:softprob
Objective candidate: rank:pairwise
Objective candidate: rank:ndcg
Objective candidate: rank:map
Objective candidate: binary:hinge
Objective candidate: survival:aft

Stack trace:
  [bt] (0) 1   xgboost.so                          0x0000000129009e3c dmlc::LogMessageFatal::~LogMessageFatal() + 124
  [bt] (1) 2   xgboost.so                          0x0000000129030970 xgboost::ObjFunction::Create(st

The stack trace is cut off as I've shown it, there isn't anything more printed to the console.

Specifying another optional objective function, e.g. reg:absoluteerror runs fine with no errors.

trivialfis commented 6 months ago

R is on 1.7.x, which doesn't include quantile function yet. We are working on the R interface, see https://github.com/dmlc/xgboost/issues/9810 .

taoari commented 5 months ago

Same error here for version 2.0.3. The interesting thing is that: if I run pip install xgboost==2.0.3from a notebook, I get this error. But if I run from the system and install the library, this error disappears.

trivialfis commented 1 month ago

Closing due to unable to reproduce. Feel free to reopen if you can share the environment for debugging.