Validition score while training lower than on final model with xgboost












0












$begingroup$


I have 3 three classes, but my metric is auc, so I have customer eval metric:



# while training eval metric
def custom_eval_metric_class(preds, dtrain):
labels = dtrain.get_label()
labels_processed = [1 if u == 2 else 0 for u in labels]
pred_proba = preds[:, 2]
return 'auc', roc_auc_score(labels_processed, pred_proba)
#final metric function
def roc_auc_score_3class(y_test, y_score):
#print (y_test, 'n', y_score)
metric_auc = roc_auc_score( [1 if v == 2 else 0 for v in y_test],
y_score)
return metric_auc


My target class is 2.



While training model performance on validation reaches .80+ but then on final validation doesnt hit such value. What might be wrong here?



def train_model(X, y, params=None, folds=5, model_type='lgb'):
for fold_n, (train_index, valid_index) in enumerate(folds.split(X, y)):
gc.collect()
print('Fold', fold_n + 1, 'started at', time.ctime())
X_train, X_valid = X.iloc[train_index], X.iloc[valid_index]
y_train, y_valid = y.iloc[train_index], y.iloc[valid_index]


if model_type == 'xgb':
model = xgb.XGBClassifier(params=params, n_estimators = 5000)
model = model.fit(X_train, y_train, eval_set = [(X_valid, y_valid)], early_stopping_rounds=200,
eval_metric = custom_eval_metric_class, verbose = 100)
y_pred_valid = model.predict_proba(X_valid, model.best_ntree_limit)[:, 2]

scores.append(roc_auc_score_3class(y_valid, y_pred_valid))
print('Fold valid roc_auc:', roc_auc_score_3class(y_valid, y_pred_valid))

Will train until validation_0-auc hasn't improved in 200 rounds.
[100] validation_0-merror:0.211905 validation_0-auc:0.790956
[200] validation_0-merror:0.214286 validation_0-auc:0.794158
[300] validation_0-merror:0.210714 validation_0-auc:0.792962
Stopping. Best iteration:
[196] validation_0-merror:0.214286 validation_0-auc:0.796363

Fold valid roc_auc: 0.731813592646








share









