-
Notifications
You must be signed in to change notification settings - Fork 8
/
data_analysis.py
159 lines (101 loc) · 3.69 KB
/
data_analysis.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# -*- coding: utf-8 -*-
##### Library Importation ####
import os
import seaborn as sns
import numpy as np
import scipy
import pandas as pd
from matplotlib import pyplot as plt
if not os.path.exists('./Figures'):
os.mkdir('./Figures')
#get_ipython().run_line_magic('matplotlib', 'inline')
#########################################################################
##### load training dataset ######
data = pd.read_csv('data/training_data.csv', delimiter=',')
print(data[['Resp','PR Seq','RT Seq','VL-t0', 'CD4-t0']].head())
# general information about the data
data.info()
####### Number of missing data ########
data.isnull().sum().sum()
####### Number of missing data ########
print('Missing data:')
print(data[['Resp','PR Seq','RT Seq','VL-t0', 'CD4-t0']].isnull().sum())
data_X = data[['VL-t0', 'CD4-t0']]
# descriptive statistic
data[['Resp','PR Seq','RT Seq','VL-t0', 'CD4-t0']].describe()
################ correlation matrix of data_X ############
#data[['VL-t0', 'CD4-t0']].corr()
print('Correlation Matrix \n')
data_X.corr()
# general data correlation heatmap
sns.heatmap(data[['Resp','VL-t0', 'CD4-t0']].corr(),cmap='YlGnBu')
plt.title('Correlation heatmap')
plt.savefig('./Figures/corr_matrix_plot')
############## Histogram of improving '1' of responds after 16 weeks of therapy #################
data['Resp'].hist()
#data["Resp"].value_counts().plot.pie()
#plt.ylabel("nb patient")
#plt.xlabel("improve 1 or not 0")
plt.title('Pie Plot of Class 0 and 1: 0 = no improvement')
plt.savefig('./Figures/imbalanced_plot')
N,D = data.shape
first_pct = np.sum(data.iloc[:,1] == 0)/N
second_pct = np.sum(data.iloc[:,1] == 1)/N
print('First Class precentage: %{:2f}'.format(100*first_pct))
print('Second Class precentage: %{:2f}'.format(100*second_pct))
# group the data by the target variable
data_grp= data[['Resp','VL-t0', 'CD4-t0']].groupby('Resp')
# general descriptive per-class
data_grp.describe()
##################################### Class 0: no improvement ###################################################
class_0 = data[data['Resp']==0]
class_0_X = class_0[['VL-t0','CD4-t0']]
# print('Class 0')
# class_0_X.describe()
#### Correlation matrix of class 0
print('Class 0')
class_0_X.corr()
######## CD4+ count histogram: class 0
class_0_X['CD4-t0'].hist()
plt.ylabel('Effective')
plt.xlabel('CD4+ count')
plt.title('Class 0: no improvement')
plt.savefig('./Figures/Class0_origin_data_CD4')
###### VL-t0 histogram
class_0_X['VL-t0'].hist()
plt.ylabel('Effective')
plt.xlabel('viral load')
plt.title('Class 0: no improvement')
plt.savefig('./Figures/Class0_origin_data_VL')
############################ Class 1: Improvement ##################################################
class_1 = data[data['Resp']==1]
class_1_X = class_1[['VL-t0','CD4-t0']]
# print('Class 1')
# class_1_X.describe()
######## Correlation matrix of class 1
print('Class 1')
class_1_X.corr()
###### CD4+ count histogram
class_1_X['CD4-t0'].hist()
plt.ylabel('Effective')
plt.xlabel('CD4+ count')
plt.title('Class 1: improvement')
plt.savefig('./Figures/Class0_origin_data_CD4')
###### VL-t0 histogram
class_1_X['VL-t0'].hist()
plt.ylabel('Effective')
plt.xlabel('viral load')
plt.title('Class 1: improvement')
plt.savefig('./Figures/Class1_origin_data_VL')
########################## Plotting ##########################
############## plotting of viral load "VL-t0" (all ) #################
data_grp['VL-t0'].plot()
plt.xlabel("nb patient")
plt.ylabel("viral load")
###### save figure, format '.png'
plt.savefig('./Figures/viral_load_plot.png')
############## plotting of absolute CD4 count "CD4-t0" #################
data_grp['CD4-t0'].plot()
plt.axhline(500, 0, 1002, color='r')
plt.xlabel("nb patient")
plt.ylabel("CD4+ count")