TypeError: fit() got an unexpected keyword argument 'epochs'

Hi Team,

I am getting the following error from the model.fit code.
Any help would be great !

Tensorflow version is
TensorFlow: 2.4.1
Keras: 2.4.0
Python: 3.8.13
Xgboost: 1.7.5
numpy ver: 1.22.4

system : Linux
Platform : Linux-5.15.0-76-generic-x86_64-with-glibc2.17

=============

code :
import xgboost as xgb
model_xgb = xgb.XGBClassifier()

early_stopping = tf.keras.callbacks.EarlyStopping(
monitor=‘val_accuracy’,
mode=‘max’,
patience=6
)

history = model_xgb.fit(X_for_training, y_train, epochs=25, batch_size=32, verbose=2,callbacks=[early_stopping])

===========
log & error:


TypeError Traceback (most recent call last)
Input In [60], in <cell line: 11>()
3 model_xgb = xgb.XGBClassifier()
5 early_stopping = tf.keras.callbacks.EarlyStopping(
6 monitor=‘val_accuracy’,
7 mode=‘max’,
8 patience=6
9 )
—> 11 history = model_xgb.fit(X_for_training, y_train, epochs=25, batch_size=32, verbose=2,callbacks=[early_stopping])

File ~/miniconda3/lib/python3.8/site-packages/xgboost/core.py:620, in require_keyword_args..throw_if..inner_f(*args, **kwargs)
618 for k, arg in zip(sig.parameters, args):
619 kwargs[k] = arg
→ 620 return func(**kwargs)

TypeError: fit() got an unexpected keyword argument ‘epochs’

Hi @SP1 ,

The error message you are getting is because the epochs argument is not supported by the XGBoost fit() method. This argument is used by Keras, but not by XGBoost.

If you want to control the number of epochs that XGBoost trains for, you can use the n_estimators argument. The following code will train XGBoost for 25 epochs:

model_xgb = xgb.XGBClassifier(n_estimators = 25 or epochs = 25) # n_estimators is number of boosting rounds (equivalent to epochs in deep learning)

history = model_xgb.fit(X_for_training, y_train, batch_size=32, verbose=2, callbacks=[early_stopping])

I hope this helps! Let me know if you have any other questions.

Thanks.