Question: I have a data set given as follows:
target shape `(200000, 1)`
train\_data.shape `(200000, 48)`
test\_data.shape`(100000, 48)`

I had used the data to `predict_proba` using `RandomForestClassifier` `ExtraTreesClassifier` `RandomForestClassifier` `AdaBoostClassifier` `GradientBoostingClassifier` and `SVC`
and got results without an error.

BUT
===

`clf = XGBClassifier()` is showing following errors (with the same code except `clf`):

`ValueError: feature_names mismatch:`

Answer: 
The problem occurs due to `DMatrix..num_col()` only returning the amount of non-zero columns in a sparse matrix. Hence, if both train & 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:

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

```
test_df = test_df[train_df.columns]

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

```
test_df.values instead of test_df

```
```
import numpy as np
train_data = np.array(train_data)
test_data = np.array(test_data)
clf = XGBClassifier()
clf.fit(train,y_train.ravel())
pred = clf.predict_proba(test_data)

```

Use this instead of your original code.