types of machine learning figure we'll turn an image into something usable by the naive bayes classifier by getting the grayscale value for each of its pixels (shown on the rightand putting those values in list the previous code snippet shows the matrix of figure flattened (the number of dimensions was reduced from two to oneto python list from this point onit' standard classification problemwhich brings us to step five of the data science processmodel building now that we have way to pass the contents of an image into the classifierwe need to pass it training data set so it can start learning how to predict the numbers in the images we mentioned earlier that scikit-learn contains subset of the mnist database ( , images)so we'll use that each image is also labeled with the number it actually shows this will build probabilistic model in memory of the most likely digit shown in an image given its grayscale values once the program has gone through the training set and built the modelwe can then pass it the test set of data to see how well it has learned to interpret the images using the model the following listing shows how to implement these steps in code listing image data classification problem on images of digits from sklearn cross_validation import train_test_split from sklearn naive_bayes import gaussiannb from sklearn metrics import confusion_matrix import pylab as plt digits target step split into test set and training set n_samples len(digits imagesxdigits images reshape((n_samples- )step select target variable step prepare data reshape adapts the matrix form this method couldfor instanceturn matrix into vectors print x_trainx_testy_trainy_test train_test_split(xyrandom_state=