-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstatistics.py
76 lines (54 loc) · 2.65 KB
/
statistics.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
if __name__ == "__main__":
df = pd.read_pickle('data/inferences/dataset-inferenced.pkl')
# Political distribution
print(df['political'].value_counts())
# Gender distribution
print(df['gender'].value_counts())
# Age distribution
print(df['age'].value_counts())
# Sentiment distribution
print(df['total_sentiment'].value_counts())
# Subjectivity distribution
ax = df['subjectivity'].plot.hist()
plt.show()
# For gender find political orientation
print("Females:\n", df[df['gender']==1]['political'].value_counts())
print("Males:\n", df[df['gender']==0]['political'].value_counts())
# For gender find age
print("Females:\n", df[df['gender']==1]['age'].value_counts())
print("Males:\n", df[df['gender']==0]['age'].value_counts())
# For gender find sentiment (polarity)
print("Females:\n", df[df['gender']==1]['total_sentiment'].value_counts())
print("Males:\n", df[df['gender']==0]['total_sentiment'].value_counts())
# For gender find subjectivity
print("Females:\n", df[df['gender']==1]['subjectivity'].value_counts())
print("Males:\n", df[df['gender']==0]['subjectivity'].value_counts())
# For political find gender
print("Republicans:\n", df[df['political']==1]['gender'].value_counts())
print("Democrats:\n", df[df['political']==0]['gender'].value_counts())
# For political find age
print("Republicans:\n", df[df['political']==1]['age'].value_counts())
print("Democrats:\n", df[df['political']==0]['age'].value_counts())
# For political find sentiment (polarity)
print("Republicans:\n", df[df['political']==1]['total_sentiment'].value_counts())
print("Democrats:\n", df[df['political']==0]['total_sentiment'].value_counts())
# For political find subjectivity
print("Republicans:\n", df[df['political']==1]['subjectivity'].value_counts())
print("Democrats:\n", df[df['political']==0]['subjectivity'].value_counts())
# Topics stats
df['topic'] = df['topic_distribution'].apply(lambda x: np.argmax(x))
for i in range(0, 6):
print("=======================")
print("Period ", i+1)
for j in range(0, 5):
# content based stats
print("-----------------")
print("Topic ", j+1)
print(df[(df['period'] == i) & (df['topic'] == j)]['topic'].count())
print('political')
print(df[(df['period'] == i) & (df['topic'] == j)]['political'].value_counts())
print('total_sentiment')
print(df[(df['period'] == i) & (df['topic'] == j)]['total_sentiment'].value_counts())