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")
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 input_relation = self.deploySQL() + " WHERE predict_knc = '{}'".format( pos_label) y_score = "(CASE WHEN proba_predict > {} THEN 1 ELSE 0 END)".format( cutoff) y_proba = "proba_predict" y_true = "DECODE({}, '{}', 1, 0)".format(self.y, 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(y_true, y_score, input_relation, self.cursor)) elif (method == "auc"): return (auc(y_true, y_proba, input_relation, self.cursor)) elif (method == "prc_auc"): return (prc_auc(y_true, y_proba, input_relation, self.cursor)) elif (method in ("best_cutoff", "best_threshold")): return (roc_curve(y_true, y_proba, input_relation, self.cursor, best_threshold=True)) elif (method in ("recall", "tpr")): return (recall_score(y_true, y_score, input_relation, self.cursor)) elif (method in ("precision", "ppv")): return (precision_score(y_true, y_score, input_relation, self.cursor)) elif (method in ("specificity", "tnr")): return (specificity_score(y_true, y_score, input_relation, self.cursor)) elif (method in ("negative_predictive_value", "npv")): return (precision_score(y_true, y_score, input_relation, self.cursor)) elif (method in ("log_loss", "logloss")): return (log_loss(y_true, y_proba, input_relation, self.cursor)) elif (method == "f1"): return (f1_score(y_true, y_score, input_relation, self.cursor)) elif (method == "mcc"): return (matthews_corrcoef(y_true, y_score, input_relation, self.cursor)) elif (method in ("bm", "informedness")): return (informedness(y_true, y_score, input_relation, self.cursor)) elif (method in ("mk", "markedness")): return (markedness(y_true, y_score, input_relation, self.cursor)) elif (method in ("csi", "critical_success_index")): return (critical_success_index(y_true, y_score, input_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" )