@@ -129,15 +129,6 @@ def find_nearest_index(array, value):
129
129
pred1_cf [i ] = surv1_cf .axes [0 ][find_nearest_index (surv1_cf .iloc [:, i ].values , death_probability )]
130
130
ITE1 = pred1 - pred1_cf
131
131
132
- correct_predicted_probability = None
133
- if best_treatment is not None :
134
- pred_best_choice0 = ((pred0 - pred0_cf ) < 0 ) * 1
135
- pred_best_choice1 = ((pred1 - pred1_cf ) > 0 ) * 1
136
- correct_predicted_probability = np .sum (np .append (best_treatment [treatment == 0 ] == pred_best_choice0 ,
137
- best_treatment [treatment == 1 ] == pred_best_choice1 )) \
138
- / (pred_best_choice0 .size + pred_best_choice1 .size )
139
- print ('Fraction best choice: ' + str (correct_predicted_probability ))
140
-
141
132
ITE = np .zeros (X .shape [0 ])
142
133
k , j = 0 , 0
143
134
for i in range (X .shape [0 ]):
@@ -148,29 +139,30 @@ def find_nearest_index(array, value):
148
139
ITE [i ] = ITE1 [j ]
149
140
j = j + 1
150
141
142
+ correct_predicted_probability = None
143
+ if best_treatment is not None :
144
+ correct_predicted_probability = np .sum (best_treatment == (ITE > 0 )* 1 )/ best_treatment .shape [0 ]
145
+ print ('Fraction best choice: ' + str (correct_predicted_probability ))
146
+
151
147
return ITE , correct_predicted_probability
152
148
153
149
def get_ITE_CFRNet (model , X , treatment , best_treatment = None ):
154
150
155
151
pred ,_ = model .predict_numpy (X , treatment )
156
152
pred_cf ,_ = model .predict_numpy (X , 1 - treatment )
157
153
158
- correct_predicted_probability = None
159
- if best_treatment is not None :
160
- pred_best_choice0 = (pred_cf [treatment == 0 ]- pred [treatment == 0 ]> 0 ) * 1
161
- pred_best_choice1 = (pred [treatment == 1 ]- pred_cf [treatment == 1 ]> 0 ) * 1
162
- correct_predicted_probability = np .sum (np .append (best_treatment [treatment == 0 ] == pred_best_choice0 ,
163
- best_treatment [treatment == 1 ] == pred_best_choice1 )) \
164
- / (pred_best_choice0 .size + pred_best_choice1 .size )
165
- print ('Fraction best choice: ' + str (correct_predicted_probability ))
166
-
167
154
ITE = np .zeros (X .shape [0 ])
168
155
for i in range (X .shape [0 ]):
169
156
if treatment [i ] == 0 :
170
157
ITE [i ] = pred_cf [i ]- pred [i ]
171
158
else :
172
159
ITE [i ] = pred [i ]- pred_cf [i ]
173
160
161
+ correct_predicted_probability = None
162
+ if best_treatment is not None :
163
+ correct_predicted_probability = np .sum (best_treatment == (ITE > 0 )* 1 )/ best_treatment .shape [0 ]
164
+ print ('Fraction best choice: ' + str (correct_predicted_probability ))
165
+
174
166
return ITE , correct_predicted_probability
175
167
176
168
@@ -206,15 +198,6 @@ def find_nearest_index(array, value):
206
198
pred1_cf [i ] = surv1_cf .axes [0 ][find_nearest_index (surv1_cf .iloc [:, i ].values , death_probability )]
207
199
ITE1 = pred1 - pred1_cf
208
200
209
- correct_predicted_probability = None
210
- if best_treatment is not None :
211
- pred_best_choice0 = ((pred0 - pred0_cf ) < 0 ) * 1
212
- pred_best_choice1 = ((pred1 - pred1_cf ) > 0 ) * 1
213
- correct_predicted_probability = np .sum (np .append (best_treatment [treatment == 0 ] == pred_best_choice0 ,
214
- best_treatment [treatment == 1 ] == pred_best_choice1 )) \
215
- / (pred_best_choice0 .size + pred_best_choice1 .size )
216
- print ('Fraction best choice: ' + str (correct_predicted_probability ))
217
-
218
201
ITE = np .zeros (X .shape [0 ])
219
202
k , j = 0 , 0
220
203
for i in range (X .shape [0 ]):
@@ -225,6 +208,11 @@ def find_nearest_index(array, value):
225
208
ITE [i ] = ITE1 [j ]
226
209
j = j + 1
227
210
211
+ correct_predicted_probability = None
212
+ if best_treatment is not None :
213
+ correct_predicted_probability = np .sum (best_treatment == (ITE > 0 )* 1 )/ best_treatment .shape [0 ]
214
+ print ('Fraction best choice: ' + str (correct_predicted_probability ))
215
+
228
216
return ITE , correct_predicted_probability
229
217
230
218
def get_ITE_DeepSurv (model , X , treatment , best_treatment = None , death_probability = 0.5 ):
@@ -257,15 +245,6 @@ def find_nearest_index(array, value):
257
245
pred1_cf [i ] = surv1_cf .axes [0 ][find_nearest_index (surv1_cf .iloc [:, i ].values , death_probability )]
258
246
ITE1 = pred1 - pred1_cf
259
247
260
- correct_predicted_probability = None
261
- if best_treatment is not None :
262
- pred_best_choice0 = ((pred0 - pred0_cf ) < 0 ) * 1
263
- pred_best_choice1 = ((pred1 - pred1_cf ) > 0 ) * 1
264
- correct_predicted_probability = np .sum (np .append (best_treatment [treatment == 0 ] == pred_best_choice0 ,
265
- best_treatment [treatment == 1 ] == pred_best_choice1 )) \
266
- / (pred_best_choice0 .size + pred_best_choice1 .size )
267
- print ('Fraction best choice: ' + str (correct_predicted_probability ))
268
-
269
248
ITE = np .zeros (X .shape [0 ])
270
249
k , j = 0 , 0
271
250
for i in range (X .shape [0 ]):
@@ -276,6 +255,11 @@ def find_nearest_index(array, value):
276
255
ITE [i ] = ITE1 [j ]
277
256
j = j + 1
278
257
258
+ correct_predicted_probability = None
259
+ if best_treatment is not None :
260
+ correct_predicted_probability = np .sum (best_treatment == (ITE > 0 )* 1 )/ best_treatment .shape [0 ]
261
+ print ('Fraction best choice: ' + str (correct_predicted_probability ))
262
+
279
263
return ITE , correct_predicted_probability
280
264
281
265
0 commit comments