|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
import pandas as pd |
|
import seaborn as sns |
|
|
|
sns.set_theme() |
|
|
|
def read_results(filename): |
|
with open(filename, "r") as f: |
|
lines = f.readlines() |
|
|
|
preds_values = [] |
|
actual_values = [] |
|
mae_values = [] |
|
|
|
for line in lines: |
|
if line.startswith("Preds:"): |
|
preds = line.replace("[", "") |
|
preds = preds.replace("]", "") |
|
preds = preds.strip("Preds:") |
|
preds = preds.strip() |
|
preds = preds.split(",") |
|
preds = [p.strip() for p in preds] |
|
preds = np.asarray([float(p) for p in preds]) |
|
preds_values.append(preds) |
|
|
|
if line.startswith("Actual:"): |
|
actual = line.replace("[", "") |
|
actual = actual.replace("]", "") |
|
actual = actual.strip("Actual values:") |
|
actual = actual.strip() |
|
actual = actual.split(",") |
|
actual = [a.strip() for a in actual] |
|
actual = np.asarray([float(a) for a in actual]) |
|
actual_values.append(actual) |
|
|
|
if line.startswith("MAE"): |
|
mae = float(line.split()[-1]) |
|
mae_values.append(mae) |
|
return preds_values, actual_values, mae_values |
|
|
|
|
|
def plot_distribution(preds_values, actual_values, mae_values, model_name, threshold, oversampled): |
|
for i in range(2): |
|
if i == 0: |
|
input_type = "BoW" |
|
else: |
|
input_type = "TF-IDF" |
|
preds = preds_values[i] |
|
actual = actual_values[i] |
|
mae = mae_values[i] |
|
|
|
res = pd.DataFrame() |
|
res["Prediction"] = preds |
|
res["Actual"] = actual |
|
|
|
sns.displot(res, kind="kde") |
|
plt.xlabel("Home standard score") |
|
plt.title(f"Model: {model_name}, Input type: {input_type}, MAE: {mae}, Threshold:{threshold}", |
|
fontsize = 10) |
|
plt.ylim(-0.03, 2.5) |
|
plt.tight_layout() |
|
plt.savefig(f"figs/{model_name}_{input_type}_{threshold[0]}_{threshold[1]}_{oversampled}.png") |
|
plt.close() |
|
|
|
|
|
if __name__ == "__main__": |
|
preds_values, actual_values, mae_values = read_results("linear_models/lasso_0.01_0.99.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.01, 0.99], False) |
|
|
|
preds_values, actual_values, mae_values = read_results("linear_models/lin_reg_0.01_0.99.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "Linear regression", [0.01, 0.99], False) |
|
|
|
preds_values, actual_values, mae_values = read_results("linear_models/sgd_reg_0.01_0.99.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "SGD Regressor", [0.01, 0.99], False) |
|
|
|
preds_values, actual_values, mae_values = read_results("oversampled_False_catboost_reg_0.01_0.99.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "CatBoostRegressor", [0.01, 0.99], False) |
|
|
|
preds_values, actual_values, mae_values = read_results("linear_models/lasso_0.2_0.8.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.2, 0.8], False) |
|
|
|
preds_values, actual_values, mae_values = read_results("linear_models/oversampled_lin_reg_0.01_0.99.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "Linear regression", [0.01, 0.99], True) |
|
|
|
preds_values, actual_values, mae_values = read_results("linear_models/oversampled_lasso_0.01_0.99.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.01, 0.99], True) |
|
|
|
preds_values, actual_values, mae_values = read_results("linear_models/oversampled_sgd_reg_0.01_0.99.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "SGD Regressor", [0.01, 0.99], True) |
|
|
|
preds_values, actual_values, mae_values = read_results("oversampled_True_catboost_reg_0.01_0.99.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "CatBoostRegressor", [0.01, 0.99], True) |
|
|
|
preds_values, actual_values, mae_values = read_results("linear_models/oversampled_lasso_0.15_0.85.txt") |
|
plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.15, 0.85], True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|