Add check for base_score in _get_attributes function #626
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the _get_attributes function in xgboost/_parse.py, I've added a check for the base_score attribute. This change is necessary because base_score can sometimes be stored as a string, which can cause issues in subsequent computations that expect it to be a float.
The updated code now checks if base_score is not in kwargs and, if not, sets it to 0.5. If base_score is in kwargs and is a string, it converts it to a float.
Here's the updated code:
if 'base_score' not in kwargs: kwargs['base_score'] = 0.5 elif isinstance(kwargs['base_score'], str): kwargs['base_score'] = float(kwargs['base_score']) return kwargs
This change ensures that base_score is always a float, which should prevent potential type-related errors in the future.