<jupyter_start><jupyter_text>Using Train Test Split<jupyter_code>train, validate = train_test_split(data, test_size = 0.2, shuffle = True, random_state = 42, stratify = data['category'])
train.head(10)
validate.head()
train['category'].value_counts()
validate['category'].value_counts()
batch_size = 10
train_datagen= ImageDataGenerator(zoom_range = 0.1, shear_range = 0.1, horizontal_flip = True, rescale = 1./255)
train_generator =train_datagen.flow_from_dataframe(train, 'D:/Data/COVID-19_Radiography_Dataset/train/', 
                                                  x_col = 'filename', y_col = 'category',target_size = IMAGE_SIZE,
                                                   
                                                  class_mode = 'categorical', batch_size = batch_size)
valid_datagen= ImageDataGenerator(zoom_range = 0.1, shear_range = 0.1, horizontal_flip = True, rescale = 1./255)
valid_generator =valid_datagen.flow_from_dataframe(validate, 'D:/Data/COVID-19_Radiography_Dataset/train/', 
                                                  x_col = 'filename', y_col = 'category',target_size = IMAGE_SIZE,
                                                   
                                                  class_mode = 'categorical', batch_size = batch_size)
example = train.sample(n=1).reset_index(drop = True)
example_generator = train_datagen.flow_from_dataframe(example, 'D:/Data/COVID-19_Radiography_Dataset/train/',
                                                   x_col = 'filename', y_col = 'category', target_size = IMAGE_SIZE,
                                                      
                                                   class_mode = 'categorical')
plt.figure(figsize = (12, 12))
for i in range(0, 2):
    plt.subplot(1, 2, i+1)
    for X_batch, Y_batch in example_generator:
        image = X_batch[0]
        plt.imshow(image)
        break
plt.tight_layout()
plt.show()
model.fit(train_generator,validation_data=valid_generator,epochs=5,verbose=2)<jupyter_output>Epoch 1/5
606/606 - 338s - loss: 0.5487 - accuracy: 0.7568 - val_loss: 0.5329 - val_accuracy: 0.7770
Epoch 2/5
606/606 - 308s - loss: 0.4520 - accuracy: 0.8078 - val_loss: 2.5081 - val_accuracy: 0.7493
Epoch 3/5
606/606 - 324s - loss: 0.4063 - accuracy: 0.8279 - val_loss: 0.4343 - val_accuracy: 0.8305
Epoch 4/5
606/606 - 332s - loss: 0.3950 - accuracy: 0.8340 - val_loss: 2.3802 - val_accuracy: 0.3694
Epoch 5/5
606/606 - 296s - loss: 0.3798 - accuracy: 0.8345 - val_loss: 0.3839 - val_accuracy: 0.8351<jupyter_text>Using KFold Crossvalidation<jupyter_code>n_folds = 3
epochs = 5
batch_size = 10
for i in range(n_folds):
    train_fold, test_fold = train_test_split(data, test_size = 0.2, random_state = 42, shuffle = True, 
                                             stratify = data['category'])
train_datagen_fold= ImageDataGenerator(zoom_range = 0.1, shear_range = 0.1, horizontal_flip = True, rescale = 1./255)
train_generator_fold =train_datagen_fold.flow_from_dataframe(train_fold, 'D:/Data/COVID-19_Radiography_Dataset/train/', 
                                                  x_col = 'filename', y_col = 'category',target_size = IMAGE_SIZE,
                                                   
                                                  class_mode = 'categorical', batch_size = batch_size)
valid_datagen_fold = ImageDataGenerator(zoom_range = 0.1, shear_range = 0.1, horizontal_flip = True, rescale = 1./255)
valid_generator_fold =valid_datagen_fold.flow_from_dataframe(test_fold, 'D:/Data/COVID-19_Radiography_Dataset/train/', 
                                                  x_col = 'filename', y_col = 'category',target_size = IMAGE_SIZE,
                                                  class_mode = 'categorical', batch_size = batch_size)
example = train.sample(n=1).reset_index(drop = True)
example_generator = train_datagen_fold.flow_from_dataframe(example, 'D:/Data/COVID-19_Radiography_Dataset/train/',
                                                   x_col = 'filename', y_col = 'category', target_size = IMAGE_SIZE,
                                                      
                                                   class_mode = 'categorical')
plt.figure(figsize = (12, 12))
for i in range(0, 2):
    plt.subplot(1, 2, i+1)
    for X_batch, Y_batch in example_generator:
        image = X_batch[0]
        plt.imshow(image)
        break
plt.tight_layout()
plt.show()
physical_devices = tf.config.experimental.list_physical_devices('GPU')
print("Num GPUs available: ", len(physical_devices))
model.fit(train_generator_fold,validation_data=valid_generator_fold,epochs=5,verbose=2)
model.fit(train_generator_fold,validation_data=valid_generator_fold,epochs=20, verbose =2)
plt.figure(figsize=(10,5))
plt.plot(model.history.history["loss"],label="loss")
plt.plot(model.history.history["val_loss"],label="val_loss")
plt.legend()
plt.figure(figsize=(10,5))
plt.plot(model.history.history["accuracy"],label="accuracy")
plt.plot(model.history.history["val_accuracy"],label="val_accuracy")
plt.legend(loc='upper left')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11300765155974102, 'fraction_numerical': 0.04904845987835982, 'mean_word_length': 2.376158940397351, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '254412', 'license': 'MIT', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1543, 'n_words': 277, 'path': 'Covid Predictions.ipynb', 'repo_name': 'Mayank0255/IT1634-Minor-Project', 'size': '5097'}