<commit_before>#!/usr/bin/env python

"""
Tasks performed after model building: Metric analysis and display
"""

import matplotlib.pyplot as plt
import pickle

__author__ = "<NAME>"
__credits__ = "<NAME>"
__license__ = "BSD 3-Clause License"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Development"

NN_PICKLE = 'nn_data.pkl'
SVM_PICKLE = 'svm_data.pkl'
DT_PICKLE = 'dt_data.pkl'
RR_PICKLE = 'rr_data.pkl'
BRR_PICKLE = 'brr_data.pkl'
LASSO_PICKLE = 'lasso_data.pkl'
XY_PICKLE = 'xy_data.pkl'


def results():
    """
    Printing results and metrics from the pickles used with the learning
    models used in models.py
    :return: None
    """
    with open(NN_PICKLE, 'rb') as result:
        grid = pickle.load(result)
        net = pickle.load(result)
        mean_abs = pickle.load(result)
        mean_sq = pickle.load(result)
        median_abs = pickle.load(result)
        r2 = pickle.load(result)
        exp_var_score = pickle.load(result)
        accuracy = pickle.load(result)
        y_pred_nn = pickle.load(result)

    grid.save_params_to('/tmp/grid.params')
    net.save_params_to('/tmp/net.params')

    print("A list of named tuples of scores for each set of parameter "
          "combinations in param_grid for the NN model:")
    print("[parameters, mean_validation_score over CV folds, the list of "
          "scores for each fold]")
    print(grid.grid_scores_)
    print("Estimator that was chosen by the search with the highest score for the NN model:")
    print(grid.best_estimator_)
    print("Score of best_estimator on the held out data for the NN model:")
    print(grid.best_score_)
    print("Parameter setting that gave the best results on the held out data for the NN model:")
    print(grid.best_params_)
    print("Scorer function used on the held out data to choose the best "
          "parameters for the NN model:")
    print(grid.scorer_)
    print("Mean absolute error regression loss for NN model:")
    print(mean_abs)
    print("Mean squared error regression loss for NN model:")
    print(mean_sq)
    print("Median absolute error regression loss for NN model:")
    print(median_abs)
    print("R^2 (coefficient of determination) regression score function for NN model:")
    print(r2)
    print("Explained variance regression score function for NN model:")
    print(exp_var_score)
    print("Accuracy prediction score for the NN model:")
    print(accuracy)

    with open(SVM_PICKLE, 'rb') as result:
        mean_abs = pickle.load(result)
        mean_sq = pickle.load(result)
        median_abs = pickle.load(result)
        r2 = pickle.load(result)
        exp_var_score = pickle.load(result)
        accuracy = pickle.load(result)
        y_pred_svm = pickle.load(result)
<commit_msg>Renamed grid to clf to maintain standard<commit_after>#!/usr/bin/env python

"""
Tasks performed after model building: Metric analysis and display
"""

import matplotlib.pyplot as plt
import pickle

__author__ = "<NAME>"
__credits__ = "<NAME>"
__license__ = "BSD 3-Clause License"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Development"

NN_PICKLE = 'nn_data.pkl'
SVM_PICKLE = 'svm_data.pkl'
DT_PICKLE = 'dt_data.pkl'
RR_PICKLE = 'rr_data.pkl'
BRR_PICKLE = 'brr_data.pkl'
LASSO_PICKLE = 'lasso_data.pkl'
XY_PICKLE = 'xy_data.pkl'


def results():
    """
    Printing results and metrics from the pickles used with the learning
    models used in models.py
    :return: None
    """
    with open(NN_PICKLE, 'rb') as result:
        clf = pickle.load(result)
        net = pickle.load(result)
        mean_abs = pickle.load(result)
        mean_sq = pickle.load(result)
        median_abs = pickle.load(result)
        r2 = pickle.load(result)
        exp_var_score = pickle.load(result)
        accuracy = pickle.load(result)
        y_pred_nn = pickle.load(result)

    clf.save_params_to('/tmp/clf.params')
    net.save_params_to('/tmp/net.params')

    print("A list of named tuples of scores for each set of parameter "
          "combinations in param_grid for the NN model:")
    print("[parameters, mean_validation_score over CV folds, the list of "
          "scores for each fold]")
    print(clf.grid_scores_)
    print("Estimator that was chosen by the search with the highest score for the NN model:")
    print(clf.best_estimator_)
    print("Score of best_estimator on the held out data for the NN model:")
    print(clf.best_score_)
    print("Parameter setting that gave the best results on the held out data for the NN model:")
    print(clf.best_params_)
    print("Scorer function used on the held out data to choose the best "
          "parameters for the NN model:")
    print(clf.scorer_)
    print("Mean absolute error regression loss for NN model:")
    print(mean_abs)
    print("Mean squared error regression loss for NN model:")
    print(mean_sq)
    print("Median absolute error regression loss for NN model:")
    print(median_abs)
    print("R^2 (coefficient of determination) regression score function for NN model:")
    print(r2)
    print("Explained variance regression score function for NN model:")
    print(exp_var_score)
    print("Accuracy prediction score for the NN model:")
    print(accuracy)

    with open(SVM_PICKLE, 'rb') as result:
        mean_abs = pickle.load(result)
        mean_sq = pickle.load(result)
        median_abs = pickle.load(result)
        r2 = pickle.load(result)
        exp_var_score = pickle.load(result)
        accuracy = pickle.load(result)
        y_pred_svm = pickle.load(result)

{'fraction_non_alphanumeric': 0.09897056167599784, 'fraction_numerical': 0.0018060321473722233, 'mean_word_length': 3.3571990558615266, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1016852', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1762, 'n_words': 524}