<jupyter_start><jupyter_text>Predictions<jupyter_code>X_test = []
y_test = []
for features, label in testing_data:
    X_test.append(features)
    y_test.append(label)
    
X_test = (np.array(X_test).reshape(-1, img_size, img_size, 3))/255
y_test = np.array(y_test)
print(X_test.shape)
print(y_test.shape)
preds = model.predict(X_test)
len(preds)
predictions_AD = []
y_pred = []
for i in preds:
    if i <= 0.50:
        predictions_AD.append('AD')
        y_pred.append(0)
    else:
        predictions_AD.append('CN')
        y_pred.append(1)

predictions_AD.count('AD')
1861/2982
predictions_AD.count('CN')
path_AD_test = '/Users/ferasaltwal/Documents/DSI/New-Capstone/extracted-png_renamed-skull-stripped/test/AD'
path_CN_test = '/Users/ferasaltwal/Documents/DSI/New-Capstone/extracted-png_renamed-skull-stripped/test/CN'
#let's write a function to preprocess new images to feed into the model
def prepare_img(filepath):
    img_size = 150
    img_array = cv2.imread(filepath)
    new_array = cv2.resize(img_array, (img_size, img_size))
    return (new_array.reshape(-1, img_size, img_size, 3))/255
pred_list_AD = []
for img in os.listdir(path_AD_test):
    if img != '.DS_Store':
        prediction = model.predict([prepare_img(os.path.join(path_AD_test, img))])
        if int(prediction[0][0]) == 0:
            pred_list_AD.append('AD')
#         elif prediction[0][1] == 1:
#             pred_list.append('MCI')
        elif int(prediction[0][0]) == 1:
            pred_list_AD.append('CN')
len(pred_list_AD)
pred_list_AD.count('AD')
pred_list_CN = []
for img in os.listdir(path_CN_test):
    if img != '.DS_Store':
        prediction = model.predict([prepare_img(os.path.join(path_CN_test, img))])
        if int(prediction[0][0]) == 0:
            pred_list_CN.append('AD')
#         elif prediction[0][1] == 1:
#             pred_list.append('MCI')
        elif int(prediction[0][0]) == 1:
            pred_list_CN.append('CN')
len(pred_list_CN)
pred_list_CN.count('CN')
train_loss = history.history['loss']
test_loss = history.history['val_loss']

# Set figure size.
plt.figure(figsize=(12, 8))

# Generate line plot of training, testing loss over epochs.
plt.plot(train_loss, label='Training Loss', color='#185fad')
plt.plot(test_loss, label='Testing Loss', color='orange')

# Set title
plt.title('Training and Testing Loss by Epoch', fontsize = 25)
plt.xlabel('Epoch', fontsize = 18)
plt.ylabel('binary Crossentropy', fontsize = 18)
plt.xticks(np.arange(10), np.arange(10))

plt.legend(fontsize = 18);
train_acc = history.history['accuracy']
test_acc = history.history['val_accuracy']

# Set figure size.
plt.figure(figsize=(12, 8))

# Generate line plot of training, testing loss over epochs.
plt.plot(train_acc, label='Training accuracy', color='#185fad')
plt.plot(test_acc, label='Testing accuracy', color='orange')

# Set title
plt.title('Training and Testing accuracy by Epoch', fontsize = 25)
plt.xlabel('Epoch', fontsize = 18)
plt.ylabel('Categorical Crossentropy', fontsize = 18)
plt.xticks(np.arange(10), np.arange(10))

plt.legend(fontsize = 18);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15124153498871332, 'fraction_numerical': 0.026443082876491456, 'mean_word_length': 4.329896907216495, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '554435', 'license': 'CC0-1.0', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1127, 'n_words': 214, 'path': 'code/modeling-with-skull-stripped-images/other codes/first-model.ipynb', 'repo_name': 'ferastwal/AD-Predictions-Capstone-Project', 'size': '3101'}