예제 #1
0
def model_evaluation(y_test_pickle_loc, test_predict_scores_pickle_loc):
    """
    """

    ## Importing raw entries
    y_test = load_df(y_test_pickle_loc)
    predicted_scores = load_df(test_predict_scores_pickle_loc)

    ##
    predicted_labels = f_predicted_labels(y_test, predicted_scores, 0.18)

    fpr, tpr, thresholds = roc_curve(y_test,
                                     predicted_scores[:, 1],
                                     pos_label=1)

    print("\n++ Tabla de referencia: \n{}\n".format(tabla_referencia()))
    print("++ Tabla de confusión 1: \n{}\n".format(
        tabla_confusion(
            confusion_matrix(y_test, predicted_labels, normalize='all'))))
    print("++ Tabla de confusión 2: \n{}\n".format(
        tabla_confusion(confusion_matrix(y_test, predicted_labels))))
    print("\n++ Score accuracy: {}\n".format(
        accuracy_score(y_test, predicted_labels)))

    precision, recall, thresholds_2 = precision_recall_curve(
        y_test, predicted_scores[:, 1], pos_label=1)

    thresholds_2 = np.append(thresholds_2, 1)

    metrics_report = get_metrics_report(fpr, tpr, thresholds, precision,
                                        recall, thresholds_2)

    save_metrics(metrics_report, metrics_report_pickle_loc)

    negocio = metrics_report[metrics_report.fpr <= 0.06]

    punto_corte = negocio.head(1).threshold.values[0]

    new_labels = [
        0 if score < punto_corte else 1 for score in predicted_scores[:, 1]
    ]

    print("++ Tabla de confusión reajustada 1: \n{}\n".format(
        tabla_confusion(confusion_matrix(y_test, new_labels,
                                         normalize='all'))))

    k = 20 / 551

    print("\n++ Precision @k: {}".format(
        precision_at_k(y_test, predicted_scores[:, 1], k)))
    print("\n++ Recall @k: {}\n".format(
        recall_at_k(y_test, predicted_scores[:, 1], k)))

    df_aeq = pd.DataFrame(y_test)
    df_aeq["score"] = new_labels

    save_metrics(df_aeq, aequitas_df_pickle_loc)

    print("\n** Model evaluation module successfully executed **\n")
예제 #2
0
def load_transformation(path):
    """
    Loading transformation pickle as dataframe for transformation pipeline.
        args:
            path (string): location where the pickle that will be loaded is.
        returns:
            df (dataframe): dataframe with features obtained from the transformation module.
    """

    df = load_df(path)

    return df
예제 #3
0
def load_model(path):
    """
    ...
        args:
            path (string): ...
        returns:
            -
    """

    df = load_df(path)

    return df
예제 #4
0
def load_selected_model_results(path):
    """
    ...
        args:
            path (string): ...
        returns:
            -
    """

    df = load_df(path)

    return df
예제 #5
0
def load_features(path):
    """
    Loading fe pickle as dataframe from fe pipeline.
        args:
            path (string): location where the pickle that will be loaded is.
        returns:
            -
    """

    df = load_df(path)

    return df
예제 #6
0
def load_ingestion(path):
    """
    Loading ingestion pickle as dataframe for transformation pipeline.
        args:
            path (string): location where the pickle that will be loaded is.
        returns:
            df (dataframe): dataframe obtained from ingestion pickle.
    """

    df = load_df(path)

    return df
예제 #7
0
def load_transformation(path):
    """
    Cargar pickle que se generó durante la transformación
    :param path: Path donde se encuentra el pickle
    :return:
    """
    print("Opening feature engineering pickle from output path")
    output_path = os.path.join(path, "output", "fe_df.pkl")

    # Recuperar el pickle
    incidentes_pkl = load_df(output_path)
    print("Feature Engineering pickle successfully retrieved.")

    return incidentes_pkl
def load_ingestion(path):
    return load_df(path)
예제 #9
0
def load_transformation(path):
    return load_df(path)