سعی کردم تشخیص دست خط رو اجرا اجرا کنم، ولی ارورها کم نمیشوند
#%%
import time
import random
from sklearn import datasets
digits_dataset = datasets.load_digits()
images = digits_dataset.data
labels = digits_dataset.target
rows_count, x_count = images.shape
images.data.shape
start_time = time.time()
print("Learning started at: " + str(start_time))
bias = 1
weights = []
weight_bias = random.random()
for _ in range(x_count):
weights.append(random.random())
random_weights = weights[:]
for epoch in range(10000):
for image, label in zip(images[:1000], labels[:1000]):
result = 0
for pixel, weight in zip(image, weights):
result += (pixel / 16) * weight
result += bias * weight_bias
result = result % 10
error = label - result
for i, (x, weight) in enumerate(zip(image, weights)):
weights[i] = weights[i] + ((x / 16) * error)
weight_bias += bias * error
if epoch % 50 == 0:
print("Epoch", epoch, "error", error, "Duration", time.time() - start_time)
end_time = time.time()
print("During: " + str(end_time - start_time))
tuple(zip(random_weights, weights))