<jupyter_start><jupyter_text>Test on digitsTest of the NN on the digits dataset from scikit-learn. We'll try to predict if the picture is **1**.<jupyter_code>from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report

digits = load_digits()

X = digits['data']/16 # normalize the values between 0 and 1
Y = digits['target']
Y = (Y == 1)*1  # target value =1 for digit 1, and 0 for all other digits

Y = Y.reshape(-1, 1)
print('X shape :', X.shape)
print('Y shape :', Y.shape)<jupyter_output>X shape : (1797, 64)
Y shape : (1797, 1)<jupyter_text>Plot a digit<jupyter_code>%matplotlib inline

index = 12
digit = X[index].reshape(8,8)
target = Y[index].squeeze()

fig, ax = plt.subplots()
fig.set_size_inches(5,5)
ax.imshow(digit, cmap='gray_r')
ax.set_title('y = {}'.format(target))
ax.axis('off');<jupyter_output><empty_output><jupyter_text>Split the data into train and test set<jupyter_code>X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42)<jupyter_output><empty_output><jupyter_text>Train the model to predict images of **1**<jupyter_code>n_1, n_2 = 20, 10

parameters, cost_list = NN_model(X_train, Y_train, n_1, n_2, epoch=5000, learning_rate=0.1, verbose=True)<jupyter_output>Cost function after epoch 0 : 0.6931467373746464
Cost function after epoch 1000 : 0.3403216870700217
Cost function after epoch 2000 : 0.060395094758117204
Cost function after epoch 3000 : 0.031245351440609
Cost function after epoch 4000 : 0.02146101578023537
Cost function after epoch 5000 : 0.016894356153856288
Time : 7.218 s<jupyter_text>Train set accuracy<jupyter_code>Y_train_pred = MakePrediction(X_train, parameters)
accuracy = GetAccuracy(Y_train, Y_train_pred)

print('train set accuracy :', accuracy)
print(classification_report(Y_train, Y_train_pred))<jupyter_output>train set accuracy : 0.99652052888
             precision    recall  f1-score   support

          0       1.00      1.00      1.00      1283
          1       0.99      0.98      0.98       154

avg / total       1.00      1.00      1.00      1437<jupyter_text>Test set accuracy<jupyter_code>Y_test_pred = MakePrediction(X_test, parameters)
accuracy = GetAccuracy(Y_test, Y_test_pred)

print('test set accuracy :', accuracy)
print(classification_report(Y_test, Y_test_pred))<jupyter_output>test set accuracy : 0.986111111111
             precision    recall  f1-score   support

          0       1.00      0.98      0.99       332
          1       0.85      1.00      0.92        28

avg / total       0.99      0.99      0.99       360
{'fraction_non_alphanumeric': 0.10064811284788411, 'fraction_numerical': 0.10789172703011818, 'mean_word_length': 3.7883211678832116, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '484341', 'license': 'MIT', 'n_tokens_mistral': 1113, 'n_tokens_neox': 935, 'n_words': 237, 'path': 'Test/NN_test.ipynb', 'repo_name': 'ArthMx/ANN', 'size': '2623'}