2020-05-19 22:02:42 +02:00
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import numpy as np
|
|
|
|
from numpy import asarray
|
|
|
|
from sklearn import datasets
|
|
|
|
from sklearn.neural_network import MLPClassifier
|
|
|
|
from sklearn.metrics import accuracy_score
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
2020-05-20 07:36:18 +02:00
|
|
|
def train():
|
|
|
|
# recznie napisane cyfry
|
|
|
|
digits = datasets.load_digits()
|
2020-05-19 22:02:42 +02:00
|
|
|
|
2020-05-20 07:36:18 +02:00
|
|
|
y = digits.target
|
|
|
|
x = digits.images.reshape((len(digits.images), -1))
|
2020-05-19 22:02:42 +02:00
|
|
|
|
2020-05-20 07:36:18 +02:00
|
|
|
x_train = x[:1000000]
|
|
|
|
y_train = y[:1000000]
|
|
|
|
x_test = x[1000:]
|
|
|
|
y_test = y[1000:]
|
2020-05-19 22:02:42 +02:00
|
|
|
|
2020-05-20 07:36:18 +02:00
|
|
|
mlp = MLPClassifier(hidden_layer_sizes=(15,), activation='logistic', alpha=1e-4,
|
|
|
|
solver='sgd', tol=1e-4, random_state=1,
|
|
|
|
learning_rate_init=.1, verbose=True)
|
2020-05-19 22:02:42 +02:00
|
|
|
|
2020-05-20 07:36:18 +02:00
|
|
|
mlp.fit(x_train, y_train)
|
|
|
|
|
|
|
|
predictions = mlp.predict(x_test)
|
|
|
|
print(accuracy_score(y_test, predictions))
|