FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan

I joined in a competition in kaggle. The website link is https://www.kaggle.com/c/tabular-playground-series-dec-2021. First I did feature engineering on the train dataset. Then I wrote the following code to reduce the memory usage:

for col in train_set.columns:
if train_set[col].dtype == “float64”:
train_set[col]=pd.to_numeric(train_set[col], downcast=“float”)
if train_set[col].dtype == “int64”:
train_set[col]=pd.to_numeric(train_set[col], downcast=“integer”)

Then I set the original parameters and use GridSearchCV to get the value of ‘n_estimators’. The code is as follows:

train_X=train_set.drop(columns=[‘Cover_Type’])
train_y=train_set[‘Cover_Type’]
xgb_model=xgb.XGBClassifier(max_depth=5,gamma=0,learning_rate=0.1,
min_child_weight=1,subsample=0.8,colsample_bytree=0.8,eval_metric=‘merror’,
random_state=1024)
param_grid={‘n_estimators’:range(100,1000,50)}
grid_search=GridSearchCV(xgb_model,param_grid,cv=5,scoring=‘accuracy’,return_train_score=True,n_jobs=-1)
grid_search.fit(train_X,train_y)
print(grid_search.best_params_,grid_search.best_score_)

But I got error:

D:\python\lib\site-packages\sklearn\model_selection_validation.py:615: FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan. Details:
Traceback (most recent call last):
File “D:\python\lib\site-packages\sklearn\model_selection_validation.py”, line 598, in _fit_and_score
estimator.fit(X_train, y_train, **fit_params)
File “D:\python\lib\site-packages\xgboost\core.py”, line 496, in inner_f
return f(**kwargs)
File “D:\python\lib\site-packages\xgboost\sklearn.py”, line 1313, in fit
train_dmatrix, evals = _wrap_evaluation_matrices(
File “D:\python\lib\site-packages\xgboost\sklearn.py”, line 368, in _wrap_evaluation_matrices
train_dmatrix = create_dmatrix(
File “D:\python\lib\site-packages\xgboost\sklearn.py”, line 1327, in
create_dmatrix=lambda **kwargs: DMatrix(nthread=self.n_jobs, **kwargs),
File “D:\python\lib\site-packages\xgboost\core.py”, line 496, in inner_f
return f(**kwargs)
File “D:\python\lib\site-packages\xgboost\core.py”, line 606, in init
handle, feature_names, feature_types = dispatch_data_backend(
File “D:\python\lib\site-packages\xgboost\data.py”, line 788, in dispatch_data_backend
return _from_pandas_df(data, enable_categorical, missing, threads,
File “D:\python\lib\site-packages\xgboost\data.py”, line 320, in _from_pandas_df
return _from_numpy_array(data, missing, nthread, feature_names, feature_types)
File “D:\python\lib\site-packages\xgboost\data.py”, line 183, in _from_numpy_array
_check_call(
File “D:\python\lib\site-packages\xgboost\core.py”, line 192, in _check_call
raise XGBoostError(py_str(_LIB.XGBGetLastError()))
xgboost.core.XGBoostError: bad allocation

warnings.warn(“Estimator fit failed. The score on this train-test”
D:\python\lib\site-packages\sklearn\model_selection_validation.py:615: FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan. Details:
Traceback (most recent call last):
File “D:\python\lib\site-packages\sklearn\model_selection_validation.py”, line 598, in _fit_and_score
estimator.fit(X_train, y_train, **fit_params)
File “D:\python\lib\site-packages\xgboost\core.py”, line 496, in inner_f
return f(**kwargs)
File “D:\python\lib\site-packages\xgboost\sklearn.py”, line 1313, in fit
train_dmatrix, evals = _wrap_evaluation_matrices(
File “D:\python\lib\site-packages\xgboost\sklearn.py”, line 368, in _wrap_evaluation_matrices
train_dmatrix = create_dmatrix(
File “D:\python\lib\site-packages\xgboost\sklearn.py”, line 1327, in
create_dmatrix=lambda **kwargs: DMatrix(nthread=self.n_jobs, **kwargs),
File “D:\python\lib\site-packages\xgboost\core.py”, line 496, in inner_f
return f(**kwargs)
File “D:\python\lib\site-packages\xgboost\core.py”, line 606, in init
handle, feature_names, feature_types = dispatch_data_backend(
File “D:\python\lib\site-packages\xgboost\data.py”, line 788, in dispatch_data_backend
return _from_pandas_df(data, enable_categorical, missing, threads,
File “D:\python\lib\site-packages\xgboost\data.py”, line 317, in _from_pandas_df
data, feature_names, feature_types = _transform_pandas_df(
File “D:\python\lib\site-packages\xgboost\data.py”, line 303, in _transform_pandas_df
arr = transformed.values
File “D:\python\lib\site-packages\pandas\core\generic.py”, line 5673, in values
return self._mgr.as_array(transpose=self._AXIS_REVERSED)
File “D:\python\lib\site-packages\pandas\core\internals\managers.py”, line 872, in as_array
arr = self._interleave(dtype=dtype, na_value=na_value)
File “D:\python\lib\site-packages\pandas\core\internals\managers.py”, line 901, in _interleave
result = np.empty(self.shape, dtype=dtype)
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 708. MiB for an array with shape (58, 3199999) and data type float32

I can’t understand the reason. Please help me. Thank you!