-
Notifications
You must be signed in to change notification settings - Fork 0
/
spamchecker.py
117 lines (109 loc) · 5.93 KB
/
spamchecker.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
from manim import *
class Spam_Detection(Scene):
def construct(self):
Tex.set_default(font_size= 30)
title = Title("Spam Detection using Bayes Theorem", match_underline_width_to_text= True)
training = Tex("Training Machine with a bunch of mails")
m1 = Tex("E1: \"send us your password\" spam").to_corner(LEFT).shift(UP * 1.2)
m1[0][-1:-5:-1].set_color(YELLOW)
m2 = Tex("E2: \"send us your review\" ham")
m2[0][-1:-4:-1].set_color(YELLOW)
m3 = Tex("E3: \"review your password\" ham")
m3[0][-1:-4:-1].set_color(YELLOW)
m4 = Tex("E4: \"review us\"spam")
m4[0][-1:-5:-1].set_color(YELLOW)
m5 = Tex("E5: \"send your password\" spam")
m5[0][-1:-5:-1].set_color(YELLOW)
m6 = Tex("E6: \"send us your account\" spam")
m6[0][-1:-5:-1].set_color(YELLOW)
pre = m1
for i in m2, m3, m4, m5, m6:
i.next_to(pre, DOWN, aligned_edge= LEFT)
pre = i
mails = VGroup(m1, m2, m3, m4, m5, m6)
table = MathTable(
[
[r"P(spam)\frac{4}{6}", r"P(ham)=\frac{2}{6}", ""],
["spam", "ham", "word"],
[r"\frac{0}{4}", r"\frac{0}{2}", "password"],
[r"\frac{0}{4}", r"\frac{0}{2}", "review"],
[r"\frac{0}{4}", r"\frac{0}{2}", "send"],
[r"\frac{0}{4}", r"\frac{0}{2}", "us"],
[r"\frac{0}{4}", r"\frac{0}{2}", "your"],
[r"\frac{0}{4}", r"\frac{0}{2}", "account"],
],
include_outer_lines= True,
).scale(0.39).next_to(mails, RIGHT)
for i in range(6):
table[0][8+i*3].set_color(BLACK)
# self.add(title, mails, table)
self.play(Write(title), run_time= 1)
self.wait(1)
self.play(Write(training), run_time= 1)
self.wait(2)
self.play(FadeOut(training), run_time= 1)
self.wait(1)
self.play(Create(mails), run_time= 3)
self.wait(3)
self.play(Create(table), run_time= 2)
self.wait(3)
# Copying Text from mails to
password = m1[0][-6:-14:-1].copy()
review = m2[0][-5:-11:-1].copy()
send = m1[0][4:8:1].copy()
us = m1[0][8:10].copy()
your = m1[0][10:14].copy()
account = m6[0][-6:-13:-1].copy()
n = 0
for i in password, review, send, us, your, account:
self.play(i.animate.move_to( table[0][8+n*3].get_center()).scale(0.7))
n = n + 1
# Counting Data
# password spam
self.play(Indicate(m1[0][-6:-14:-1]), table[0][6][0][0].animate.become(Tex("1").move_to(table[0][6][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m5[0][-6:-14:-1]), table[0][6][0][0].animate.become(Tex("2").move_to(table[0][6][0][0].get_center()).scale(0.7)))
self.wait(0.5)
# password ham
self.play(Indicate(m3[0][-5:-13:-1]), table[0][7][0][0].animate.become(Tex("1").move_to(table[0][7][0][0].get_center()).scale(0.7)))
self.wait(0.5)
# review ham
self.play(Indicate(m2[0][-5:-11:-1]), table[0][10][0][0].animate.become(Tex("1").move_to(table[0][10][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m3[0][4:10:1]), table[0][10][0][0].animate.become(Tex("2").move_to(table[0][10][0][0].get_center()).scale(0.7)))
self.wait(0.5)
# review spam
self.play(Indicate(m4[0][4:10:1]), table[0][9][0][0].animate.become(Tex("1").move_to(table[0][9][0][0].get_center()).scale(0.7)))
self.wait(0.5)
# send spam and ham
self.play(Indicate(m1[0][4:8:1]), table[0][12][0][0].animate.become(Tex("1").move_to(table[0][12][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m2[0][4:8:1]), table[0][13][0][0].animate.become(Tex("1").move_to(table[0][13][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m5[0][4:8:1]), table[0][12][0][0].animate.become(Tex("2").move_to(table[0][12][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m6[0][4:8:1]), table[0][12][0][0].animate.become(Tex("3").move_to(table[0][12][0][0].get_center()).scale(0.7)))
self.wait(0.5)
# us spam and ham
self.play(Indicate(m1[0][8:10:1]), table[0][15][0][0].animate.become(Tex("1").move_to(table[0][15][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m2[0][8:10:1]), table[0][16][0][0].animate.become(Tex("1").move_to(table[0][16][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m4[0][10:12:1]), table[0][15][0][0].animate.become(Tex("2").move_to(table[0][15][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m6[0][8:10:1]), table[0][15][0][0].animate.become(Tex("3").move_to(table[0][15][0][0].get_center()).scale(0.7)))
self.wait(0.5)
# your spam and ham
self.play(Indicate(m1[0][10:14:1]), table[0][18][0][0].animate.become(Tex("1").move_to(table[0][18][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m2[0][10:14:1]), table[0][19][0][0].animate.become(Tex("1").move_to(table[0][19][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m3[0][10:14:1]), table[0][19][0][0].animate.become(Tex("2").move_to(table[0][19][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m5[0][8:12:1]), table[0][18][0][0].animate.become(Tex("2").move_to(table[0][18][0][0].get_center()).scale(0.7)))
self.wait(0.5)
self.play(Indicate(m6[0][10:14:1]), table[0][18][0][0].animate.become(Tex("3").move_to(table[0][18][0][0].get_center()).scale(0.7)))
self.wait(0.5)
# account spam
self.play(Indicate(m6[0][-6:-13:-1]), table[0][21][0][0].animate.become(Tex("1").move_to(table[0][21][0][0].get_center()).scale(0.7)))
self.wait(0.5)