ececet commited on
Commit
780bb93
1 Parent(s): 0b6e4a7
Files changed (1) hide show
  1. plots.py +106 -25
plots.py CHANGED
@@ -2,6 +2,8 @@ import numpy as np
2
  import matplotlib.pyplot as plt
3
  import pandas as pd
4
  import seaborn as sns
 
 
5
 
6
  sns.set_theme()
7
 
@@ -64,36 +66,115 @@ def plot_distribution(preds_values, actual_values, mae_values, model_name, thres
64
  plt.close()
65
 
66
 
67
- if __name__ == "__main__":
68
- preds_values, actual_values, mae_values = read_results("linear_models/lasso_0.01_0.99.txt")
69
- plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.01, 0.99], False)
70
-
71
- preds_values, actual_values, mae_values = read_results("linear_models/lin_reg_0.01_0.99.txt")
72
- plot_distribution(preds_values, actual_values, mae_values, "Linear regression", [0.01, 0.99], False)
73
-
74
- preds_values, actual_values, mae_values = read_results("linear_models/sgd_reg_0.01_0.99.txt")
75
- plot_distribution(preds_values, actual_values, mae_values, "SGD Regressor", [0.01, 0.99], False)
76
-
77
- preds_values, actual_values, mae_values = read_results("oversampled_False_catboost_reg_0.01_0.99.txt")
78
- plot_distribution(preds_values, actual_values, mae_values, "CatBoostRegressor", [0.01, 0.99], False)
79
-
80
- preds_values, actual_values, mae_values = read_results("linear_models/lasso_0.2_0.8.txt")
81
- plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.2, 0.8], False)
82
 
83
- preds_values, actual_values, mae_values = read_results("linear_models/oversampled_lin_reg_0.01_0.99.txt")
84
- plot_distribution(preds_values, actual_values, mae_values, "Linear regression", [0.01, 0.99], True)
 
85
 
86
- preds_values, actual_values, mae_values = read_results("linear_models/oversampled_lasso_0.01_0.99.txt")
87
- plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.01, 0.99], True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
- preds_values, actual_values, mae_values = read_results("linear_models/oversampled_sgd_reg_0.01_0.99.txt")
90
- plot_distribution(preds_values, actual_values, mae_values, "SGD Regressor", [0.01, 0.99], True)
91
 
92
- preds_values, actual_values, mae_values = read_results("oversampled_True_catboost_reg_0.01_0.99.txt")
93
- plot_distribution(preds_values, actual_values, mae_values, "CatBoostRegressor", [0.01, 0.99], True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
- preds_values, actual_values, mae_values = read_results("linear_models/oversampled_lasso_0.15_0.85.txt")
96
- plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.15, 0.85], True)
97
 
98
 
99
 
 
2
  import matplotlib.pyplot as plt
3
  import pandas as pd
4
  import seaborn as sns
5
+ from sklearn.metrics import mean_absolute_error
6
+
7
 
8
  sns.set_theme()
9
 
 
66
  plt.close()
67
 
68
 
69
+ def print_category_errors(actual, preds):
70
+ for i in range(2):
71
+ if i == 0:
72
+ input_type = "BoW"
73
+ else:
74
+ input_type = "TF-IDF"
 
 
 
 
 
 
 
 
 
75
 
76
+ preds = preds_values[i]
77
+ actual = actual_values[i]
78
+ mae = mae_values[i]
79
 
80
+ print(input_type)
81
+ actual1 = list(actual[np.where(actual < 0.98)])
82
+ preds1 = list(preds[np.where(actual < 0.98)])
83
+ print(f"Category 1 MAE: {mean_absolute_error(actual1, preds1):.4f}")
84
+ print(f"Category 1 correlation: {np.corrcoef(actual1, preds1)[0][1]:.4f}")
85
+ print()
86
+
87
+ actual2 = list(actual[np.where((actual >= 0.98) & (actual < 1.5))])
88
+ preds2 = list(preds[np.where((actual >= 0.98) & (actual < 1.5))])
89
+ print(f"Category 2 MAE: {mean_absolute_error(actual2, preds2):.4f}")
90
+ print(f"Category 2 correlation: {np.corrcoef(actual2, preds2)[0][1]:.4f}")
91
+ print()
92
+
93
+ actual3 = list(actual[np.where((actual >= 1.5) & (actual < 2))])
94
+ preds3 = list(preds[np.where((actual >= 1.5) & (actual < 2))])
95
+ print(f"Category 3 MAE: {mean_absolute_error(actual3, preds3):.4f}")
96
+ print(f"Category 3 correlation: {np.corrcoef(actual3, preds3)[0][1]:.4f}")
97
+ print()
98
+
99
+ actual4 = list(actual[np.where(actual >= 2)])
100
+ preds4 = list(preds[np.where(actual >= 2)])
101
+ print(f"Category 4 MAE: {mean_absolute_error(actual4, preds4):.4f}")
102
+ print(f"Category 4 correlation: {np.corrcoef(actual4, preds4)[0][1]:.4f}")
103
+ print()
104
+ print(f"Overall corr: {np.corrcoef(actual, preds)[0][1]:.4f}")
105
 
 
 
