I'm a newbie to this machine learning concepts! I've made a model and trained it to an accuracy of 98% using KNN-Classifier, but I'm unable to test the model using an image as the input. Each datapoint contains an equivalent of 8X8 image of a digit. When I convert this into a numpy array , It gives a me list of integers between 0.0 to 16.0 (dtype = float64). But the problem , I'm unable to break down the input image into the dateset's corresponding image. The following is the executed in CMD prompt , Python version - 3x
Asked
Active
Viewed 123 times
2 Answers
0
With the information you have provided it is impossible to know what is wrong. Also, 0.0 and 16.0 are not integers, they are floats. Before training ML algorithm it is a good idea to normalize the images to a maximum of 1.0 like so numpy_Image = numpy_Image/np.max(numpy_Image)
. For KNN (and almost everything else) training and test images have to have the same size. "But the problem , I'm unable to break down the input image into the dateset's corresponding image." - post the code and the error message you get in terminal, please.

Aramakus
- 1,910
- 2
- 11
- 22
-
1Thanks for the info, Sir. Your suggestion was highly useful . Now , my model is working fine. Sorry, Since I was totally new to this platform, so didn't know how to post stuff . Thanks again :) – Mohammed Hashim May 12 '20 at 16:19
0
To print an array as an image, use:
import matplotlib.pyplot as plt
import numpy as np
array = np.array([0,0,0,10,9,0,0,0,0,0,5,15,0,0,9,5,0,0,14,10,0,7,16,4,0,5,16,7,5,16,6,0,0,11,16,16,16,14,0,0,0,3,4,11,16,8,0,0,0,0,0,7,16,2,0,0,0,0,0,12,12,0,0,0])
plt.imshow(array.reshape(8,8))
plt.show()
Next time, make sure your data can be easily copy and pasted, pictures are frowned upon.

Bobby Ocean
- 3,120
- 1
- 8
- 15