Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XGBModel' object has no attribute 'evals_result_'

I am trying to use xgboost on a dataset. I have seen the same syntax in various blogs but I am getting an error while calling clf.evals_result() here is my code

from xgboost import XGBRegressor as xgb
from sklearn.metrics import mean_absolute_error as mae

evals_result ={}
eval_s = [(x, y),(xval,yval)]

clf = xgb(n_estimators=100,learning_rate=0.03,tree_method='gpu_hist',lamda=0.1,eval_metric='mae',eval_set=eval_s,early_stopping_rounds=0,evals_result=evals_result)

clf.fit(x,y) 

r = clf.evals_result()

here is error I am receiving

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-138-2d6867968043> in <module>
      1 
----> 2 r = clf.evals_result()
      3 
      4 p = clf.predict(xval)

/opt/conda/lib/python3.6/site-packages/xgboost/sklearn.py in evals_result(self)
    399          'validation_1': {'logloss': ['0.41965', '0.17686']}}
    400         """
--> 401         if self.evals_result_:
    402             evals_result = self.evals_result_
    403         else:

AttributeError: 'XGBRegressor' object has no attribute 'evals_result_'
like image 462
Ayush Aggarwal Avatar asked Oct 15 '18 11:10

Ayush Aggarwal


People also ask

What is N_estimators in XGBoost?

n_estimators — the number of runs XGBoost will try to learn. learning_rate — learning speed.

What is DMatrix in XGBoost?

DMatrix is an internal data structure that is used by XGBoost, which is optimized for both memory efficiency and training speed. You can construct DMatrix from multiple different sources of data.

What is N_jobs in XGBoost?

By Harish AmatyaPosted in Questions & Answers 2 years ago. 0. "On larger datasets where runtime is a consideration, you can use parallelism to build your models faster. It's common to set the parameter n_jobs equal to the number of cores on your machine."


1 Answers

I got exactly the same error, the solution it's to pass the eval_set to the fit function and not in the creation of the classifier

clf.fit(x,y,eval_set=eval_s) 

Then you can run clf.evals_result()

like image 87
Marco Visibelli Avatar answered Nov 15 '22 09:11

Marco Visibelli