-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualizeDiabetes.py
More file actions
76 lines (64 loc) · 2.84 KB
/
VisualizeDiabetes.py
File metadata and controls
76 lines (64 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def diabetes_bar(df):
import matplotlib
matplotlib.use('agg') # Set backend
import numpy as np
import matplotlib.pyplot as plt
## Create a series of bar plots for the various levels of the
## string columns in the data frame by readmi_class.
names = df.columns.tolist()
for col in names:
if(df[col].dtype not in [np.int64, np.int32, np.float64]):
temp1 = df.ix[df.readmitted == 'YES', col].value_counts()
temp0 = df.ix[df.readmitted == 'NO', col].value_counts()
fig = plt.figure(figsize = (12,6))
fig.clf()
ax1 = fig.add_subplot(1, 2, 1)
ax0 = fig.add_subplot(1, 2, 2)
temp1.plot(kind = 'bar', ax = ax1)
ax1.set_title('Values of ' + col + '\n for readmitted patients')
temp0.plot(kind = 'bar', ax = ax0)
ax0.set_title('Values of ' + col + '\n for patients not readmitted')
fig.savefig('bar_' + col + '.png')
return 'Done'
def diabetes_box(df):
import matplotlib
matplotlib.use('agg') # Set backend
import numpy as np
import matplotlib.pyplot as plt
## Now make some box plots of the columbns with numerical values.
names = df.columns.tolist()
for col in names:
if(df[col].dtype in [np.int64, np.int32, np.float64]):
temp1 = df.ix[df.readmitted == 'YES', col]
temp0 = df.ix[df.readmitted == 'NO', col]
fig = plt.figure(figsize = (12,6))
fig.clf()
ax1 = fig.add_subplot(1, 2, 1)
ax0 = fig.add_subplot(1, 2, 2)
ax1.boxplot(temp1.as_matrix())
ax1.set_title('Box plot of ' + col + '\n for readmitted patients')
ax0.boxplot(temp0.as_matrix())
ax0.set_title('Box plot of ' + col + '\n for patients not readmitted')
fig.savefig('box_' + col + '.png')
return 'Done'
def diabetes_hist(df):
import matplotlib
matplotlib.use('agg') # Set backend
import numpy as np
import matplotlib.pyplot as plt
## Now make historgrams of the columbns with numerical values.
names = df.columns.tolist()
for col in names:
if(df[col].dtype in [np.int64, np.int32, np.float64]):
temp1 = df.ix[df.readmitted == 'YES', col]
temp0 = df.ix[df.readmitted == 'NO', col]
fig = plt.figure(figsize = (12,6))
fig.clf()
ax1 = fig.add_subplot(1, 2, 1)
ax0 = fig.add_subplot(1, 2, 2)
ax1.hist(temp1.as_matrix(), bins = 30)
ax1.set_title('Histogram of ' + col + '\n for readmitted patients')
ax0.hist(temp0.as_matrix(), bins = 30)
ax0.set_title('Histogram of ' + col + '\n for patients not readmitted')
fig.savefig('hist_' + col + '.png')
return 'Done'