# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # 7. Evaluation and results comparison

# Evaluating stored metrics for different experiments
#

# +
import pandas as pd
import numpy as np
import seaborn as sns
import math

from IPython.display import Image

from matplotlib import pyplot as plt
from matplotlib import patches

from metrics import save_metrics
from metrics import plot_metrics
from metrics import init_metrics_file

from models import evaluate_model


from lightgbm import LGBMClassifier
from sklearn.model_selection import train_test_split
import time
from sklearn.metrics import f1_score
from sklearn.model_selection import GridSearchCV


sns.set()


# -

# ---

# +
#init_metrics_file()
# -

# ### Define methods to plot metrics

# +
def plot_classifier(df_data_to_plot, classifier):

    plt.figure(figsize=(20,5))
    x = range(0, df_data_to_plot.shape[1])
    _x = np.arange(len(x))
    labels = df_data_to_plot.columns
    plt.xticks(x, labels, rotation='vertical');
    
    plt.bar(_x + 0, height=df_data_to_plot.loc[(classifier, 'accuracy')], width=.1, label='accuracy')
    plt.bar(_x + .1, height=df_data_to_plot.loc[(classifier, 'f1-score')], width=.1, label='f1-score')
    plt.bar(_x + .2, height=df_data_to_plot.loc[(classifier, 'auc-roc')], width=.1, label='auc-roc')
    plt.bar(_x + .3, height=df_data_to_plot.loc[(classifier, 'precision')], width=.1, label='precision')
    plt.bar(_x + .4, height=df_data_to_plot.loc[(classifier, 'recall')], width=.1, label='recall')
    
    plt.xticks(rotation=90);
    plt.title(f'Metrics comparison for classifier {classifier}');
    plt.legend();
    
    
def plot_metric(df_data_to_plot, classifiers, metric):
    plt.figure(figsize=(20,5))
    x = range(0, df.shape[1])
    _x = np.arange(len(x))
    labels = df.columns
    plt.xticks(x, labels, rotation='vertical');
    width = 0
    for classifier in classifiers:
        plt.bar(_x + width, height=df_data_to_plot.loc[(classifier, metric)], width=.1, label=classifier)
        width = width + .1 
        
    plt.xticks(rotation=90);
    plt.title(f'Metric {metric} comparison for multiple classifiers');
    plt.legend();    
    
   
# -

# ---
# ### Read metrics from a file 

df = plot_metrics()
df = df.replace(to_replace='-', value=0).astype(float)
cols = ['first_dataset', 'balanced', 'with_distance', 'with_angle', 'with_player_ids', 'with_player_stats', 'with_player_stats_tuned', 'with_player_salary', 'short_dist', 'long_dist']
df = df[cols]
cols_top = [ 'balanced', 'with_distance', 'with_angle', 'with_player_stats', 'with_player_stats_tuned']
df_top = df[cols_top].copy()
df

# ---
# ### Plot metrics per classifier

plot_classifier(df, 'LogReg');
plot_classifier(df, 'LGBM');
plot_classifier(df, 'KNC');


# ---
# ### Plot metrics per metric for all classifier

plot_metric(df, ['LogReg', 'LGBM', 'KNC'], 'f1-score');
plot_metric(df, ['LogReg', 'LGBM', 'KNC'], 'accuracy');
plot_metric(df, ['LogReg', 'LGBM', 'KNC'], 'auc-roc');
plot_metric(df, ['LogReg', 'LGBM', 'KNC'], 'precision');
plot_metric(df, ['LogReg', 'LGBM', 'KNC'], 'recall');



StarcoderdataJupyterScriptsDedupFiltered