## How to do Fashion MNIST image classification using Xgboost in Python
def Snippet_341():
print()
print(format('How to do Fashion MNIST image classification using Xgboost in Python','*^88'))
import warnings
warnings.filterwarnings("ignore")
# load libraries
from keras.datasets import fashion_mnist
from sklearn import metrics
import xgboost as xgb
from sklearn.model_selection import cross_val_score
import time
start_time = time.time()
# data: shuffled and split between train and test sets
(X_train, y_train), (X_test, y_test) = fashion_mnist.load_data()
# X_train is 60000 rows of 28x28 values --> reshaped in 60000 x 784
RESHAPED = 784
X_train = X_train.reshape(60000, RESHAPED)
X_test = X_test.reshape(10000, RESHAPED)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
# normalize the datasets
X_train /= 255.
X_test /= 255.
print(X_train.shape[0], 'train samples')
print(X_test.shape[0], 'test samples')
# fit a Xgboost model to the data
model = xgb.XGBClassifier()
cv_results = cross_val_score(model, X_train, y_train,
cv = 2, scoring='accuracy', n_jobs = -1, verbose = 1)
model.fit(X_train, y_train, verbose=True)
print(); print(cv_results)
print(); print(model)
# make predictions
expected_y = y_test
predicted_y = model.predict(X_test)
# summarize the fit of the model
print(); print(metrics.classification_report(expected_y, predicted_y))
print(); print(metrics.confusion_matrix(expected_y, predicted_y))
print()
print("Execution Time %s seconds: " % (time.time() - start_time))
Snippet_341()