XGBClassifier error! ValueError: feature_names mismatch:
The problem occurs due to DMatrix..num_col() only returning the amount of non-zero columns in a sparse matrix. Hence, if both train &amp; test data have the same amount of non-zero columns, everything works fine. Otherwise, you end up with different feature names lists. There're currently three solutions to work around this problem:


realign the columns names of the train dataframe and test dataframe using:

test_df = test_df[train_df.columns]

save the model first and then load the model
change the test data into array before feeding into the model, ie: use, 

test_df.values instead of test_df