How to Sort Read Handwritten Number Python

How to classify handwritten digits in python

Without the assistance of any machine learning libraries

Drew Parmelee

There exists some mathematical function that tin can tell us what is in the picture, based on the input (photons) we receive from the flick.

Getting and cleaning our information

This picture is labeled as a 3. *Image past author*

*Image by author*
                      import pandas as pd
import numpy every bit np
import matplotlib.pyplot as plt
data = pd.read_csv('mnist_train.csv')

*Image by author*
                      labels = np.array(information.iloc[:,0])
x_train = np.array(data.iloc[:,ane:])/255
# We dissever past 255 then that all inputs are between 0 and 1
                      encoded_labels = []
for i in range(len(labels)):
naked = [0,0,0,0,0,0,0,0,0,0]
naked[labels[i]] = i
encoded_labels.append(naked)
                      # Take a look at what the images wait like
random_index = np.random.randint(0,40000)
img = x_train[random_index].reshape(28,28)
plt.imshow(img, cmap = "gray")

*Image past author*

Creating our Neural Network and grooming

                      model = DNN([784,1250,10])                                from collections import deque
mistake = deque(maxlen = 1000)
"""A deque is just a list that stays at 1000 units long (last item gets deleted when a new item gets added when at length = chiliad)"""
for n in range(30000):
index = np.random.randint(0,59998)
mistake.append(model.railroad train(x_train[alphabetize], encoded_labels[index]))
if n%1000 == 0:
print("\nStep: ",n)
print("Average Error: ", sum(error)/grand)
plt.imshow(x_train[index].reshape(28,28), cmap = "gray")
plt.show()
print("Prediction: ", np.argmax(model.predict(x_train[index])))

Results and testing

                      test_data = pd.read_csv('mnist_test.csv')
test_labels = np.assortment(test_data.iloc[:,0])
x_test = np.array(test_data.iloc[:,i:])/255
correct = 0 for i in range(len(test_data)):
prediction = np.argmax(model.predict(x_test[i]))
if prediction == test_labels[i]:
correct +=i
percent_correct = right/len(test_data) * 100
print(percent_correct,'%')

hatcherharioned.blogspot.com

Source: https://towardsdatascience.com/how-to-classify-handwritten-digits-in-python-7706b1ab93a3

0 Response to "How to Sort Read Handwritten Number Python"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel