So I am using Xgboost for an image classification problem but I am getting a Bad Allocation error when running model.fit and passing the train data. I think that the problem must be the data but its in a 2d array as supported by XGBoost also when the data had been passed through a VGG16 Feature Extractor it worked with no problem. Any possible solutions please?
x = np.array(allImages)<br>
y = np.array(allLabels)<br>
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=123)<br>
le = preprocessing.LabelEncoder()<br>
le.fit(y_train)<br>
y_train_encoded = le.transform(y_train)<br>
del y_train<br>
le.fit(y_test)<br>
y_test_encoded = le.transform(y_test)<br>
x_train = x_train.reshape(x_train.shape[0],-1)<br>
model = xgb.XGBClassifier(use_label_encoder=False,objective='multi:softprob',
num_class= 10)<br>
model.fit(x_train,y_train_encoded)<br>
---------------------------------------------------------------------------
XGBoostError Traceback (most recent call last)
<ipython-input-12-d0749b6882f3> in <module>
5 model = xgb.XGBClassifier(use_label_encoder=False,objective='multi:softprob',
6 num_class= 10)
----> 7 model.fit(x_train,y_train_encoded)
8 #For the kFold
9 le.fit(y)
C:\Anaconda\lib\site-packages\xgboost\core.py in inner_f(*args, **kwargs)
420 for k, arg in zip(sig.parameters, args):
421 kwargs[k] = arg
--> 422 return f(**kwargs)
423
424 return inner_f
C:\Anaconda\lib\site-packages\xgboost\sklearn.py in fit(self, X, y, sample_weight, base_margin, eval_set, eval_metric, early_stopping_rounds, verbose, xgb_model, sample_weight_eval_set, feature_weights, callbacks)
901 self.n_features_in_ = self._features_count
902
--> 903 train_dmatrix, evals = self._wrap_evaluation_matrices(
904 X, y, group=None, sample_weight=sample_weight, base_margin=base_margin,
905 feature_weights=feature_weights,
C:\Anaconda\lib\site-packages\xgboost\sklearn.py in _wrap_evaluation_matrices(self, X, y, group, sample_weight, base_margin, feature_weights, eval_set, sample_weight_eval_set, eval_group, label_transform)
263
264 y = label_transform(y)
--> 265 train_dmatrix = DMatrix(data=X, label=y, weight=sample_weight,
266 base_margin=base_margin,
267 missing=self.missing, nthread=self.n_jobs)
C:\Anaconda\lib\site-packages\xgboost\core.py in __init__(self, data, label, weight, base_margin, missing, silent, feature_names, feature_types, nthread, enable_categorical)
498
499 from .data import dispatch_data_backend
--> 500 handle, feature_names, feature_types = dispatch_data_backend(
501 data, missing=self.missing,
502 threads=self.nthread,
C:\Anaconda\lib\site-packages\xgboost\data.py in dispatch_data_backend(data, missing, threads, feature_names, feature_types, enable_categorical)
528 return _from_scipy_csr(data.tocsr(), missing, feature_names, feature_types)
529 if _is_numpy_array(data):
--> 530 return _from_numpy_array(data, missing, threads, feature_names,
531 feature_types)
532 if _is_uri(data):
C:\Anaconda\lib\site-packages\xgboost\data.py in _from_numpy_array(data, missing, nthread, feature_names, feature_types)
145 flatten = _transform_np_array(data)
146 handle = ctypes.c_void_p()
--> 147 _check_call(_LIB.XGDMatrixCreateFromMat_omp(
148 flatten.ctypes.data_as(ctypes.POINTER(ctypes.c_float)),
149 c_bst_ulong(data.shape[0]),
C:\Anaconda\lib\site-packages\xgboost\core.py in _check_call(ret)
187 """
188 if ret != 0:
--> 189 raise XGBoostError(py_str(_LIB.XGBGetLastError()))
190
191
XGBoostError: bad allocation