-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbayes_solution.html
More file actions
35 lines (24 loc) · 813 Bytes
/
bayes_solution.html
File metadata and controls
35 lines (24 loc) · 813 Bytes
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
<html>
<body>
<h1>perform calculation for Naive Bayes Theorem</h1>
<script>
// if using one array remove all occurences of (B|A) in common // then compute number of B in common
function mr_bayes(total_size, B_num, A_num, B_in_common)
{
const p_B_A = B_num/A_num;
const p_A = A_num/total_size;
const numerator = p_B_A * p_A;
const common_num = total_size - A_num;
const p_B_common = B_in_common/common_num;
const p_common = 1-p_A;
const denominator = numerator+(p_B_common * p_common);
const bayes_factor = numerator/denominator;
const pp = p_B_A * bayes_factor;
return pp;
}
document.write("<h3>row1:</h3>" + mr_bayes(1000,1,3,0));
document.write("<h3>row2:</h3>" + mr_bayes(615,2,3,1));
document.write("<h3>row3:</h3>" + mr_bayes(100000,98,100,5000));
</script>
</body>
</html>