def _update_metrics(self, y_true, y_pred,
onco_prob, tsg_prob):
# record which genes were predicted what
self.driver_gene_pred = pd.Series(y_pred, self.y.index)
self.driver_gene_score = pd.Series(onco_prob+tsg_prob, self.y.index)
# evaluate performance
prec, recall, fscore, support = metrics.precision_recall_fscore_support(y_true, y_pred,
average='macro')
cancer_gene_pred = ((onco_prob + tsg_prob)>.5).astype(int)
self.cancer_gene_count[self.num_pred] = np.sum(cancer_gene_pred)
self.precision[self.num_pred] = prec
self.recall[self.num_pred] = recall
self.f1_score[self.num_pred] = fscore
# compute Precision-Recall curve metrics
driver_prob = onco_prob + tsg_prob
driver_true = (y_true > 0).astype(int)
p, r, thresh = metrics.precision_recall_curve(driver_true, driver_prob)
p, r, thresh = p[::-1], r[::-1], thresh[::-1] # reverse order of results
thresh = np.insert(thresh, 0, 1.0)
self.driver_precision_array[self.num_pred, :] = interp(self.driver_recall_array, r, p)
self.driver_threshold_array[self.num_pred, :] = interp(self.driver_recall_array, r, thresh)
# calculate prediction summary statistics
prec, recall, fscore, support = metrics.precision_recall_fscore_support(driver_true, cancer_gene_pred)
self.driver_precision[self.num_pred] = prec[1]
self.driver_recall[self.num_pred] = recall[1]
# save driver metrics
fpr, tpr, thresholds = metrics.roc_curve(driver_true, driver_prob)
self.driver_tpr_array[self.num_pred, :] = interp(self.driver_fpr_array, fpr, tpr)
评论列表
文章目录