-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththesis_method.py
150 lines (109 loc) · 4.33 KB
/
thesis_method.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import numpy as np
import matplotlib.pyplot as plt
def generate_dataset():
x = np.random.rand(100,2)
return x
def plot_dataset():
np.random.seed(26)
# Sample data
#time = np.arange(1, 16)
time_class1 = np.random.choice(np.arange(1, 41), size=20, replace=False)
time_class2 = np.delete(np.arange(1,41), time_class1-1)
feature2_class1 = np.random.uniform(0.532, 0.55, size=20)
feature2_class2 = np.random.uniform(0.45, 0.53, size=len(time_class2))
# Create the plot
plt.figure(figsize=(8, 8))
plt.scatter(time_class1, feature2_class1, color='orange', label='Class 1', s=200)
plt.scatter(time_class2, feature2_class2, color='purple', label='Class 2', s=200)
# Add lines
plt.axhline(y=0.53, color='red', linestyle='-', linewidth=3)
plt.axhline(y=0.505, color='green', linestyle='-', linewidth=3)
# Labels and title
plt.xlabel('time', fontsize=20, color='black')
plt.ylabel('feature 2', fontsize=20, color='black')
# Remove x-axis ticks
plt.xticks([])
# Set y-axis limits
plt.ylim(0.44, 0.56)
plt.yticks(fontsize=18)
plt.savefig("e_drift_explanation_large.pdf")
plt.show()
def plot_dataset_yellow():
np.random.seed(9)
# Sample data
time_class1 = np.random.choice(np.arange(1, 41), size=20, replace=False)
time_class2 = np.delete(np.arange(1,41), time_class1-1)
feature2_class1 = np.random.uniform(0.50, 0.55, size=20)
feature2_class2 = np.random.uniform(0.45, 0.50, size=len(time_class2))
# Create the plot
plt.figure(figsize=(8, 8))
plt.scatter(time_class1, feature2_class1, color='orange', label='Class 1', s=200)
plt.scatter(time_class2, feature2_class2, color='purple', label='Class 2', s=200)
# Add lines
plt.axhline(y=0.50, color='red', linestyle='-', linewidth=3)
plt.axhline(y=0.505, color='green', linestyle='-', linewidth=3)
# Add arrows from yellow points above the green line to the green line
for i in range(len(time_class1)):
if feature2_class1[i] <= 0.505:
plt.annotate(
'',
xy=(time_class1[i], 0.505),
xytext=(time_class1[i], feature2_class1[i]),
arrowprops=dict(arrowstyle="->", color='blue', lw=3)
)
# Labels and title
plt.xlabel('time', fontsize=20, color='black')
plt.ylabel('feature 2', fontsize=20, color='black')
# Remove x-axis ticks
plt.xticks([])
# Set y-axis limits
plt.ylim(0.44, 0.56)
plt.yticks(fontsize=18)
plt.savefig("e_drift_explanation_misclassified_1.pdf")
plt.show()
def plot_dataset_purple():
np.random.seed(26)
# Sample data
time_class1 = np.random.choice(np.arange(1, 41), size=20, replace=False)
time_class2 = np.delete(np.arange(1,41), time_class1-1)
feature2_class1 = np.random.uniform(0.532, 0.55, size=20)
feature2_class2 = np.random.uniform(0.45, 0.53, size=len(time_class2))
# Create the plot
plt.figure(figsize=(8, 8))
plt.scatter(time_class1, feature2_class1, color='orange', label='Class 1', s=200)
plt.scatter(time_class2, feature2_class2, color='purple', label='Class 2', s=200)
# Add lines
plt.axhline(y=0.53, color='red', linestyle='-', linewidth=3)
plt.axhline(y=0.505, color='green', linestyle='-', linewidth=3)
# Add arrows from purple points below the green line to the green line
for i in range(len(time_class2)):
if feature2_class2[i] > 0.505:
plt.annotate(
'',
xy=(time_class2[i], 0.505),
xytext=(time_class2[i], feature2_class2[i]),
arrowprops=dict(arrowstyle="->", color='blue', lw=3)
)
# Labels and title
plt.xlabel('time', fontsize=20, color='black')
plt.ylabel('feature 2', fontsize=20, color='black')
# Remove x-axis ticks
plt.xticks([])
# Set y-axis limits
plt.ylim(0.44, 0.56)
plt.yticks(fontsize=18)
plt.savefig("e_drift_explanation_misclassified_2.pdf")
plt.show()
def main():
#set random seed
np.random.seed(42)
#generate random dataset
x_values = generate_dataset()
#generate plot
#seed is 9 for small one (no concept drift)
#seed is 26 for large one (concept drift)
#plot_dataset()
plot_dataset_yellow()
plot_dataset_purple()
if __name__ == '__main__':
main()