$endgroup$

















    0












    $begingroup$


    I have 3 three classes, but my metric is auc, so I have customer eval metric:



    # while training eval metric
    def custom_eval_metric_class(preds, dtrain):
    labels = dtrain.get_label()
    labels_processed = [1 if u == 2 else 0 for u in labels]
    pred_proba = preds[:, 2]
    return 'auc', roc_auc_score(labels_processed, pred_proba)
    #final metric function
    def roc_auc_score_3class(y_test, y_score):
    #print (y_test, 'n', y_score)
    metric_auc = roc_auc_score( [1 if v == 2 else 0 for v in y_test],
    y_score)
    return metric_auc


    My target class is 2.



    While training model performance on validation reaches .80+ but then on final validation doesnt hit such value. What might be wrong here?



    def train_model(X, y, params=None, folds=5, model_type='lgb'):
    for fold_n, (train_index, valid_index) in enumerate(folds.split(X, y)):
    gc.collect()
    print('Fold', fold_n + 1, 'started at', time.ctime())
    X_train, X_valid = X.iloc[train_index], X.iloc[valid_index]
    y_train, y_valid = y.iloc[train_index], y.iloc[valid_index]


    if model_type == 'xgb':
    model = xgb.XGBClassifier(params=params, n_estimators = 5000)
    model = model.fit(X_train, y_train, eval_set = [(X_valid, y_valid)], early_stopping_rounds=200,
    eval_metric = custom_eval_metric_class, verbose = 100)
    y_pred_valid = model.predict_proba(X_valid, model.best_ntree_limit)[:, 2]

    scores.append(roc_auc_score_3class(y_valid, y_pred_valid))
    print('Fold valid roc_auc:', roc_auc_score_3class(y_valid, y_pred_valid))

    Will train until validation_0-auc hasn't improved in 200 rounds.
    [100] validation_0-merror:0.211905 validation_0-auc:0.790956
    [200] validation_0-merror:0.214286 validation_0-auc:0.794158
    [300] validation_0-merror:0.210714 validation_0-auc:0.792962
    Stopping. Best iteration:
    [196] validation_0-merror:0.214286 validation_0-auc:0.796363

    Fold valid roc_auc: 0.731813592646








    share









    $endgroup$















      0












      0








      0





      $begingroup$


      I have 3 three classes, but my metric is auc, so I have customer eval metric:



      # while training eval metric
      def custom_eval_metric_class(preds, dtrain):
      labels = dtrain.get_label()
      labels_processed = [1 if u == 2 else 0 for u in labels]
      pred_proba = preds[:, 2]
      return 'auc', roc_auc_score(labels_processed, pred_proba)
      #final metric function
      def roc_auc_score_3class(y_test, y_score):
      #print (y_test, 'n', y_score)
      metric_auc = roc_auc_score( [1 if v == 2 else 0 for v in y_test],
      y_score)
      return metric_auc


      My target class is 2.



      While training model performance on validation reaches .80+ but then on final validation doesnt hit such value. What might be wrong here?



      def train_model(X, y, params=None, folds=5, model_type='lgb'):
      for fold_n, (train_index, valid_index) in enumerate(folds.split(X, y)):
      gc.collect()
      print('Fold', fold_n + 1, 'started at', time.ctime())
      X_train, X_valid = X.iloc[train_index], X.iloc[valid_index]
      y_train, y_valid = y.iloc[train_index], y.iloc[valid_index]


      if model_type == 'xgb':
      model = xgb.XGBClassifier(params=params, n_estimators = 5000)
      model = model.fit(X_train, y_train, eval_set = [(X_valid, y_valid)], early_stopping_rounds=200,
      eval_metric = custom_eval_metric_class, verbose = 100)
      y_pred_valid = model.predict_proba(X_valid, model.best_ntree_limit)[:, 2]

      scores.append(roc_auc_score_3class(y_valid, y_pred_valid))
      print('Fold valid roc_auc:', roc_auc_score_3class(y_valid, y_pred_valid))

      Will train until validation_0-auc hasn't improved in 200 rounds.
      [100] validation_0-merror:0.211905 validation_0-auc:0.790956
      [200] validation_0-merror:0.214286 validation_0-auc:0.794158
      [300] validation_0-merror:0.210714 validation_0-auc:0.792962
      Stopping. Best iteration:
      [196] validation_0-merror:0.214286 validation_0-auc:0.796363

      Fold valid roc_auc: 0.731813592646








      share









      $endgroup$




      I have 3 three classes, but my metric is auc, so I have customer eval metric:



      # while training eval metric
      def custom_eval_metric_class(preds, dtrain):
      labels = dtrain.get_label()
      labels_processed = [1 if u == 2 else 0 for u in labels]
      pred_proba = preds[:, 2]
      return 'auc', roc_auc_score(labels_processed, pred_proba)
      #final metric function
      def roc_auc_score_3class(y_test, y_score):
      #print (y_test, 'n', y_score)
      metric_auc = roc_auc_score( [1 if v == 2 else 0 for v in y_test],
      y_score)
      return metric_auc


      My target class is 2.



      While training model performance on validation reaches .80+ but then on final validation doesnt hit such value. What might be wrong here?



      def train_model(X, y, params=None, folds=5, model_type='lgb'):
      for fold_n, (train_index, valid_index) in enumerate(folds.split(X, y)):
      gc.collect()
      print('Fold', fold_n + 1, 'started at', time.ctime())
      X_train, X_valid = X.iloc[train_index], X.iloc[valid_index]
      y_train, y_valid = y.iloc[train_index], y.iloc[valid_index]


      if model_type == 'xgb':
      model = xgb.XGBClassifier(params=params, n_estimators = 5000)
      model = model.fit(X_train, y_train, eval_set = [(X_valid, y_valid)], early_stopping_rounds=200,
      eval_metric = custom_eval_metric_class, verbose = 100)
      y_pred_valid = model.predict_proba(X_valid, model.best_ntree_limit)[:, 2]

      scores.append(roc_auc_score_3class(y_valid, y_pred_valid))
      print('Fold valid roc_auc:', roc_auc_score_3class(y_valid, y_pred_valid))

      Will train until validation_0-auc hasn't improved in 200 rounds.
      [100] validation_0-merror:0.211905 validation_0-auc:0.790956
      [200] validation_0-merror:0.214286 validation_0-auc:0.794158
      [300] validation_0-merror:0.210714 validation_0-auc:0.792962
      Stopping. Best iteration:
      [196] validation_0-merror:0.214286 validation_0-auc:0.796363

      Fold valid roc_auc: 0.731813592646






      xgboost cross-validation





      share












      share










      share



      share










      asked 4 mins ago









      RocketqRocketq

      1235




      1235






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "557"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f45794%2fvalidition-score-while-training-lower-than-on-final-model-with-xgboost%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f45794%2fvalidition-score-while-training-lower-than-on-final-model-with-xgboost%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Ponta tanko

          Tantalo (mitologio)

          Erzsébet Schaár