-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject1.html
173 lines (168 loc) · 12.8 KB
/
project1.html
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Naive Bayes And Sailor Search</title>
<link rel="stylesheet" href="style.css">
<script src="https://kit.fontawesome.com/83c6b17d5b.js" crossorigin="anonymous"></script>
<!-- MathJax CDN -->
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<!----------Adding a Modular-------------------------------->
<!-- Add modal HTML and JavaScript here -->
<style>
/* Modal styles */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* Close button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
<!------------The Project------------------------>
</head>
<div id="header">
<nav>
<img src="images/logo.png" class="logo">
<ul id="sidemenu">
<li><a href="index.html">Home</a></li>
<li><a href="more.html">More</a></li>
<li><a href="index.html#contact">Contact</a></li>
<i class="fa-solid fa-xmark" onclick="closemenu()"></i>
</ul>
<i class="fa-solid fa-bars" onclick="openmenu()"></i>
</nav>
<body class="container1">
<!-- Project -->
<header style="text-align: center; font-family: cursive; font-style: italic; color: cadetblue; margin-top: 10px; ">
<h1>Finding Lost Sailors Using Naïve Bayes</h1>
</header>
<article class="art">
<p> In 1763, Richard Price, a moral philosopher, introduced the essay, “An Essay Towards Solving a Problem in the Indoctrine of Chances,” by Thomas Bayes.
Naïve Bayes theorem is now a fundamental tool in statistical and Machine Learning. However, the origins of this tool are very unexpected.
This theorem was invented by an English Presbyterian minister in an attempt to prove God’s existence. Thomas Bayes passed away in the year 1763. <img src="images/ThomasBayes.png" class="Thomas" alt="Thomas Bayes Image"> </p>
<p> However, his essay was posthumously published in 1766 by Price. However, during the time of its publication, the essay was not given it’s right recognition, as the mathematics was too extensive to prove.
It wasn’t until the invention of the modern computer, with fast processors, that we found the full potential of this mathematical tool. </p>
<h3 class="heads">So what Is Naïve Bayes Theorem?</h3>
<p>This theorem allows us to mathematically incorporate data correctly, and calculate the probabilities of an event.
It’s a tool that is versatile because it penetrates almost all questions that come to mind, from healthcare-related probabilities to coding to presidential elections.
The Bayes’ rule helps us determine the probability that something is true with a given set of events.</p>
<strong> Bayes' Rule:</strong>
<div class="formula">
\( P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)} \)
</div>
<p> Here, A is the hypothesis and B is data. </p>
<div class="formula"> \( P(A|B) \) </div> means the probability of A given B.
<div class="formula"> \( P(B|A) \) </div>
<p> means the probability of B given A. </p>
<strong>Bayes' Rule Example:</strong>
<div class="formula">
\( P(\text{Cancer}|\text{Positive Test}) = \frac{P(\text{Positive Test}|\text{Cancer}) \cdot P(\text{Cancer})}{P(\text{Positive Test})} \)
</div>
<p>So here the initial probabilities would be based on clinical outcomes.</p>
<h3 style="text-align: left; font-style: normal; font-size: medium;"> Let’s do a few sample problems to get a gist </h3>
<h4 style="text-align: center; font-size: medium; font-style: italic; font-family: sans-serif;"> Problem 1: Breast Cancer Outcomes </h4>
<p> Suppose a mammography screening test for breast cancer has a sensitivity of 90% and a specificity of 93%.
The prevalence of breast cancer in the population is 1%. A woman undergoes a mammography screening and the test results come back positive.
What is the probability that she actually has breast cancer? </p>
<h3 >Solution:</h3>
<p>Let's define the following:</p>
<div class="formula">
<ul style="text-align: center;">
P(A) = Probability of having breast cancer = 0.01 (prevalence)
P(B|A) = Probability of testing positive given breast cancer = 0.90 (sensitivity)
P(¬A) = Probability of not having breast cancer = 1 - P(A) = 0.99
P(B|¬A) = Probability of testing positive given no breast cancer = 1 - specificity = 1 - 0.93 = 0.07
</ul>
</div>
<h4 style="text-align: center; font-size: medium; font-style: italic; font-family: sans-serif;">Now, let's apply Bayes' theorem:</h4>
<div class="formula" style="text-align: center;">
<ul>P(A|B) = (P(B|A) * P(A)) / [P(B|A) * P(A) + P(B|¬A) * P(¬A)]</ul>
<p>Substituting the values:</p>
<ul>P(A|B) = (0.90 * 0.01) / [(0.90 * 0.01) + (0.07 * 0.99)]</ul>
<ul>P(A|B) ≈ 0.1136</ul>
</div>
<p>So, the probability that the woman actually has breast cancer given a positive mammography screening result is approximately 11.36%.</p>
<h4> Problem 2: Weather Outlook </h4>
<p> Marie is getting married tomorrow at an outdoor ceremony in the desert. In recent years it has rained only 5 days, each year (5/365 = 0.014).
Unfortunately, the weatherman has predicted rain for tomorrow. When it rains the weatherman correctly forecasts the rain 90% of the time.
It is 10% of the time when it predicts it incorrectly. What is the probability that it will rain on Marie’s wedding? </p>
<h3 style="text-align: center;">Solution:</h3>
<p>Given:</p>
<ul>
<div class="formula" style="text-align: center;">
P(rain) = Probability of rain = 0.014
P(Prediction|rain) = Probability of correct prediction given rain = 0.90
P(¬rain) = Probability of no rain = 1 - P(rain) = 0.986
P(Prediction|¬rain) = Probability of incorrect prediction given no rain = 0.10
</div>
</ul>
<p> Using the provided equation:</p>
<div class="formula" style="text-align: center;">
<ul>P(rain|Prediction) = (P(Prediction|rain) * P(rain)) / P(prediction)
Calculate the denominator \( P(prediction) \):
P(prediction) = P(Prediction|rain) * P(rain) + P(Prediction|¬rain) * P(¬rain)
P(prediction) = 0.90 * 0.014 + 0.10 * 0.986 = 0.0126 + 0.0986 = 0.1112
Substitute \( P(prediction) \) back into the equation:
P(rain|Prediction) = (0.90 * 0.014) / 0.1112
P(rain|Prediction) = 0.0126 / 0.1112 ≈ 0.1132
</ul>
</div>
<p>So, the probability that it will rain on Marie's wedding given the weatherman's prediction is approximately 11.32%.</p>
<h2 style="font-size: medium; text-align: center;"> The Project </h2>
<p>In this section, we will be reviewing Naïve Bayes using Python Libraries, and the situation will be the search and rescue efforts of a fisherman.
This project is found in the 3book, “ Real World Python, a Hacker’s Guide to Solving Problems with Code,” by Lee Vaughan. This is the first Chapter of the book. </p>
<h3> The Scenario of the Project </h3>
<p>A fisherman has gone missing off the coast of a nation called python. It is our job as the coast guard to find this person.
We have already determined a location he was in 6 hours ago, based on his wife’s statements. In the last call, he radioed that he was abandoning ship but we have no clue whether he is in a life raft or whether he is floating in the sea.
Even though the water is warm around this time of the year, there is still a risk of hypothermia if the fisherman is floating in the water, especially if that’s for 12 hours or more. If the fisherman is wearing a floatation device, he can last in the water for 3 days.
The currents in the sea off of Cape Python are causing the waves to be choppy, leading to us having a hard time spotting a human in the water despite visibility being good. The wind is blowing from the southwest direction. Usually in the real world, the Coast Guard uses a system called SAROPS, an abbreviation for Coast Guard Search and Rescue Optimal Planning System.
This software it’s great because it uses factors like wind tides currents, and whether the body is underwater or on the surface. This allows it to create rectangular search areas in calculating the probabilities of finding lost sailors at Sea, and this allows the most efficient flight patterns to search for them.
So in this particular scenario SAROPS has identified at least three search areas and hear what we will do is write the program to apply the base rule to it. We already have enough resources to search for two of the three areas but will have to decide how to allocate those resources so the cost versus value has the best outcome. </p>
<h3> The Strategy </h3>
<p>Given the vastness of the sea, locating sailors or lost passengers can be a daunting task, akin to finding a needle in a haystack. Initially, we work with target probabilities based on the sealer's last known location, updating them as we obtain search results.
However, if the search yields nothing, the likelihood of the sailor being in a different area increases. This mirrors real-life situations where complications arise, potentially leading to inefficiencies in search efforts. In such cases, valuable time may be lost, and the risk to the lost sailor may escalate.
This is why the Bayes equation is so important because this way you have a better idea of where to search and you’re not using emotions or throwing shots in the dark. So to aid the search in this stimulation here is what we will do, Optimize the OpenCV Library to build an interface to work with the program. OpenCV stores properties as rows, columns, and channels.
Usually, the interface can be very simple, but we would want to have a map of this cape and the search area where we can use this map to sort of display the last position when he was lost and the position where he was found. Open CV is a great library because it allows you to display images drawings and text. </p>
<!-- Add more sections for additional content -->
<h3> The Project </h3>
<p>Click on the section below to view the Python code and the output:</p>
<button onclick="viewPythonCode()">View Python Code</button>
</article>
</body>
<footer class="copyright" style="margin-bottom: 0%;">
<p> Copyright © Kashish. Designed for excellence <i class="fa-solid fa-trophy"></i></p>
</footer>
<script>
function viewPythonCode() {
window.location.href = "bayes.html"; // Replace "baye.html" with the path to your HTML page containing the Python code
}
</script>