1
+ #Logistic Regression
2
+ #importing the required packages
3
+ import numpy as np
4
+ import pandas as pd
5
+ from matplotlib import pyplot as plt
6
+ from sklearn .model_selection import train_test_split
7
+ from sklearn .preprocessing import StandardScaler
8
+ from sklearn .preprocessing import MinMaxScaler
9
+ from sklearn .linear_model import LogisticRegression
10
+ from sklearn .metrics import accuracy_score
11
+
12
+ #loading the data
13
+ dataset = pd .read_csv ('/content/drive/MyDrive/TCR/datasets/parkinsons.csv' )
14
+
15
+ dataset .head ()
16
+ dataset .shape
17
+ dataset .info ()
18
+
19
+ #checking for null values if any
20
+ dataset .isnull ().sum ()
21
+
22
+ dataset .describe ()
23
+
24
+ #EDA
25
+ dataset .status .value_counts ()
26
+ dataset ['status' ].value_counts ()
27
+ dataset .groupby ('status' ).mean ()
28
+
29
+ #dividing the data in features and target
30
+ x = dataset .drop (columns = ['name' , 'status' ], axis = 1 )
31
+ y = dataset ['status' ]
32
+
33
+ x .head ()
34
+
35
+ #test-train split
36
+ X_train , X_test , Y_train , Y_test = train_test_split (x , y , test_size = 0.10 , random_state = 2 )
37
+ print (X_train .shape , X_test .shape , Y_train .shape , Y_test .shape )
38
+
39
+ #standardising the data for better accuracy
40
+ sclaer = StandardScaler ()
41
+ sclaer .fit (X_train )
42
+ X_train = sclaer .transform (X_train )
43
+ X_test = sclaer .transform (X_test )
44
+
45
+ #logistic regression in training data
46
+ model = LogisticRegression ()
47
+ model .fit (X_train , Y_train )
48
+
49
+ #accuracy check using accuracy score
50
+ Y_pred_train = model .predict (X_train )
51
+ Y_pred_train_accuracy = accuracy_score (Y_train , Y_pred_train )
52
+ print ("Accuracy on training Data : " , Y_pred_train_accuracy )
53
+
54
+ Y_pred_test = model .predict (X_test )
55
+ Y_pred_test_accuracy = accuracy_score (Y_test , Y_pred_test )
56
+ print ("Accuracy on testing data : " , Y_pred_test_accuracy )
57
+
58
+ #testing the model with data
59
+ input_data = x [5 :6 ]
60
+ input_data_as_array = np .asarray (input_data )
61
+ input_data_reshaped = input_data_as_array .reshape (1 , - 1 )
62
+ std_scaler = sclaer .transform (input_data_reshaped )
63
+ prediction = model .predict (std_scaler )
64
+ print (prediction )
65
+ if (prediction [0 ] == 0 ):
66
+ print ("The Person doesnt have parkinson diesease" )
67
+ else :
68
+ print ("The Person is suffering from Parkinson diesease" )
69
+
70
+ #comparing the predicted value with actual value
71
+ print ("The actual value is : " , y [5 :6 ])
72
+
73
+ #This is the end of file, please ignore this comment.
0 commit comments