title: 'Booster' object has no attribute 'score' - Accuracy
body: <p>While looking for the best parameters for xgboost I came across a problem.</p>
  
  <p>The whole went well and I manage to attach parameters to the model and check its accuracy, but my solution is very primitive and not quite good (
  "manually" attach parameters to the previously created model)</p>
  
  <p>I get the following error when I try to check the accuracy of the model :</p>
  
  <pre><code>AttributeError: 'Booster' object has no attribute 'score'
  </code></pre>
  
  <p>Accuracy:</p>
  
  <pre><code>accuracy = classifier.score(X_test, y_test)
  print(accuracy*100,'%')
  </code></pre>
  
  <p>I put all the code below (all because I don't know exactly where the error occur):</p>
  
  <pre><code># Fitting XGBoost to the Training set
  from xgboost import XGBClassifier
  classifier = XGBClassifier()
  
  # Predicting the Test set results
  y_pred = classifier.predict(X_test)
  
  # here the accuracy is checked without any problem
  accuracy = classifier.score(X_test, y_test)
  print(accuracy*100,'%')
  
  dtrain = xgb.DMatrix(X_train, label=y_train)
  dtest = xgb.DMatrix(X_test, label=y_test)
  
  params = {
      # Parameters that we are going to tune.
      'max_depth':6,
      'min_child_weight': 1,
      'eta':.3,
      'lambda': .1,
      'subsample': 1,
      'colsample_bytree': 1,
       # Other parameters
      'objective':'reg:squarederror',
  }
  
  params['eval_metric'] = "rmse"
  
  num_boost_round = 999
  
  model = xgb.train(
      params,
      dtrain,
      num_boost_round=num_boost_round,
      evals=[(dtest, "Test")],
      early_stopping_rounds=10
  )
  
  print("Best RMSE: {:.2f} with {} rounds".format(
                   model.best_score,
                   model.best_iteration+1))
  
  cv_results = xgb.cv ( 
      params, 
      dtrain, 
      num_boost_round = num_boost_round, 
      seed = 42, 
      nfold = 5, 
      metrics = {'rmse'}, 
      early_stopping_rounds = 10 
  ) 
  cv_results
  
  cv_results ['test-rmse-mean']. min () 
  
  gridsearch_params = [
      (max_depth, min_child_weight)
      for max_depth in range(9,12)
      for min_child_weight in range(5,8)
  ]
  
  min_rmse = float("Inf")
  best_params = None
  for max_depth, min_child_weight in gridsearch_params:
      print("CV with max_depth={}, min_child_weight={}".format(
                               max_depth,
                               min_child_weight))
      # Update our parameters
      params['max_depth'] = max_depth
      params['min_child_weight'] = min_child_weight
      # Run CV
      cv_results = xgb.cv(
          params,
          dtrain,
          num_boost_round=num_boost_round,
          seed=42,
          nfold=5,
          metrics={'rmse'},
          early_stopping_rounds=10
      )
      # Update best RMSE
      mean_rmse = cv_results['test-rmse-mean'].min()
      boost_rounds = cv_results['test-rmse-mean'].argmin()
      print("\RMSE {} for {} rounds".format(mean_rmse, boost_rounds))
      if mean_rmse &lt; min_rmse:
          min_rmse = mean_rmse
          best_params = (max_depth,min_child_weight)
  print("Best params: {}, {}, RMSE: {}".format(best_params[0], best_params[1], min_rmse))
  
  params['max_depth'] = 9
  params['min_child_weight'] = 7
  
  gridsearch_params = [
      (subsample, colsample)
      for subsample in [i/10. for i in range(7,11)]
      for colsample in [i/10. for i in range(7,11)]
  ]
  
  min_rmse = float("Inf")
  best_params = None
  # We start by the largest values and go down to the smallest
  for subsample, colsample in reversed(gridsearch_params):
      print("CV with subsample={}, colsample={}".format(
                               subsample,
                               colsample))
      # We update our parameters
      params['subsample'] = subsample
      params['colsample_bytree'] = colsample
      # Run CV
      cv_results = xgb.cv(
          params,
          dtrain,
          num_boost_round=num_boost_round,
          seed=42,
          nfold=5,
          metrics={'rmse'},
          early_stopping_rounds=10
      )
      # Update best score
      mean_rmse = cv_results['test-rmse-mean'].min()
      boost_rounds = cv_results['test-rmse-mean'].argmin()
      print("\tRMSE {} for {} rounds".format(mean_rmse, boost_rounds))
      if mean_rmse &lt; min_rmse:
          min_rmse = mean_rmse
          best_params = (subsample,colsample)
  print("Best params: {}, {}, RMSE: {}".format(best_params[0], best_params[1], min_rmse))
  
  params['subsample'] = 1.0
  params['colsample_bytree'] = 1.0
  
  %time
  # This can take some time…
  min_rmse = float("Inf")
  best_params = None
  for eta in [.3, .2, .1, .05, .01, .005]:
      print("CV with eta={}".format(eta))
      # We update our parameters
      params['eta'] = eta
      # Run and time CV
  
      %time cv_results = xgb.cv(\
              params,\
              dtrain,\
              num_boost_round=num_boost_round,\
              seed=42,\
              nfold=5,\
              metrics=['rmse'],\
              early_stopping_rounds=10\
            )
  
      # Update best score
      mean_rmse = cv_results['test-rmse-mean'].min()
      boost_rounds = cv_results['test-rmse-mean'].argmin()
      print("\tRMSE {} for {} rounds\n".format(mean_rmse, boost_rounds))
      if mean_rmse &lt; min_rmse:
          min_rmse = mean_rmse
          best_params = eta
  
  print("Best params: {}, RMSE: {}".format(best_params, min_rmse))
  
  params['eta'] = .2
  
  classifier = xgb.train(
      params,
      dtrain,
      num_boost_round=num_boost_round,
      evals=[(dtest, "Test")],
      early_stopping_rounds=10
  )
  
  num_boost_round = model.best_iteration + 1
  best_model = xgb.train(
      params,
      dtrain,
      num_boost_round=num_boost_round,
      evals=[(dtest, "Test")]
  )
  
  from sklearn.metrics import mean_absolute_error
  mean_absolute_error(best_model.predict(dtest), y_test)
  
  best_model.save_model("my_model.model")
  
  loaded_model = xgb.Booster()
  loaded_model.load_model("my_model.model")
  
  accuracy = classifier.score(X_test, y_test)
  print(accuracy*100,'%')
  </code></pre>
  
  <p>the second time I try to check accuracy, I get an error.</p>