text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import os

import pandas as pd

import seaborn as sns

data_path = '/kaggle/input/covidx9a/'
images_path = '/kaggle/input/covidx-cxr2/train'
data_file = 'train_COVIDx9A.txt'
train = pd.read_csv(os.path.join(data_path, data_file), header=None, sep=' ')
train.columns = ['patient id', 'filename', 'class', 'data source']

plt.figure(figsize=(8, 6))
sns.histplot(data=train, x='data source', hue='class')
plt.show()
data_classes = train['class'].unique()
df_summary_count = pd.DataFrame()
for dataset in ['cohen', 'fig1', 'actmed', 'sirm', 'ricord', 'rsna', 'stonybrook', 'bimcv', 'rnsa']:
    num_negative = train.loc[(train['data source'] == dataset) & (train['class'] == data_classes[0]), 'filename'].count()
    if len(data_classes) == 2:
        num_positive = train.loc[(train['data source'] == dataset) & (train['class'] == data_classes[1]), 'filename'].count()
        df_new = pd.DataFrame({'Dataset': [dataset], 'Covid': [num_positive], 'Negative': [num_negative]})
    elif len(data_classes) == 3:
        num_pneumonia = train.loc[(train['data source'] == dataset) & (train['class'] == data_classes[1]), 'filename'].count()
        num_positive = train.loc[(train['data source'] == dataset) & (train['class'] == data_classes[2]), 'filename'].count()
        df_new = pd.DataFrame({'Dataset': [dataset], 'Covid': [num_positive], 'Pneumonia': [num_pneumonia], 'Negative': [num_negative]})
    else:
        print(f'Error! Not accounting for {len(data_classes)} no. of classes.')
    df_summary_count = pd.concat([df_summary_count, df_new])
display(df_summary_count)