Multiple disease prediction system - Parkinsons
Multi-disease system එක සම්පූර්ණ කරන, තෙවෙනි disease module එක — දැන් වෙනකොට deployment pattern එක, classifier ඕනම එකකට run කරන්න පුළුවන් checklist එකක් වගේ දැනිය යුතුයි.
The third disease module, completing the multi-disease system — by now the deployment pattern should feel like a checklist you can run on almost any classifier.
Lesson 56 of 64 · Part 5 · Shipping Models to the World · Multiple Disease Prediction System · bilingual notes (English + සිංහල)
Why this matters. The third disease module, completing the multi-disease system — by now the deployment pattern should feel like a checklist you can run on almost any classifier.
සිංහලෙන්: Multi-disease system එක සම්පූර්ණ කරන, තෙවෙනි disease module එක — දැන් වෙනකොට deployment pattern එක, classifier ඕනම එකකට run කරන්න පුළුවන් checklist එකක් වගේ දැනිය යුතුයි.
What you'll use this for. Voice and movement-pattern features (used for Parkinson's detection) show that this exact same pipeline works regardless of what the input data actually represents.
සිංහලෙන්: Parkinson's detection එකට පාවිච්චි කරන voice සහ movement-pattern features වලින් පේනවා, input data එකෙන් ඇත්තටම නියෝජනය කරන්නෙ මොකක් උනත් මේ එකම pipeline එක වැඩ කරනවා කියලා.
Key principles
- A generalizable pipeline is judged by how little changes between projects, not how much. If deploying this model needed a completely different app structure from the diabetes one, that would be a sign your first design wasn't actually reusable.
Generalize වෙන pipeline එකක්, projects අතර වෙනස් වෙන්නෙ අඩුවෙන් තරමින් judge වෙනවා, වැඩියෙන් නෙවෙයි
Walkthrough
Importing the Dependencies
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import svm
from sklearn.metrics import accuracy_scoreData Collection & Analysis
# loading the data from csv file to a Pandas DataFrame
parkinsons_data = pd.read_csv('/content/parkinsons.csv')# printing the first 5 rows of the dataframe
parkinsons_data.head()| name | MDVP:Fo(Hz) | MDVP:Fhi(Hz) | MDVP:Flo(Hz) | MDVP:Jitter(%) | MDVP:Jitter(Abs) | MDVP:RAP | … | |
|---|---|---|---|---|---|---|---|---|
| 0 | phon_R01_S01_1 | 119.992 | 157.302 | 74.997 | 0.00784 | 0.00007 | 0.00370 | … |
| 1 | phon_R01_S01_2 | 122.400 | 148.650 | 113.819 | 0.00968 | 0.00008 | 0.00465 | … |
| 2 | phon_R01_S01_3 | 116.682 | 131.111 | 111.555 | 0.01050 | 0.00009 | 0.00544 | … |
| 3 | phon_R01_S01_4 | 116.676 | 137.871 | 111.366 | 0.00997 | 0.00009 | 0.00502 | … |
| 4 | phon_R01_S01_5 | 116.014 | 141.781 | 110.655 | 0.01284 | 0.00011 | 0.00655 | … |
# number of rows and columns in the dataframe
parkinsons_data.shapeOutput
(195, 24)# getting more information about the dataset
parkinsons_data.info()Output
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 195 entries, 0 to 194
Data columns (total 24 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 name 195 non-null object
1 MDVP:Fo(Hz) 195 non-null float64
2 MDVP:Fhi(Hz) 195 non-null float64
3 MDVP:Flo(Hz) 195 non-null float64
4 MDVP:Jitter(%) 195 non-null float64
5 MDVP:Jitter(Abs) 195 non-null float64
6 MDVP:RAP 195 non-null float64
7 MDVP:PPQ 195 non-null float64
8 Jitter:DDP 195 non-null float64
9 MDVP:Shimmer 195 non-null float64
10 MDVP:Shimmer(dB) 195 non-null float64
11 Shimmer:APQ3 195 non-null float64
12 Shimmer:APQ5 195 non-null float64
… (13 more lines)# checking for missing values in each column
parkinsons_data.isnull().sum()Output
name 0
MDVP:Fo(Hz) 0
MDVP:Fhi(Hz) 0
MDVP:Flo(Hz) 0
MDVP:Jitter(%) 0
MDVP:Jitter(Abs) 0
MDVP:RAP 0
MDVP:PPQ 0
Jitter:DDP 0
MDVP:Shimmer 0
MDVP:Shimmer(dB) 0
Shimmer:APQ3 0
Shimmer:APQ5 0
MDVP:APQ 0
Shimmer:DDA 0
NHR 0
HNR 0
status 0
… (7 more lines)# getting some statistical measures about the data
parkinsons_data.describe()| MDVP:Fo(Hz) | MDVP:Fhi(Hz) | MDVP:Flo(Hz) | MDVP:Jitter(%) | MDVP:Jitter(Abs) | MDVP:RAP | MDVP:PPQ | … | |
|---|---|---|---|---|---|---|---|---|
| count | 195.000000 | 195.000000 | 195.000000 | 195.000000 | 195.000000 | 195.000000 | 195.000000 | … |
| mean | 154.228641 | 197.104918 | 116.324631 | 0.006220 | 0.000044 | 0.003306 | 0.003446 | … |
| std | 41.390065 | 91.491548 | 43.521413 | 0.004848 | 0.000035 | 0.002968 | 0.002759 | … |
| min | 88.333000 | 102.145000 | 65.476000 | 0.001680 | 0.000007 | 0.000680 | 0.000920 | … |
| 25% | 117.572000 | 134.862500 | 84.291000 | 0.003460 | 0.000020 | 0.001660 | 0.001860 | … |
| 50% | 148.790000 | 175.829000 | 104.315000 | 0.004940 | 0.000030 | 0.002500 | 0.002690 | … |
… 2 more rows
# distribution of target Variable
parkinsons_data['status'].value_counts()Output
1 147
0 48
Name: status, dtype: int641 --> Parkinson's Positive
0 --> Healthy
# grouping the data bas3ed on the target variable
parkinsons_data.groupby('status').mean()| MDVP:Fo(Hz) | MDVP:Fhi(Hz) | MDVP:Flo(Hz) | MDVP:Jitter(%) | MDVP:Jitter(Abs) | MDVP:RAP | MDVP:PPQ | … | |
|---|---|---|---|---|---|---|---|---|
| status | … | |||||||
| 0 | 181.937771 | 223.636750 | 145.207292 | 0.003866 | 0.000023 | 0.001925 | 0.002056 | … |
| 1 | 145.180762 | 188.441463 | 106.893558 | 0.006989 | 0.000051 | 0.003757 | 0.003900 | … |
Data Pre-Processing
Separating the features & Target
X = parkinsons_data.drop(columns=['name','status'], axis=1)
Y = parkinsons_data['status']print(X)Output
MDVP:Fo(Hz) MDVP:Fhi(Hz) MDVP:Flo(Hz) MDVP:Jitter(%) \
0 119.992 157.302 74.997 0.00784
1 122.400 148.650 113.819 0.00968
2 116.682 131.111 111.555 0.01050
3 116.676 137.871 111.366 0.00997
4 116.014 141.781 110.655 0.01284
.. ... ... ... ...
190 174.188 230.978 94.261 0.00459
191 209.516 253.017 89.488 0.00564
192 174.688 240.005 74.287 0.01360
193 198.764 396.961 74.904 0.00740
194 214.289 260.277 77.973 0.00567
MDVP:Jitter(Abs) MDVP:RAP MDVP:PPQ Jitter:DDP MDVP:Shimmer \
0 0.00007 0.00370 0.00554 0.01109 0.04374
1 0.00008 0.00465 0.00696 0.01394 0.06134
2 0.00009 0.00544 0.00781 0.01633 0.05233
3 0.00009 0.00502 0.00698 0.01505 0.05492
… (35 more lines)print(Y)Output
0 1
1 1
2 1
3 1
4 1
..
190 0
191 0
192 0
193 0
194 0
Name: status, Length: 195, dtype: int64Splitting the data to training data & Test data
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=2)print(X.shape, X_train.shape, X_test.shape)Output
(195, 22) (156, 22) (39, 22)Model Training
Support Vector Machine Model
model = svm.SVC(kernel='linear')# training the SVM model with training data
model.fit(X_train, Y_train)Output
SVC(kernel='linear')Model Evaluation
Accuracy Score
# accuracy score on training data
X_train_prediction = model.predict(X_train)
training_data_accuracy = accuracy_score(Y_train, X_train_prediction)print('Accuracy score of training data : ', training_data_accuracy)Output
Accuracy score of training data : 0.8717948717948718# accuracy score on training data
X_test_prediction = model.predict(X_test)
test_data_accuracy = accuracy_score(Y_test, X_test_prediction)print('Accuracy score of test data : ', test_data_accuracy)Output
Accuracy score of test data : 0.8717948717948718Building a Predictive System
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)
# changing input data to a numpy array
input_data_as_numpy_array = np.asarray(input_data)
# reshape the numpy array
input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
prediction = model.predict(input_data_reshaped)
print(prediction)
if (prediction[0] == 0):
print("The Person does not have Parkinsons Disease")
else:
print("The Person has Parkinsons")Output
[0]
The Person does not have Parkinsons DiseaseOutput
/usr/local/lib/python3.7/dist-packages/sklearn/base.py:451: UserWarning: X does not have valid feature names, but SVC was fitted with feature names
"X does not have valid feature names, but"Saving the trained model
import picklefilename = 'parkinsons_model.sav'
pickle.dump(model, open(filename, 'wb'))# loading the saved model
loaded_model = pickle.load(open('parkinsons_model.sav', 'rb'))for column in X.columns:
print(column)Output
MDVP:Fo(Hz)
MDVP:Fhi(Hz)
MDVP:Flo(Hz)
MDVP:Jitter(%)
MDVP:Jitter(Abs)
MDVP:RAP
MDVP:PPQ
Jitter:DDP
MDVP:Shimmer
MDVP:Shimmer(dB)
Shimmer:APQ3
Shimmer:APQ5
MDVP:APQ
Shimmer:DDA
NHR
HNR
RPDE
DFA
… (4 more lines)Keep going: ← Lesson 55 · Lesson 57 → · Track it in the Self Guide
Finished this one?
Part of Self Guide · Stage 17: ML 5 — Shipping Models to the World. Progress is saved in this browser.



