Сюжет особенности имен по важности функций XGBoost - PullRequest
0 голосов
/ 03 июня 2019

Я работаю над проектом ML, это бинарная классификация, и я тренирую XGBoost.

Я хочу показать важность функций после моей перекрестной проверки, но мне не удалось это сделать. Вот мой текущий код:

# transform X, Y, X_test, to array
X_cross = np.array(X_train)
Y_cross = np.array(Y_train)
test = np.array(X_test)
id_test = X_test.index.values
sub = pd.DataFrame()
sub['id'] = id_test
sub['target'] = np.zeros_like(id_test)
list_names = list(X_train.columns)
# for each K, a new section of index will be used for the separation of train set and test set
for i, (train_index, test_index) in enumerate(skf.split(X_cross, Y_cross)): print('[Fold %d/%d]' % (i + 1, kfold)) 
# Split data with the the index computed with the function of cross_val
X_train_kfd, X_valid=X_cross[train_index],X_cross[test_index]
y_train_kfd, y_valid = Y_cross[train_index], Y_cross[test_index] 
#Convert our data into XGBoost format 
d_train = xgboost.DMatrix(X_train_kfd,label=y_train_kfd, feature_names=list_names) 
d_valid = xgboost.DMatrix(X_valid,label=y_valid, feature_names=list_names) 
d_test  = xgboost.DMatrix(X_test.values) 
watchlist = [(d_train, 'train'), (d_valid, 'valid')] 
# Train the model. We pass in a max of 2500 rounds (with early stopping after 60) 
mdl = xgboost.train(gbm_params,d_train,2500,evals=watchlist,early_stopping_rounds=60,verbose_eval =10) 
print('[Fold %d/%d Prediction:]' % (i + 1, kfold)) 
# Predict on our test data 
p_test = mdl.predict(d_test) 
sub['target'] += p_test/kfold

Я пытался передать имена своих функций в DMatrix (потому что я использую массивы numpy), но, похоже, это не работает.

И ошибка, которую я получаю:

несоответствие имен_функций: ['x1', 'x2', 'x3' ...] ['f0', 'f1', 'f2', 'f3' ...] ожидаемые x1, x2, x3 ... во входных данных обучения данные не имели следующих полей: f1, f2, f3 ...

Может ли кто-нибудь мне помочь?

Большое спасибо.

...