[d2c46b]: / 13-Adversarial validation.R

Download this file

192 lines (184 with data), 12.1 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
 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#train for Adversarial validation
{
setwd("E:/workplace/mywork/methy/dbgap/chf/data_chf_contr/early_chf/c1_UMN_JHU/train_UMN_tset_JHU/1123_dataSummary/")
{
load(file="train_meta_raw.Rdata")
train_meta = train_meta_raw[,!colnames(train_meta_raw) %in% c("PACKS_SET","Omega3amount","Statinamount","Thiazidesamount","Diureticamount",
"Potassiumamount" , "Aldosteroneamount" , "Amiodaroneamount",
"Vasodilatorsamount","CoQ10amount","Betablockingamount",
"AngiotensinIIantagonistsamount", "ACEIamount" , "Warfarinamount" ,
"Clopidogrelamount" , "Aspirinamount" , "Folicacidamount" ,"chddate" ,
"chfdate" ,"cvddate" ,"midate" ,"afxdate" ,"strokedate" ,"DATE8","lvh","cvd",
"DATE9","aspirin.1","other_heart","other_peripheral_vascular_disease",
"other_vascular_diagnosis","other","other2","pneumonia.1","emphysema.1")]
train_meta = train_meta[,-c(1,2)]
train_meta <- train_meta[,!colnames(train_meta) %in% c("Numberofcigarettessmoked")]
train_meta <- train_meta[,!colnames(train_meta) %in% c("Heartfailure")]
train_meta <- train_meta[,!colnames(train_meta) %in% c("Diabetes")]
train_meta <- train_meta[,!colnames(train_meta) %in% c("Rightventricularhypertrophy")]
library(tibble)
library(impute)
Patient_impute <- impute.knn(as.matrix(data.frame(t(train_meta))))
Patient_impute <- data.frame(t(Patient_impute$data))
for(i in c("LDLcholesterol","Fastingbloodglucose","Atrialenlargement","Leftventricularhypertrophy",
"Neurological","Gidisease","Infectious",
"Fever","Chronicbronchitis","COPD")){
Patient_impute[,i] <- round(Patient_impute[,i],0)
}
for(i in c("BMI","Waist","Albuminurine","Creactiveprotein","Hight")){
Patient_impute[,i] <- round(Patient_impute[,i],2)
}
Patient_impute <- Patient_impute[,-c(88:93)]
}
X <- data.frame(Patient_impute)
write.table(X,"D:\\anaconda-python\\learn_DL\\Basic-DeepFM-model\\data\\20210819deepfm_feature_AdversarialValidation1.csv",row.names = F,sep=",")
}
#test for Adversarial validation
{
setwd("E:/workplace/mywork/methy/dbgap/chf/data_chf_contr/early_chf/c1_UMN_JHU/train_UMN_tset_JHU/1123_dataSummary/")
{
load(file="test/test_meta_raw.Rdata")
test_meta = test_meta_raw[,!colnames(test_meta_raw) %in% c("PACKS_SET","Omega3amount","Statinamount","Thiazidesamount","Diureticamount",
"Potassiumamount" , "Aldosteroneamount" , "Amiodaroneamount",
"Vasodilatorsamount","CoQ10amount","Betablockingamount",
"AngiotensinIIantagonistsamount", "ACEIamount" , "Warfarinamount" ,
"Clopidogrelamount" , "Aspirinamount" , "Folicacidamount" ,"chddate" ,
"chfdate" ,"cvddate" ,"midate" ,"afxdate" ,"strokedate" ,"DATE8","lvh","cvd",
"DATE9","aspirin.1","other_heart","other_peripheral_vascular_disease",
"other_vascular_diagnosis","other","other2","pneumonia.1","emphysema.1")]
test_meta = test_meta[,-c(1,2)]
test_meta <- test_meta[,!colnames(test_meta) %in% c("Numberofcigarettessmoked")]
test_meta <- test_meta[,!colnames(test_meta) %in% c("Heartfailure")]
test_meta <- test_meta[,!colnames(test_meta) %in% c("Diabetes")]
test_meta <- test_meta[,!colnames(test_meta) %in% c("Rightventricularhypertrophy")]
library(tibble)
library(impute)
Patient_impute <- impute.knn(as.matrix(data.frame(t(test_meta))))
Patient_impute <- data.frame(t(Patient_impute$data))
for(i in c("LDLcholesterol","Fastingbloodglucose","Atrialenlargement","Leftventricularhypertrophy",
"Neurological","Gidisease","Infectious",
"Fever","Chronicbronchitis","COPD",
"Treatedforlipids","Drinkwine")){
Patient_impute[,i] <- round(Patient_impute[,i],0)
}
for(i in c("BMI","Waist","Albuminurine","Creactiveprotein","Hight")){
Patient_impute[,i] <- round(Patient_impute[,i],2)
}
Patient_impute <- Patient_impute[,-c(88:93)]
}
X <- data.frame(Patient_impute)
write.table(X,"D:\\anaconda-python\\learn_DL\\Basic-DeepFM-model\\data\\20210819deepfm_feature_AdversarialValidation1_test.csv",row.names = F,sep=",")
}
#train
{
setwd("E:/workplace/mywork/methy/dbgap/chf/data_chf_contr/early_chf/c1_UMN_JHU/train_UMN_tset_JHU/1123_dataSummary")
load("tmp_train.Rdata")#90 ehr impute after
data = Patient_impute[,-c(1:3)]
X <- data.frame(data)
X = X[,-c(92:97)]#"CD8T" "CD4T" "NK" "Bcell" "Mono" "Gran"
write.table(X,"D:\\anaconda-python\\learn_DL\\Basic-DeepFM-model\\data\\20210819deepfm_feature_AdversarialValidation2.csv",row.names = F,sep=",")
}
#test
{
setwd("E:/workplace/mywork/methy/dbgap/chf/data_chf_contr/early_chf/c1_UMN_JHU/train_UMN_tset_JHU/1123_dataSummary")
load("tmp_test.Rdata")
data = Patient_impute_test[,-c(1:3)]
X <- data.frame(data)
X = X[,-c(92:97)]#"CD8T" "CD4T" "NK" "Bcell" "Mono" "Gran"
write.table(X,"D:\\anaconda-python\\learn_DL\\Basic-DeepFM-model\\data\\20210819deepfm_feature_AdversarialValidation2_test.csv",row.names = F,sep=",")
}
#train
{
setwd("E:/workplace/mywork/methy/dbgap/chf/data_chf_contr/early_chf/c1_UMN_JHU/train_UMN_tset_JHU/1123_dataSummary")
load("tmp_train.Rdata")#90 ehr impute after
data = Patient_impute[,-c(1:3)]
X <- data.frame(data)
X = X[,-c(92:97)]#"CD8T" "CD4T" "NK" "Bcell" "Mono" "Gran"
set.seed(1234)
samp=sample(1:nrow(X),171)
X=X[samp,]
write.table(X,"D:\\anaconda-python\\learn_DL\\Basic-DeepFM-model\\data\\20210819deepfm_feature_AdversarialValidation3.csv",row.names = F,sep=",")
}
#test
{
setwd("E:/workplace/mywork/methy/dbgap/chf/data_chf_contr/early_chf/c1_UMN_JHU/train_UMN_tset_JHU/1123_dataSummary")
load("tmp_test.Rdata")
data = Patient_impute_test[,-c(1:3)]
X <- data.frame(data)
X = X[,-c(92:97)]#"CD8T" "CD4T" "NK" "Bcell" "Mono" "Gran"
write.table(X,"D:\\anaconda-python\\learn_DL\\Basic-DeepFM-model\\data\\20210819deepfm_feature_AdversarialValidation3_test.csv",row.names = F,sep=",")
}
#train for Adversarial validation
{
setwd("E:/workplace/mywork/methy/dbgap/chf/data_chf_contr/early_chf/c1_UMN_JHU/train_UMN_tset_JHU/1123_dataSummary/")
{
load(file="train_meta_raw.Rdata")
train_meta = train_meta_raw[,!colnames(train_meta_raw) %in% c("PACKS_SET","Omega3amount","Statinamount","Thiazidesamount","Diureticamount",
"Potassiumamount" , "Aldosteroneamount" , "Amiodaroneamount",
"Vasodilatorsamount","CoQ10amount","Betablockingamount",
"AngiotensinIIantagonistsamount", "ACEIamount" , "Warfarinamount" ,
"Clopidogrelamount" , "Aspirinamount" , "Folicacidamount" ,"chddate" ,
"chfdate" ,"cvddate" ,"midate" ,"afxdate" ,"strokedate" ,"DATE8","lvh","cvd",
"DATE9","aspirin.1","other_heart","other_peripheral_vascular_disease",
"other_vascular_diagnosis","other","other2","pneumonia.1","emphysema.1")]
train_meta = train_meta[,-c(1,2)]
train_meta <- train_meta[,!colnames(train_meta) %in% c("Numberofcigarettessmoked")]
train_meta <- train_meta[,!colnames(train_meta) %in% c("Heartfailure")]
train_meta <- train_meta[,!colnames(train_meta) %in% c("Diabetes")]
train_meta <- train_meta[,!colnames(train_meta) %in% c("Rightventricularhypertrophy")]
library(tibble)
library(impute)
Patient_impute <- impute.knn(as.matrix(data.frame(t(train_meta))))
Patient_impute <- data.frame(t(Patient_impute$data))
for(i in c("LDLcholesterol","Fastingbloodglucose","Atrialenlargement","Leftventricularhypertrophy",
"Neurological","Gidisease","Infectious",
"Fever","Chronicbronchitis","COPD")){
Patient_impute[,i] <- round(Patient_impute[,i],0)
}
for(i in c("BMI","Waist","Albuminurine","Creactiveprotein","Hight")){
Patient_impute[,i] <- round(Patient_impute[,i],2)
}
Patient_impute <- Patient_impute[,-c(88:93)]
}
X <- data.frame(Patient_impute)
set.seed(1234)
samp=sample(1:nrow(X),171)
X=X[samp,]
write.table(X,"D:\\anaconda-python\\learn_DL\\Basic-DeepFM-model\\data\\20210819deepfm_feature_AdversarialValidation4.csv",row.names = F,sep=",")
}
#test for Adversarial validation
{
setwd("E:/workplace/mywork/methy/dbgap/chf/data_chf_contr/early_chf/c1_UMN_JHU/train_UMN_tset_JHU/1123_dataSummary/")
{
load(file="test/test_meta_raw.Rdata")
test_meta = test_meta_raw[,!colnames(test_meta_raw) %in% c("PACKS_SET","Omega3amount","Statinamount","Thiazidesamount","Diureticamount",
"Potassiumamount" , "Aldosteroneamount" , "Amiodaroneamount",
"Vasodilatorsamount","CoQ10amount","Betablockingamount",
"AngiotensinIIantagonistsamount", "ACEIamount" , "Warfarinamount" ,
"Clopidogrelamount" , "Aspirinamount" , "Folicacidamount" ,"chddate" ,
"chfdate" ,"cvddate" ,"midate" ,"afxdate" ,"strokedate" ,"DATE8","lvh","cvd",
"DATE9","aspirin.1","other_heart","other_peripheral_vascular_disease",
"other_vascular_diagnosis","other","other2","pneumonia.1","emphysema.1")]
test_meta = test_meta[,-c(1,2)]
test_meta <- test_meta[,!colnames(test_meta) %in% c("Numberofcigarettessmoked")]
test_meta <- test_meta[,!colnames(test_meta) %in% c("Heartfailure")]
test_meta <- test_meta[,!colnames(test_meta) %in% c("Diabetes")]
test_meta <- test_meta[,!colnames(test_meta) %in% c("Rightventricularhypertrophy")]
library(tibble)
library(impute)
Patient_impute <- impute.knn(as.matrix(data.frame(t(test_meta))))
Patient_impute <- data.frame(t(Patient_impute$data))
for(i in c("LDLcholesterol","Fastingbloodglucose","Atrialenlargement","Leftventricularhypertrophy",
"Neurological","Gidisease","Infectious",
"Fever","Chronicbronchitis","COPD",
"Treatedforlipids","Drinkwine")){
Patient_impute[,i] <- round(Patient_impute[,i],0)
}
for(i in c("BMI","Waist","Albuminurine","Creactiveprotein","Hight")){
Patient_impute[,i] <- round(Patient_impute[,i],2)
}
Patient_impute <- Patient_impute[,-c(88:93)]
}
X <- data.frame(Patient_impute)
write.table(X,"D:\\anaconda-python\\learn_DL\\Basic-DeepFM-model\\data\\20210819deepfm_feature_AdversarialValidation4_test.csv",row.names = F,sep=",")
}