-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_score_dist.py
43 lines (28 loc) · 1.24 KB
/
make_score_dist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from logger import Logger
from utils.data_preprocess import generate_data
from collections import Counter
def plot_scores_distribution(plt_filename, dataset, logger):
click_bait_scores = [elem['clickBaitScore'] for elem in dataset]
occurences = dict(Counter(click_bait_scores)).items()
occurences = sorted(occurences, key=lambda tup: tup[1], reverse = True)
sns.set()
x = np.array(range(len(occurences)))
y = [item[1] for item in occurences]
fig = plt.figure(figsize=(10, 8))
plt.bar(x, y, color = 'blue')
my_xticks = ["{:.2f}".format(item[0]) for item in occurences]
plt.xticks(x, my_xticks, rotation = 90, fontsize = 11)
plt.yticks(fontsize = 11)
plt.xlabel("Click-bait scores", fontsize = 13)
plt.ylabel("Count", fontsize = 13)
for pos_x, pos_y in zip(x, y):
plt.text(pos_x - 0.5, pos_y + 0.8, str(pos_y), fontsize = 9)
plt.savefig(logger.get_output_file(plt_filename), dpi = 120, bbox_inches='tight')
plt.close()
if __name__ == '__main__':
logger = Logger(show = True, html_output = True, config_file = "config.txt")
dataset = generate_data("large", logger)
plot_scores_distribution("large_scores_distribution.jpg", dataset, logger)