Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Generating scores using XGBoost The function get_margin_scores is used to predict the sector for each of the given samples. Input Training set (X_train) Validation set
Generating scores using XGBoost
The function get_margin_scores is used to predict the sector for each of the given samples.
Input
- Training set (X_train)
- Validation set (X_valid)
- Training labels (y_train)
- XGBoost Parameter List (param)
Output Return the following:
- y_pred_valid: The raw output scores for the validation set
Note:
- Round all raw scores to three decimal places
- Remember to use verbose_eval = False while training.
- Remember to provide the num_round parameter while training and do not change it. We have currently set it to 100 (Refer to previous cell). Not providing the parameter or changing it could produce different results.
- Documentation for XGBoost Python API is here
All but one of the lines of the function have been filled. You need only fill the one missing line that trains the model. Check the XGBoost documentation for instructions on using train() function for XGBoost
def get_margin_scores(X_train, X_valid, y_train, param):
dtrain = xgb.DMatrix(X_train, label=y_train)
evallist = [(dtrain, 'train')]
plst = param.items()
###
### YOUR CODE HERE
###
dvalid = xgb.DMatrix(X_valid)
y_pred_valid = bst.predict(dvalid, ntree_limit=bst.best_ntree_limit, output_margin=True)
y_pred_valid = np.around(y_pred_valid, decimals = 3)
return y_pred_valid
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started