@coolphil15 wrote:
i am trying to learn Analytics and need help in one solving one of the practice problems.I have been trying to solve the Identify the digit problem and need help in terms of the approach in how to solve that problem.
This is the solution that I have created but I don't think it is correct.
Kindly help in implementing the correct solution:-----------------------------------------------------------Load train data and get the binary information--------------------
from PIL import Image
import glob
image_list = []
count= 0
path='D:\Python\Images\train\'
for filename in glob.glob(path + '*.png'): #assuming gif
# if count < 1000:
im=Image.open(filename).convert('L')
data = im.getdata()
nparray = np.array(data,'uint8')
image_list.append(nparray)
im.close
count = count + 1
-------------------------------------------------converting images to 2 dimension format---------------------------------
list_features = []
for img in image_list:
fd = hog(img.reshape((28, 28)), orientations=9, pixels_per_cell=(14, 14), cells_per_block=(1, 1), visualise=False)
list_features.append(fd)hog_features = np.array(list_features,'float64')
--------------------------------------------------use the SVM model to train the model---------------------------
model = svm.SVC(gamma=0.01,C=100)
model.fit(image_list,train['label'])
model.score()---------------------------------------------loading the test data and using the model to predict-------------------------------------------------
test_images = []
path='D:\Python\Images\test\'
for filename in glob.glob(path + '*.png'): #assuming gif
# if count < 1000:
im=Image.open(filename).convert('L')
data = im.getdata()
testarray = np.array(data,'uint8')
test_images.append(testarray)
im.closetestlabels = model.predict(test_images)
Thanks in advance
Posts: 1
Participants: 1