Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,7 +64,7 @@ def load_data():
|
|
| 64 |
disease_dict = {
|
| 65 |
'Fungal infection': 0, 'Allergy': 1, 'GERD': 2, 'Chronic cholestasis': 3, 'Drug Reaction': 4,
|
| 66 |
'Peptic ulcer disease': 5, 'AIDS': 6, 'Diabetes': 7, 'Gastroenteritis': 8, 'Bronchial Asthma': 9,
|
| 67 |
-
'Hypertension': 10, 'Migraine': 11, 'Cervical spondylosis': 12, 'Paralysis': 13,
|
| 68 |
'Jaundice': 14, 'Malaria': 15, 'Chicken pox': 16, 'Dengue': 17, 'Typhoid': 18,
|
| 69 |
'Hepatitis A': 19, 'Hepatitis B': 20, 'Hepatitis C': 21, 'Hepatitis D': 22, 'Hepatitis E': 23,
|
| 70 |
'Alcoholic hepatitis': 24, 'Tuberculosis': 25, 'Common Cold': 26, 'Pneumonia': 27,
|
|
@@ -80,37 +80,36 @@ def load_data():
|
|
| 80 |
# Unique values for debugging
|
| 81 |
print("Unique values in prognosis after mapping:", df['prognosis'].unique())
|
| 82 |
|
| 83 |
-
#
|
| 84 |
-
if df['prognosis'].dtype == 'object': # Check
|
| 85 |
-
raise ValueError(f"
|
| 86 |
|
| 87 |
-
# Convert to integer
|
| 88 |
-
df['prognosis'] = df['prognosis'].astype(int)
|
| 89 |
|
| 90 |
# Inference doesn't require fixing as copy=True defaults
|
| 91 |
df = df.infer_objects()
|
| 92 |
|
| 93 |
tr.replace({'prognosis': disease_dict}, inplace=True)
|
| 94 |
-
|
| 95 |
# Ensure it is also numerical
|
| 96 |
if tr['prognosis'].dtype == 'object':
|
| 97 |
raise ValueError(f"Testing data prognosis contains unmapped values: {tr['prognosis'].unique()}")
|
| 98 |
-
|
| 99 |
-
tr['prognosis'] = tr['prognosis'].astype(int) # Convert to integer
|
| 100 |
-
tr = tr.infer_objects()
|
| 101 |
|
| 102 |
return df, tr, disease_dict
|
| 103 |
|
| 104 |
df, tr, disease_dict = load_data()
|
| 105 |
-
l1 = list(df.columns[:-1])
|
| 106 |
X = df[l1]
|
| 107 |
y = df['prognosis']
|
| 108 |
X_test = tr[l1]
|
| 109 |
y_test = tr['prognosis']
|
| 110 |
|
| 111 |
-
# Encode the target variable with LabelEncoder if
|
| 112 |
le = LabelEncoder()
|
| 113 |
-
y_encoded = le.fit_transform(y) #
|
| 114 |
|
| 115 |
def train_models():
|
| 116 |
models = {
|
|
|
|
| 64 |
disease_dict = {
|
| 65 |
'Fungal infection': 0, 'Allergy': 1, 'GERD': 2, 'Chronic cholestasis': 3, 'Drug Reaction': 4,
|
| 66 |
'Peptic ulcer disease': 5, 'AIDS': 6, 'Diabetes': 7, 'Gastroenteritis': 8, 'Bronchial Asthma': 9,
|
| 67 |
+
'Hypertension': 10, 'Migraine': 11, 'Cervical spondylosis': 12, 'Paralysis (brain hemorrhage)': 13,
|
| 68 |
'Jaundice': 14, 'Malaria': 15, 'Chicken pox': 16, 'Dengue': 17, 'Typhoid': 18,
|
| 69 |
'Hepatitis A': 19, 'Hepatitis B': 20, 'Hepatitis C': 21, 'Hepatitis D': 22, 'Hepatitis E': 23,
|
| 70 |
'Alcoholic hepatitis': 24, 'Tuberculosis': 25, 'Common Cold': 26, 'Pneumonia': 27,
|
|
|
|
| 80 |
# Unique values for debugging
|
| 81 |
print("Unique values in prognosis after mapping:", df['prognosis'].unique())
|
| 82 |
|
| 83 |
+
# Ensure prognosis is purely numerical after mapping
|
| 84 |
+
if df['prognosis'].dtype == 'object': # Check for unmapped entries
|
| 85 |
+
raise ValueError(f"The prognosis contains unmapped values: {df['prognosis'].unique()}")
|
| 86 |
|
| 87 |
+
df['prognosis'] = df['prognosis'].astype(int) # Convert to integer
|
|
|
|
| 88 |
|
| 89 |
# Inference doesn't require fixing as copy=True defaults
|
| 90 |
df = df.infer_objects()
|
| 91 |
|
| 92 |
tr.replace({'prognosis': disease_dict}, inplace=True)
|
| 93 |
+
|
| 94 |
# Ensure it is also numerical
|
| 95 |
if tr['prognosis'].dtype == 'object':
|
| 96 |
raise ValueError(f"Testing data prognosis contains unmapped values: {tr['prognosis'].unique()}")
|
| 97 |
+
|
| 98 |
+
tr['prognosis'] = tr['prognosis'].astype(int) # Convert to integer
|
| 99 |
+
tr = tr.infer_objects() # Remove 'copy' argument
|
| 100 |
|
| 101 |
return df, tr, disease_dict
|
| 102 |
|
| 103 |
df, tr, disease_dict = load_data()
|
| 104 |
+
l1 = list(df.columns[:-1]) # All columns except prognosis
|
| 105 |
X = df[l1]
|
| 106 |
y = df['prognosis']
|
| 107 |
X_test = tr[l1]
|
| 108 |
y_test = tr['prognosis']
|
| 109 |
|
| 110 |
+
# Encode the target variable with LabelEncoder if still in string format
|
| 111 |
le = LabelEncoder()
|
| 112 |
+
y_encoded = le.fit_transform(y) # Needs to be only string labels for the encoder
|
| 113 |
|
| 114 |
def train_models():
|
| 115 |
models = {
|