def confusion_matrix(self, pos_label=None, cutoff: float = 0.5):
     pos_label = self.classes[1] if (
         pos_label == None and len(self.classes) == 2) else pos_label
     if (pos_label in self.classes and cutoff < 1 and cutoff > 0):
         input_relation = self.deploySQL(
         ) + " WHERE predict_knc = '{}'".format(pos_label)
         y_score = "(CASE WHEN proba_predict > {} THEN 1 ELSE 0 END)".format(
             cutoff)
         y_true = "DECODE({}, '{}', 1, 0)".format(self.y, pos_label)
         result = confusion_matrix(y_true, y_score, input_relation,
                                   self.cursor)
         if pos_label == 1:
             return (result)
         else:
             return (tablesample(values={
                 "index":
                 ["Non-{}".format(pos_label), "{}".format(pos_label)],
                 "Non-{}".format(pos_label):
                 result.values[0],
                 "{}".format(pos_label):
                 result.values[1]
             },
                                 table_info=False))
     else:
         input_relation = "(SELECT *, ROW_NUMBER() OVER(PARTITION BY {}, row_id ORDER BY proba_predict DESC) AS pos FROM {}) knc_table_predict WHERE pos = 1".format(
             ", ".join(self.X), self.deploySQL())
         return (multilabel_confusion_matrix(self.y, "predict_knc",
                                             input_relation, self.cursor,
                                             self.classes))
 def confusion_matrix(self, pos_label=None, cutoff: float = 0.5):
     pos_label = self.classes[1] if (
         pos_label == None and len(self.classes) == 2) else pos_label
     if (pos_label in self.classes and cutoff < 1 and cutoff > 0):
         input_relation = self.deploySQL(
         ) + " WHERE predict_nc = '{}'".format(pos_label)
         y_score = "(CASE WHEN proba_predict > {} THEN 1 ELSE 0 END)".format(
             cutoff)
         y_true = "DECODE({}, '{}', 1, 0)".format(self.y, pos_label)
         result = confusion_matrix(y_true, y_score, input_relation,
                                   self.cursor)
         if pos_label == 1:
             return (result)
         else:
             return (tablesample(values={
                 "index":
                 ["Non-{}".format(pos_label), "{}".format(pos_label)],
                 "Non-{}".format(pos_label):
                 result.values[0],
                 "{}".format(pos_label):
                 result.values[1]
             },
                                 table_info=False))
     else:
         return (multilabel_confusion_matrix(self.y, "predict_nc",
                                             self.deploySQL(predict=True),
                                             self.cursor, self.classes))
 def confusion_matrix(self, pos_label=None, cutoff: float = 0.5):
     pos_label = self.classes[1] if (
         pos_label == None and len(self.classes) == 2) else pos_label
     if (pos_label in self.classes and cutoff < 1 and cutoff > 0):
         return (confusion_matrix(self.y,
                                  self.deploySQL(pos_label, cutoff),
                                  self.test_relation,
                                  self.cursor,
                                  pos_label=pos_label))
     else:
         return (multilabel_confusion_matrix(self.y, self.deploySQL(),
                                             self.test_relation,
                                             self.cursor, self.classes))
Beispiel #4
0
 def confusion_matrix(self, cutoff: float = 0.5):
     return (confusion_matrix(self.y, self.deploySQL(cutoff),
                              self.test_relation, self.cursor))