106
 
107
+ if __name__ == "__main__":
108
+ filename = "linear_models/lasso_0.01_0.99.txt"
109
+ print(filename)
110
+ preds_values, actual_values, mae_values = read_results(filename)
111
+ #plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.01, 0.99], False)
112
+ print_category_errors(actual_values, preds_values)
113
+ print("============================")
114
+
115
+ filename = "linear_models/lin_reg_0.01_0.99.txt"
116
+ print(filename)
117
+ preds_values, actual_values, mae_values = read_results(filename)
118
+ #plot_distribution(preds_values, actual_values, mae_values, "Linear regression", [0.01, 0.99], False)
119
+ print_category_errors(actual_values, preds_values)
120
+ print("============================")
121
+
122
+ filename = "linear_models/sgd_reg_0.01_0.99.txt"
123
+ print(filename)
124
+ preds_values, actual_values, mae_values = read_results(filename)
125
+ #plot_distribution(preds_values, actual_values, mae_values, "SGD Regressor", [0.01, 0.99], False)
126
+ print_category_errors(actual_values, preds_values)
127
+ print("============================")
128
+
129
+ filename = "oversampled_False_catboost_reg_0.01_0.99.txt"
130
+ print(filename)
131
+ preds_values, actual_values, mae_values = read_results(filename)
132
+ #plot_distribution(preds_values, actual_values, mae_values, "CatBoostRegressor", [0.01, 0.99], False)
133
+ print_category_errors(actual_values, preds_values)
134
+ print("============================")
135
+
136
+ filename = "linear_models/lasso_0.2_0.8.txt"
137
+ print(filename)
138
+ preds_values, actual_values, mae_values = read_results(filename)
139
+ #plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.2, 0.8], False)
140
+ print_category_errors(actual_values, preds_values)
141
+ print("============================")
142
+
143
+ filename = "linear_models/oversampled_lin_reg_0.01_0.99.txt"
144
+ print(filename)
145
+ preds_values, actual_values, mae_values = read_results(filename)
146
+ #plot_distribution(preds_values, actual_values, mae_values, "Linear regression", [0.01, 0.99], True)
147
+ print_category_errors(actual_values, preds_values)
148
+ print("============================")
149
+
150
+ filename = "linear_models/oversampled_lasso_0.01_0.99.txt"
151
+ print(filename)
152
+ preds_values, actual_values, mae_values = read_results(filename)
153
+ #plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.01, 0.99], True)
154
+ print_category_errors(actual_values, preds_values)
155
+ print("============================")
156
+
157
+ filename = "linear_models/oversampled_sgd_reg_0.01_0.99.txt"
158
+ print(filename)
159
+ preds_values, actual_values, mae_values = read_results(filename)
160
+ #plot_distribution(preds_values, actual_values, mae_values, "SGD Regressor", [0.01, 0.99], True)
161
+ print_category_errors(actual_values, preds_values)
162
+ print("============================")
163
+
164
+ filename = "oversampled_True_catboost_reg_0.01_0.99.txt"
165
+ print(filename)
166
+ preds_values, actual_values, mae_values = read_results(filename)
167
+ #plot_distribution(preds_values, actual_values, mae_values, "CatBoostRegressor", [0.01, 0.99], True)
168
+ print_category_errors(actual_values, preds_values)
169
+ print("============================")
170
+
171
+ filename = "linear_models/oversampled_lasso_0.15_0.85.txt"
172
+ print(filename)
173
+ preds_values, actual_values, mae_values = read_results(filename)
174
+ #plot_distribution(preds_values, actual_values, mae_values, "Lasso", [0.15, 0.85], True)
175
+ print_category_errors(actual_values, preds_values)
176
+ print("============================")
177
 
 
 
178
 
179
 
180