D-Khalid/GeneScout_AI_Predictive_Pathologist
1
1# eda_analysis.py2 3import pandas as pd4import seaborn as sns5import matplotlib.pyplot as plt6 7# --- Step 1: Load the Data ---8print("Loading dataset...")9df = pd.read_csv('genetic_disease_dataset.csv')10 11# --- Step 2: Decode the "Disease" Column ---12# Mapping 0-4 to actual names so the saved images are readable13disease_map = {14 0: 'Thalassemia',15 1: 'Hemophilia',16 2: 'Breast Cancer',17 3: 'Sickle Cell Anemia',18 4: 'Cystic Fibrosis'19}20df['Disease_Name'] = df['Disease'].map(disease_map)21 22# --- Step 3: Check for Class Imbalance (Saved as Image) ---23print("Generating Disease Distribution plot...")24plt.figure(figsize=(10, 6))25sns.countplot(x='Disease_Name', data=df, palette='viridis')26plt.title('Distribution of Patients per Disease')27plt.xticks(rotation=45)28plt.tight_layout()29 30# SAVE the plot instead of showing it31plt.savefig('1_disease_distribution.png') 32plt.close() # Close memory to prevent overlap33 34 35# --- Step 4: The Correlation Matrix (Saved as Image) ---36print("Generating Correlation Heatmap...")37plt.figure(figsize=(12, 10))38numeric_df = df.drop('Disease_Name', axis=1) 39sns.heatmap(numeric_df.corr(), annot=True, fmt=".2f", cmap='coolwarm')40plt.title('Feature Correlation Heatmap')41plt.tight_layout()42 43# SAVE the plot44plt.savefig('2_correlation_heatmap.png')45plt.close()46 47 48# --- Step 5: The "Smoking Gun" Evidence (Saved as Image) ---49print("Generating Biomarker Boxplots...")50fig, axes = plt.subplots(2, 2, figsize=(16, 12))51 52# 1. Cystic Fibrosis Check: Sweat Chloride53sns.boxplot(x='Disease_Name', y='Sweat_Chloride', data=df, ax=axes[0, 0])54axes[0, 0].set_title('Sweat Chloride Levels (High in CF?)')55axes[0, 0].tick_params(axis='x', rotation=45)56 57# 2. Sickle Cell Check: Sickled RBC %58sns.boxplot(x='Disease_Name', y='Sickled_RBC_Percent', data=df, ax=axes[0, 1])59axes[0, 1].set_title('Sickled RBC % (High in Sickle Cell?)')60axes[0, 1].tick_params(axis='x', rotation=45)61 62# 3. Breast Cancer Check: BRCA1 Expression63sns.boxplot(x='Disease_Name', y='BRCA1_Expression', data=df, ax=axes[1, 0])64axes[1, 0].set_title('BRCA1 Gene Expression (High in Cancer?)')65axes[1, 0].tick_params(axis='x', rotation=45)66 67# 4. Thalassemia Check: Fetal Hemoglobin68sns.boxplot(x='Disease_Name', y='Fetal_Hemoglobin', data=df, ax=axes[1, 1])69axes[1, 1].set_title('Fetal Hemoglobin (High in Thalassemia?)')70axes[1, 1].tick_params(axis='x', rotation=45)71 72plt.tight_layout()73 74# SAVE the plot75plt.savefig('3_biomarker_analysis.png')76plt.close()77 78print("\nSUCCESS: All plots saved to your folder!")