├── .gitignore ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multiple Disease prediction 2 | ## Application code: 3 | import os 4 | import pickle 5 | import streamlit as st 6 | from streamlit_option_menu import option_menu 7 | 8 | ### Set page configuration 9 | st.set_page_config(page_title="Health Assistant", 10 | layout="wide", 11 | page_icon="🧑‍⚕️") 12 | 13 | 14 | ### getting the working directory of the main.py 15 | working_dir = os.path.dirname(os.path.abspath(__file__)) 16 | 17 | ### loading the saved models 18 | 19 | diabetes_model = pickle.load(open(f'{working_dir}/saved_models/diabetes_model.sav', 'rb')) 20 | 21 | heart_disease_model = pickle.load(open(f'{working_dir}/saved_models/heart_disease_model.sav', 'rb')) 22 | 23 | parkinsons_model = pickle.load(open(f'{working_dir}/saved_models/parkinsons_model.sav', 'rb')) 24 | 25 | ### sidebar for navigation 26 | with st.sidebar: 27 | selected = option_menu('Multiple Disease Prediction System', 28 | 29 | ['Diabetes Prediction', 30 | 'Heart Disease Prediction', 31 | 'Parkinsons Prediction'], 32 | menu_icon='hospital-fill', 33 | icons=['activity', 'heart', 'person'], 34 | default_index=0) 35 | 36 | 37 | ### Diabetes Prediction Page 38 | if selected == 'Diabetes Prediction': 39 | 40 | # page title 41 | st.title('Diabetes Prediction using ML') 42 | 43 | # getting the input data from the user 44 | col1, col2, col3 = st.columns(3) 45 | 46 | with col1: 47 | Pregnancies = st.text_input('Number of Pregnancies') 48 | 49 | with col2: 50 | Glucose = st.text_input('Glucose Level') 51 | 52 | with col3: 53 | BloodPressure = st.text_input('Blood Pressure value') 54 | 55 | with col1: 56 | SkinThickness = st.text_input('Skin Thickness value') 57 | 58 | with col2: 59 | Insulin = st.text_input('Insulin Level') 60 | 61 | with col3: 62 | BMI = st.text_input('BMI value') 63 | 64 | with col1: 65 | DiabetesPedigreeFunction = st.text_input('Diabetes Pedigree Function value') 66 | 67 | with col2: 68 | Age = st.text_input('Age of the Person') 69 | 70 | 71 | # code for Prediction 72 | diab_diagnosis = '' 73 | 74 | # creating a button for Prediction 75 | 76 | if st.button('Diabetes Test Result'): 77 | 78 | user_input = [Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, 79 | BMI, DiabetesPedigreeFunction, Age] 80 | 81 | user_input = [float(x) for x in user_input] 82 | 83 | diab_prediction = diabetes_model.predict([user_input]) 84 | 85 | if diab_prediction[0] == 1: 86 | diab_diagnosis = 'The person is diabetic' 87 | else: 88 | diab_diagnosis = 'The person is not diabetic' 89 | 90 | st.success(diab_diagnosis) 91 | 92 | ### Heart Disease Prediction Page 93 | if selected == 'Heart Disease Prediction': 94 | 95 | # page title 96 | st.title('Heart Disease Prediction using ML') 97 | 98 | col1, col2, col3 = st.columns(3) 99 | 100 | with col1: 101 | age = st.text_input('Age') 102 | 103 | with col2: 104 | sex = st.text_input('Sex') 105 | 106 | with col3: 107 | cp = st.text_input('Chest Pain types') 108 | 109 | with col1: 110 | trestbps = st.text_input('Resting Blood Pressure') 111 | 112 | with col2: 113 | chol = st.text_input('Serum Cholestoral in mg/dl') 114 | 115 | with col3: 116 | fbs = st.text_input('Fasting Blood Sugar > 120 mg/dl') 117 | 118 | with col1: 119 | restecg = st.text_input('Resting Electrocardiographic results') 120 | 121 | with col2: 122 | thalach = st.text_input('Maximum Heart Rate achieved') 123 | 124 | with col3: 125 | exang = st.text_input('Exercise Induced Angina') 126 | 127 | with col1: 128 | oldpeak = st.text_input('ST depression induced by exercise') 129 | 130 | with col2: 131 | slope = st.text_input('Slope of the peak exercise ST segment') 132 | 133 | with col3: 134 | ca = st.text_input('Major vessels colored by flourosopy') 135 | 136 | with col1: 137 | thal = st.text_input('thal: 0 = normal; 1 = fixed defect; 2 = reversable defect') 138 | 139 | # code for Prediction 140 | heart_diagnosis = '' 141 | 142 | # creating a button for Prediction 143 | 144 | if st.button('Heart Disease Test Result'): 145 | 146 | user_input = [age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal] 147 | 148 | user_input = [float(x) for x in user_input] 149 | 150 | heart_prediction = heart_disease_model.predict([user_input]) 151 | 152 | if heart_prediction[0] == 1: 153 | heart_diagnosis = 'The person is having heart disease' 154 | else: 155 | heart_diagnosis = 'The person does not have any heart disease' 156 | 157 | st.success(heart_diagnosis) 158 | 159 | ### Parkinson's Prediction Page 160 | if selected == "Parkinsons Prediction": 161 | 162 | # page title 163 | st.title("Parkinson's Disease Prediction using ML") 164 | 165 | col1, col2, col3, col4, col5 = st.columns(5) 166 | 167 | with col1: 168 | fo = st.text_input('MDVP:Fo(Hz)') 169 | 170 | with col2: 171 | fhi = st.text_input('MDVP:Fhi(Hz)') 172 | 173 | with col3: 174 | flo = st.text_input('MDVP:Flo(Hz)') 175 | 176 | with col4: 177 | Jitter_percent = st.text_input('MDVP:Jitter(%)') 178 | 179 | with col5: 180 | Jitter_Abs = st.text_input('MDVP:Jitter(Abs)') 181 | 182 | with col1: 183 | RAP = st.text_input('MDVP:RAP') 184 | 185 | with col2: 186 | PPQ = st.text_input('MDVP:PPQ') 187 | 188 | with col3: 189 | DDP = st.text_input('Jitter:DDP') 190 | 191 | with col4: 192 | Shimmer = st.text_input('MDVP:Shimmer') 193 | 194 | with col5: 195 | Shimmer_dB = st.text_input('MDVP:Shimmer(dB)') 196 | 197 | with col1: 198 | APQ3 = st.text_input('Shimmer:APQ3') 199 | 200 | with col2: 201 | APQ5 = st.text_input('Shimmer:APQ5') 202 | 203 | with col3: 204 | APQ = st.text_input('MDVP:APQ') 205 | 206 | with col4: 207 | DDA = st.text_input('Shimmer:DDA') 208 | 209 | with col5: 210 | NHR = st.text_input('NHR') 211 | 212 | with col1: 213 | HNR = st.text_input('HNR') 214 | 215 | with col2: 216 | RPDE = st.text_input('RPDE') 217 | 218 | with col3: 219 | DFA = st.text_input('DFA') 220 | 221 | with col4: 222 | spread1 = st.text_input('spread1') 223 | 224 | with col5: 225 | spread2 = st.text_input('spread2') 226 | 227 | with col1: 228 | D2 = st.text_input('D2') 229 | 230 | with col2: 231 | PPE = st.text_input('PPE') 232 | 233 | # code for Prediction 234 | parkinsons_diagnosis = '' 235 | 236 | # creating a button for Prediction 237 | if st.button("Parkinson's Test Result"): 238 | 239 | user_input = [fo, fhi, flo, Jitter_percent, Jitter_Abs, 240 | RAP, PPQ, DDP,Shimmer, Shimmer_dB, APQ3, APQ5, 241 | APQ, DDA, NHR, HNR, RPDE, DFA, spread1, spread2, D2, PPE] 242 | 243 | user_input = [float(x) for x in user_input] 244 | 245 | parkinsons_prediction = parkinsons_model.predict([user_input]) 246 | 247 | if parkinsons_prediction[0] == 1: 248 | parkinsons_diagnosis = "The person has Parkinson's disease" 249 | else: 250 | parkinsons_diagnosis = "The person does not have Parkinson's disease" 251 | 252 | st.success(parkinsons_diagnosis) 253 | 254 | ## Mutiple disease prediction stystem - Parkinson's.ipynp 255 | 256 | Importing the Dependencies 257 | import numpy as np 258 | import pandas as pd 259 | from sklearn.model_selection import train_test_split 260 | from sklearn import svm 261 | from sklearn.metrics import accuracy_score 262 | Data Collection & Analysis 263 | ### loading the data from csv file to a Pandas DataFrame 264 | parkinsons_data = pd.read_csv('/content/parkinsons.csv') 265 | ### printing the first 5 rows of the dataframe 266 | parkinsons_data.head() 267 | ### number of rows and columns in the dataframe 268 | parkinsons_data.shape 269 | ### getting more information about the dataset 270 | parkinsons_data.info() 271 | ### checking for missing values in each column 272 | parkinsons_data.isnull().sum() 273 | ### getting some statistical measures about the data 274 | parkinsons_data.describe() 275 | ### distribution of target Variable 276 | parkinsons_data['status'].value_counts() 277 | 1 --> Parkinson's Positive 278 | 279 | 0 --> Healthy 280 | 281 | ### grouping the data bas3ed on the target variable 282 | parkinsons_data.groupby('status').mean() 283 | Data Pre-Processing 284 | Separating the features & Target 285 | X = parkinsons_data.drop(columns=['name','status'], axis=1) 286 | Y = parkinsons_data['status'] 287 | print(X) 288 | print(Y) 289 | Splitting the data to training data & Test data 290 | X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=2) 291 | print(X.shape, X_train.shape, X_test.shape) 292 | Model Training 293 | Support Vector Machine Model 294 | model = svm.SVC(kernel='linear') 295 | ### training the SVM model with training data 296 | model.fit(X_train, Y_train) 297 | Model Evaluation 298 | Accuracy Score 299 | ### accuracy score on training data 300 | X_train_prediction = model.predict(X_train) 301 | training_data_accuracy = accuracy_score(Y_train, X_train_prediction) 302 | print('Accuracy score of training data : ', training_data_accuracy) 303 | ### accuracy score on training data 304 | X_test_prediction = model.predict(X_test) 305 | test_data_accuracy = accuracy_score(Y_test, X_test_prediction) 306 | print('Accuracy score of test data : ', test_data_accuracy) 307 | Building a Predictive System 308 | input_data = (197.07600,206.89600,192.05500,0.00289,0.00001,0.00166,0.00168,0.00498,0.01098,0.09700,0.00563,0.00680,0.00802,0.01689,0.00339,26.77500,0.422229,0.741367,-7.348300,0.177551,1.743867,0.085569) 309 | 310 | ### changing input data to a numpy array 311 | input_data_as_numpy_array = np.asarray(input_data) 312 | 313 | ### reshape the numpy array 314 | input_data_reshaped = input_data_as_numpy_array.reshape(1,-1) 315 | 316 | prediction = model.predict(input_data_reshaped) 317 | print(prediction) 318 | 319 | 320 | if (prediction[0] == 0): 321 | print("The Person does not have Parkinsons Disease") 322 | 323 | else: 324 | print("The Person has Parkinsons") 325 | 326 | Saving the trained model 327 | import pickle 328 | filename = 'parkinsons_model.sav' 329 | pickle.dump(model, open(filename, 'wb')) 330 | ### loading the saved model 331 | loaded_model = pickle.load(open('parkinsons_model.sav', 'rb')) 332 | for column in X.columns: 333 | print(column) 334 | 335 | ## Mutiple disease prediction stystem - Heart disease.ipynp 336 | 337 | Importing the Dependencies 338 | import numpy as np 339 | import pandas as pd 340 | from sklearn.model_selection import train_test_split 341 | from sklearn.linear_model import LogisticRegression 342 | from sklearn.metrics import accuracy_score 343 | Data Collection and Processing 344 | ### loading the csv data to a Pandas DataFrame 345 | heart_data = pd.read_csv('/content/heart.csv') 346 | ### print first 5 rows of the dataset 347 | heart_data.head() 348 | ### print last 5 rows of the dataset 349 | heart_data.tail() 350 | ### number of rows and columns in the dataset 351 | heart_data.shape 352 | ### getting some info about the data 353 | heart_data.info() 354 | ### checking for missing values 355 | heart_data.isnull().sum() 356 | ### statistical measures about the data 357 | heart_data.describe() 358 | ### checking the distribution of Target Variable 359 | heart_data['target'].value_counts() 360 | 1 --> Defective Heart 361 | 362 | 0 --> Healthy Heart 363 | Splitting the Features and Target 364 | X = heart_data.drop(columns='target', axis=1) 365 | Y = heart_data['target'] 366 | print(X) 367 | print(Y) 368 | Splitting the Data into Training data & Test Data 369 | X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, stratify=Y, random_state=2) 370 | print(X.shape, X_train.shape, X_test.shape) 371 | Model Training 372 | Logistic Regression 373 | model = LogisticRegression() 374 | ### training the LogisticRegression model with Training data 375 | model.fit(X_train, Y_train) 376 | Model Evaluation 377 | Accuracy Score 378 | ### accuracy on training data 379 | X_train_prediction = model.predict(X_train) 380 | training_data_accuracy = accuracy_score(X_train_prediction, Y_train) 381 | print('Accuracy on Training data : ', training_data_accuracy) 382 | ### accuracy on test data 383 | X_test_prediction = model.predict(X_test) 384 | test_data_accuracy = accuracy_score(X_test_prediction, Y_test) 385 | print('Accuracy on Test data : ', test_data_accuracy) 386 | Building a Predictive System 387 | input_data = (62,0,0,140,268,0,0,160,0,3.6,0,2,2) 388 | 389 | ### change the input data to a numpy array 390 | input_data_as_numpy_array= np.asarray(input_data) 391 | 392 | ### reshape the numpy array as we are predicting for only on instance 393 | input_data_reshaped = input_data_as_numpy_array.reshape(1,-1) 394 | 395 | prediction = model.predict(input_data_reshaped) 396 | print(prediction) 397 | 398 | if (prediction[0]== 0): 399 | print('The Person does not have a Heart Disease') 400 | else: 401 | print('The Person has Heart Disease') 402 | Saving the trained model 403 | import pickle 404 | filename = 'heart_disease_model.sav' 405 | pickle.dump(model, open(filename, 'wb')) 406 | ### loading the saved model 407 | loaded_model = pickle.load(open('heart_disease_model.sav', 'rb')) 408 | for column in X.columns: 409 | print(column) 410 | --------------------------------------------------------------------------------