You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import os
import numpy as np
import xgboost as xgb
# load data in do training
CURRENT_DIR = os.path.dirname(__file__)
dtrain = xgb.DMatrix(
os.path.join(CURRENT_DIR, "../data/agaricus.txt.train?format=libsvm")
)
param = {"max_depth": 2, "eta": 1, "objective": "binary:logistic"}
num_round = 2
print("running cross validation, disable standard deviation display and save best")
# do cross validation, this will print result out as
# [iteration] metric_name:mean_value
res = xgb.cv(
param,
dtrain,
num_boost_round=10,
nfold=5,
metrics={"error"},
seed=0,
callbacks=[
xgb.callback.EvaluationMonitor(show_stdv=False),
xgb.callback.EarlyStopping(3, save_best=True),
],
)
print(res)
Finally I will got a
ValueError: could not convert string to float: '(0.001228171312096744, 0.0010411026299985337)'
~/.conda/envs/sklearn-env/lib/python3.12/site-packages/xgboost/training.py", line 271
will return a float but
self.cvfolds[0].bst.attr("best_score")
just give a str like
(0.001228171312096744, 0.0010411026299985337)
When I trying to skip this step I got another error:
File "~/.conda/envs/sklearn-env/lib/python3.12/site-packages/xgboost/callback.py", line 464, in after_training
model = model[: best_iteration + 1]
~~~~~^^^^^^^^^^^^^^^^^^^^^^
TypeError: '_PackedBooster' object is not subscriptable
Did I miss something? How can I fix it? Thanks in advance.
The text was updated successfully, but these errors were encountered:
Hello, recently I tried xgb.cv and got an error when assigning save_best=True in xgb.callback.EarlyStopping().
I just used the demo privided at https://xgboost.readthedocs.io/en/latest/python/examples/cross_validation.html
Here is the full code I used:
Finally I will got a
When I tracing back, I found the function
at
will return a float but
just give a str like
When I trying to skip this step I got another error:
Did I miss something? How can I fix it? Thanks in advance.
The text was updated successfully, but these errors were encountered: