Beispiel #1
0
 def score(self, cutoff: float = 0.5, method: str = "accuracy"):
     if (method in ("accuracy", "acc")):
         return (accuracy_score(self.y, self.deploySQL(cutoff),
                                self.test_relation, self.cursor))
     elif (method == "auc"):
         return auc(self.y, self.deploySQL(), self.test_relation,
                    self.cursor)
     elif (method == "prc_auc"):
         return prc_auc(self.y, self.deploySQL(), self.test_relation,
                        self.cursor)
     elif (method in ("best_cutoff", "best_threshold")):
         return (roc_curve(self.y,
                           self.deploySQL(),
                           self.test_relation,
                           self.cursor,
                           best_threshold=True))
     elif (method in ("recall", "tpr")):
         return (recall_score(self.y, self.deploySQL(cutoff),
                              self.test_relation, self.cursor))
     elif (method in ("precision", "ppv")):
         return (precision_score(self.y, self.deploySQL(cutoff),
                                 self.test_relation, self.cursor))
     elif (method in ("specificity", "tnr")):
         return (specificity_score(self.y, self.deploySQL(cutoff),
                                   self.test_relation, self.cursor))
     elif (method in ("negative_predictive_value", "npv")):
         return (precision_score(self.y, self.deploySQL(cutoff),
                                 self.test_relation, self.cursor))
     elif (method in ("log_loss", "logloss")):
         return (log_loss(self.y, self.deploySQL(), self.test_relation,
                          self.cursor))
     elif (method == "f1"):
         return (f1_score(self.y, self.deploySQL(cutoff),
                          self.test_relation, self.cursor))
     elif (method == "mcc"):
         return (matthews_corrcoef(self.y, self.deploySQL(cutoff),
                                   self.test_relation, self.cursor))
     elif (method in ("bm", "informedness")):
         return (informedness(self.y, self.deploySQL(cutoff),
                              self.test_relation, self.cursor))
     elif (method in ("mk", "markedness")):
         return (markedness(self.y, self.deploySQL(cutoff),
                            self.test_relation, self.cursor))
     elif (method in ("csi", "critical_success_index")):
         return (critical_success_index(self.y, self.deploySQL(cutoff),
                                        self.test_relation, self.cursor))
     else:
         raise ValueError(
             "The parameter 'method' must be in accuracy|auc|prc_auc|best_cutoff|recall|precision|log_loss|negative_predictive_value|specificity|mcc|informedness|markedness|critical_success_index"
         )
Beispiel #2
0
def auc(y_true: str, 
		y_score: str, 
		input_relation: str,
		cursor,
		pos_label = 1):
	return (roc_curve(y_true, y_score, input_relation, cursor, pos_label, nbins = 10000, auc_roc = True))
 def score(self,
           pos_label=None,
           cutoff: float = 0.5,
           method: str = "accuracy"):
     pos_label = self.classes[1] if (
         pos_label == None and len(self.classes) == 2) else pos_label
     if (pos_label not in self.classes):
         raise ValueError(
             "'pos_label' must be one of the response column classes")
     elif (cutoff >= 1 or cutoff <= 0):
         raise ValueError("'cutoff' must be in ]0;1[")
     if (method in ("accuracy", "acc")):
         return (accuracy_score(self.y, self.deploySQL(pos_label, cutoff),
                                self.test_relation, self.cursor))
     elif (method == "auc"):
         return auc("DECODE({}, '{}', 1, 0)".format(self.y, pos_label),
                    self.deploySQL(allSQL=True)[0].format(pos_label),
                    self.test_relation, self.cursor)
     elif (method == "prc_auc"):
         return prc_auc("DECODE({}, '{}', 1, 0)".format(self.y, pos_label),
                        self.deploySQL(allSQL=True)[0].format(pos_label),
                        self.test_relation, self.cursor)
     elif (method in ("best_cutoff", "best_threshold")):
         return (roc_curve("DECODE({}, '{}', 1, 0)".format(
             self.y, pos_label),
                           self.deploySQL(allSQL=True)[0].format(pos_label),
                           self.test_relation,
                           self.cursor,
                           best_threshold=True))
     elif (method in ("recall", "tpr")):
         return (recall_score(self.y, self.deploySQL(pos_label, cutoff),
                              self.test_relation, self.cursor))
     elif (method in ("precision", "ppv")):
         return (precision_score(self.y, self.deploySQL(pos_label, cutoff),
                                 self.test_relation, self.cursor))
     elif (method in ("specificity", "tnr")):
         return (specificity_score(self.y,
                                   self.deploySQL(pos_label, cutoff),
                                   self.test_relation, self.cursor))
     elif (method in ("negative_predictive_value", "npv")):
         return (precision_score(self.y, self.deploySQL(pos_label, cutoff),
                                 self.test_relation, self.cursor))
     elif (method in ("log_loss", "logloss")):
         return (log_loss(
             "DECODE({}, '{}', 1, 0)".format(self.y, pos_label),
             self.deploySQL(allSQL=True)[0].format(pos_label),
             self.test_relation, self.cursor))
     elif (method == "f1"):
         return (f1_score(self.y, self.deploySQL(pos_label, cutoff),
                          self.test_relation, self.cursor))
     elif (method == "mcc"):
         return (matthews_corrcoef(self.y,
                                   self.deploySQL(pos_label, cutoff),
                                   self.test_relation, self.cursor))
     elif (method in ("bm", "informedness")):
         return (informedness(self.y, self.deploySQL(pos_label, cutoff),
                              self.test_relation, self.cursor))
     elif (method in ("mk", "markedness")):
         return (markedness(self.y, self.deploySQL(pos_label, cutoff),
                            self.test_relation, self.cursor))
     elif (method in ("csi", "critical_success_index")):
         return (critical_success_index(self.y,
                                        self.deploySQL(pos_label, cutoff),
                                        self.test_relation, self.cursor))
     else:
         raise ValueError(
             "The parameter 'method' must be in accuracy|auc|prc_auc|best_cutoff|recall|precision|log_loss|negative_predictive_value|specificity|mcc|informedness|markedness|critical_success_index"
         )
Beispiel #4
0
 def roc_curve(self):
     return (roc_curve(self.y, self.deploySQL(), self.test_relation,
                       self.cursor))