Lab 6
Lab 6
A 5 * 3 matrix
forms the numbers. For any valid point it is taken as 1 and invalid point it is
taken as 0. The net has to be trained to recognize all the numbers and
when the test data is given, the network has to recognize the particular
numbers
In [ ]: import numpy as np
from sklearn.neural_network import MLPClassifier
[[0, 1, 0],
[0, 1, 0],
[0, 1, 0],
[0, 1, 0],
[0, 1, 0]], # Number 1
[[1, 1, 1],
[0, 0, 1],
[1, 1, 1],
[1, 0, 0],
[1, 1, 1]], # Number 2
[[1, 1, 1],
[1, 0, 1],
[1, 1, 1],
[0, 0, 1],
[1, 1, 1]] # Number 39
])
In [ ]: # Define labels
y_train = [0, 1, 2, 39]
Out[ ]: ▾ MLPClassifier i ?
MLPClassifier(hidden_layer_sizes=(10,), max_iter=1000)
In [ ]: # Test data
X_test = np.array([
[[0, 1, 0],
[0, 1, 0],
[0, 1, 0],
[0, 1, 0],
[0, 1, 0]], # Number 1
[[1, 1, 1],
[0, 0, 1],
[1, 1, 1],
[1, 0, 0],
[1, 1, 1]], # Number 2
[[1, 1, 1],
[1, 0, 1],
[1, 1, 1],
[0, 0, 1],
[1, 1, 1]], # Number 39
[[1, 1, 1],
[1, 0, 1],
[1, 0, 1],
[1, 0, 1],
[1, 1, 1]] # Number 0
])
In [ ]: # Print predictions
for i, pred in enumerate(predictions):
print(f"Test {i+1}: Predicted number is {pred}")