-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
Description
Course
machine-learning-zoomcamp
Question
When running parse_xg_output(output), I get the following error:
ValueError Traceback (most recent call last)
Cell In[67], line 1
----> 1 df_score = parse_xg_output(output)
Cell In[66], line 5, in parse_xg_output(output)
2 results = []
4 for line in output.stdout.strip().split('\n'):
----> 5 it_line, train_line, val_line = line.split('\t')
7 it = int(it_line.strip('[]'))
8 train = float(train_line.split(':')[1])
ValueError: not enough values to unpack (expected 3, got 1)Answer
Check the following outputs:
print(repr(output.stdout))and
print(repr(output.stderr))If they are empty, this means XGBoost does not print training logs to stdout.
One solution is to use the training results returned by the Python API:
evals_result = {}
model = xgb.train(
params=xgb_params,
dtrain=dtrain,
num_boost_round=200,
evals=[(dtrain, 'train'), (dval, 'val')],
evals_result=evals_result,
verbose_eval=True
)
# Convert results to a DataFrame directly
df_results = pd.DataFrame({
'num_iter': range(len(evals_result['train']['auc'])),
'train_auc': evals_result['train']['auc'],
'val_auc': evals_result['val']['auc']
})
df_results.head()This will replace relevant code in parse_xg_output(). Also, the function now does not take any parameters.
Checklist
- I have searched existing FAQs and this question is not already answered
- The answer provides accurate, helpful information
- I have included any relevant code examples or links