Question: 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

  1. Training set (X_train)
  2. Validation set (X_valid)
  3. Training labels (y_train)
  4. XGBoost Parameter List (param)

Output Return the following:

  1. y_pred_valid: The raw output scores for the validation set

Note:

  1. Round all raw scores to three decimal places
  2. Remember to use verbose_eval = False while training.
  3. 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.
  4. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!