mirror of
https://github.com/redoules/redoules.github.io.git
synced 2025-12-12 15:59:34 +00:00
305 lines
14 KiB
HTML
305 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
|
<meta name="description" content="Data Science for Political and Social Phenomena">
|
|
<meta name="author" content="Guillaume Redoulès">
|
|
<link rel="icon" href="../favicon.ico">
|
|
|
|
<title>Day 3 - Conditionnal probability - Blog</title>
|
|
|
|
<!-- JQuery -->
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
|
<script>
|
|
window.jQuery || document.write('<script src="../theme/js/jquery.min.js"><\/script>')
|
|
</script>
|
|
|
|
<!-- Bootstrap core CSS -->
|
|
<link rel="stylesheet" href="../theme/css/bootstrap.css" />
|
|
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
|
|
<link rel="stylesheet" type="text/css" href="../theme/css/ie10-viewport-bug-workaround.css" />
|
|
<!-- Custom styles for this template -->
|
|
<link rel="stylesheet" type="text/css" href="../theme/css/style.css" />
|
|
<link rel="stylesheet" type="text/css" href="../theme/css/notebooks.css" />
|
|
<link href='https://fonts.googleapis.com/css?family=PT+Serif:400,700|Roboto:400,500,700' rel='stylesheet' type='text/css'>
|
|
|
|
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
|
<!--[if lt IE 9]>
|
|
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
|
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
|
<![endif]-->
|
|
|
|
|
|
<meta name="tags" content="Basics" />
|
|
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="navbar navbar-fixed-top">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</button>
|
|
<a class="navbar-brand" href="..">Guillaume Redoulès</a>
|
|
</div>
|
|
<div class="navbar-collapse collapse" id="searchbar">
|
|
|
|
<ul class="nav navbar-nav navbar-right">
|
|
<li class="dropdown">
|
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">About<span class="caret"></span></a>
|
|
<ul class="dropdown-menu">
|
|
<li><a href="../pages/about.html">About Guillaume</a></li>
|
|
<li><a href="https://github.com/redoules">GitHub</a></li>
|
|
<li><a href="https://www.linkedin.com/in/guillaume-redoul%C3%A8s-33923860/">LinkedIn</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="dropdown">
|
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Data Science<span class="caret"></span></a>
|
|
<ul class="dropdown-menu">
|
|
<li><a href="..#Blog">Blog</a></li>
|
|
<li><a href="..#Python">Python</a></li>
|
|
<li><a href="..#Bash">Bash</a></li>
|
|
<li><a href="..#SQL">SQL</a></li>
|
|
<li><a href="..#Mathematics">Mathematics</a></li>
|
|
<li><a href="..#Machine_Learning">Machine Learning</a></li>
|
|
<li><a href="..#Projects">Projects</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="dropdown">
|
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Projects<span class="caret"></span></a>
|
|
<ul class="dropdown-menu">
|
|
<li><a href="https://github.com/redoules/redoules.github.io">Notes (Github)</a></li>
|
|
</ul>
|
|
</li>
|
|
|
|
<!--<li class="dropdown">
|
|
<a href="../feeds/blog.rss.xml">Blog RSS</a>
|
|
</li>-->
|
|
|
|
|
|
</ul>
|
|
|
|
<form class="navbar-form" action="../search.html" onsubmit="return validateForm(this.elements['q'].value);">
|
|
<div class="form-group" style="display:inline;">
|
|
<div class="input-group" style="display:table;">
|
|
<span class="input-group-addon" style="width:1%;"><span class="glyphicon glyphicon-search"></span></span>
|
|
<input class="form-control search-query" name="q" id="tipue_search_input" placeholder="e.g. scikit KNN, pandas merge" required autocomplete="off" type="text">
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
</div>
|
|
<!--/.nav-collapse -->
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<!-- end of header section -->
|
|
<div class="container">
|
|
<!-- <div class="alert alert-warning" role="alert">
|
|
Did you find this page useful? Please do me a quick favor and <a href="#" class="alert-link">endorse me for data science on LinkedIn</a>.
|
|
</div> -->
|
|
<section id="content" class="body">
|
|
<header>
|
|
<h1>
|
|
Day 3 - Conditionnal probability
|
|
</h1>
|
|
<ol class="breadcrumb">
|
|
<li>
|
|
<time class="published" datetime="2018-11-10T11:24:00+01:00">
|
|
10 novembre 2018
|
|
</time>
|
|
</li>
|
|
<li>Blog</li>
|
|
<li>Basics</li>
|
|
</ol>
|
|
</header>
|
|
<div class='article_content'>
|
|
<h2>Conditionnal probability</h2>
|
|
<h3>Problem</h3>
|
|
<p>Suppose a family has 2 children, one of which is a boy. What is the probability that both children are boys?</p>
|
|
<h3>Mathematical explanation</h3>
|
|
<p>Let's look at the possible outcomes :
|
|
<div>
|
|
<style scoped="">
|
|
.dataframe tbody tr th:only-of-type {
|
|
vertical-align: middle;
|
|
}</p>
|
|
<div class="highlight"><pre><span></span><span class="na">.dataframe</span> <span class="no">tbody</span> <span class="no">tr</span> <span class="no">th</span> <span class="err">{</span>
|
|
<span class="nl">vertical-align:</span> <span class="nf">top</span><span class="c">;</span>
|
|
<span class="err">}</span>
|
|
|
|
<span class="na">.dataframe</span> <span class="no">thead</span> <span class="no">th</span> <span class="err">{</span>
|
|
<span class="nl">text-align:</span> <span class="nf">right</span><span class="c">;</span>
|
|
<span class="err">}</span>
|
|
</pre></div>
|
|
|
|
|
|
<p></style>
|
|
<table class="dataframe" border="1">
|
|
<thead>
|
|
<tr style="text-align: right;">
|
|
<th></th>
|
|
<th>B</th>
|
|
<th>G</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<th>B</th>
|
|
<td>BB</td>
|
|
<td>BG</td>
|
|
</tr>
|
|
<tr>
|
|
<th>G</th>
|
|
<td>GB</td>
|
|
<td>GG</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div></p>
|
|
<p>We know that at least one of the children is a boy, so only "GG" is not possible. The event where the family has a new boy is then "BB". Hence the probability is :
|
|
</p>
|
|
<div class="math">$$\frac{BB}{BB+GB+BG}=\frac{1}{3}$$</div>
|
|
<h2>Draw 2 cards from a deck</h2>
|
|
<h3>Problem</h3>
|
|
<p>You 2 draw cards from a standard 52-card deck without replacing them. What is the probability that both cards are of the same suit?</p>
|
|
<h3>Mathematical explanation</h3>
|
|
<p>There are 13 cards of each suit. Draw one card. It can be anything with probability of 1. Now there are 51 cards left and 12 of them are the same suit as the first card you drew. So the chance the second card matches the 1st is <span class="math">\(\frac{12}{51}\)</span>.</p>
|
|
<h2>Drawing marbles</h2>
|
|
<h3>Problem</h3>
|
|
<p>A bag contains 3 red marbles and 4 blue marbles. Then, 2 marbles are drawn from the bag, at random, without replacement. If the first marble drawn is red, what is the probability that the second marble is blue?</p>
|
|
<h3>Mathematical explanation</h3>
|
|
<p>On the first draw, the probabilities are the following :
|
|
we call B the event "a blue ball is drawn" and R the event "a red ball is drawn"
|
|
* <span class="math">\(P(B)=\frac{4}{7}\)</span>
|
|
* <span class="math">\(P(R)=\frac{3}{7}\)</span></p>
|
|
<p>On the second draw, if a red ball has been drawn at first, the probabilities are :
|
|
* <span class="math">\(P(B|R)=\frac{4}{6}\)</span>
|
|
* <span class="math">\(P(R|R)=\frac{2}{6}\)</span></p>
|
|
<p>Hence, the probability of drawing a blue ball if the first ball drawn was red is <span class="math">\(\frac{1}{3}\)</span></p>
|
|
<script type="text/javascript">if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
|
|
var align = "center",
|
|
indent = "0em",
|
|
linebreak = "false";
|
|
|
|
if (false) {
|
|
align = (screen.width < 768) ? "left" : align;
|
|
indent = (screen.width < 768) ? "0em" : indent;
|
|
linebreak = (screen.width < 768) ? 'true' : linebreak;
|
|
}
|
|
|
|
var mathjaxscript = document.createElement('script');
|
|
mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
|
|
mathjaxscript.type = 'text/javascript';
|
|
mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';
|
|
mathjaxscript[(window.opera ? "innerHTML" : "text")] =
|
|
"MathJax.Hub.Config({" +
|
|
" config: ['MMLorHTML.js']," +
|
|
" TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'AMS' } }," +
|
|
" jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
|
|
" extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
|
|
" displayAlign: '"+ align +"'," +
|
|
" displayIndent: '"+ indent +"'," +
|
|
" showMathMenu: true," +
|
|
" messageStyle: 'normal'," +
|
|
" tex2jax: { " +
|
|
" inlineMath: [ ['\\\\(','\\\\)'] ], " +
|
|
" displayMath: [ ['$$','$$'] ]," +
|
|
" processEscapes: true," +
|
|
" preview: 'TeX'," +
|
|
" }, " +
|
|
" 'HTML-CSS': { " +
|
|
" styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
|
|
" linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
|
|
" }, " +
|
|
"}); " +
|
|
"if ('default' !== 'default') {" +
|
|
"MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
|
|
"var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
|
|
"VARIANT['normal'].fonts.unshift('MathJax_default');" +
|
|
"VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
|
|
"VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
|
|
"VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
|
|
"});" +
|
|
"MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
|
|
"var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
|
|
"VARIANT['normal'].fonts.unshift('MathJax_default');" +
|
|
"VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
|
|
"VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
|
|
"VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
|
|
"});" +
|
|
"}";
|
|
(document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
|
|
}</script>
|
|
</div>
|
|
<aside>
|
|
<div class="bug-reporting__panel">
|
|
<h3>Find an error or bug? Have a suggestion?</h3>
|
|
<p>Everything on this site is avaliable on GitHub. Head on over and <a href='https://github.com/redoules/redoules.github.io/issues/new'>submit an issue.</a> You can also message me directly by <a href='mailto:guillaume.redoules@gadz.org'>email</a>.</p>
|
|
</div>
|
|
</aside>
|
|
</section>
|
|
|
|
</div>
|
|
<!-- start of footer section -->
|
|
<footer class="footer">
|
|
<div class="container">
|
|
<p class="text-muted">
|
|
<center>This project contains 115 pages and is available on <a href="https://github.com/redoules/redoules.github.io">GitHub</a>.
|
|
<br/>
|
|
Copyright © Guillaume Redoulès,
|
|
<time datetime="2018">2018</time>.
|
|
</center>
|
|
</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<!-- This jQuery line finds any span that contains code highlighting classes and then selects the parent <pre> tag and adds a border. This is done as a workaround to visually distinguish the code inputs and outputs -->
|
|
<script>
|
|
$( ".hll, .n, .c, .err, .k, .o, .cm, .cp, .c1, .cs, .gd, .ge, .gr, .gh, .gi, .go, .gp, .gs, .gu, .gt, .kc, .kd, .kn, .kp, .kr, .kt, .m, .s, .na, .nb, .nc, .no, .nd, .ni, .ne, .nf, .nl, .nn, .nt, .nv, .ow, .w, .mf, .mh, .mi, .mo, .sb, .sc, .sd, .s2, .se, .sh, .si, .sx, .sr, .s1, .ss, .bp, .vc, .vg, .vi, .il" ).parent( "pre" ).css( "border", "1px solid #DEDEDE" );
|
|
</script>
|
|
|
|
|
|
<!-- Load Google Analytics -->
|
|
<script>
|
|
/*
|
|
(function(i, s, o, g, r, a, m) {
|
|
i['GoogleAnalyticsObject'] = r;
|
|
i[r] = i[r] || function() {
|
|
(i[r].q = i[r].q || []).push(arguments)
|
|
}, i[r].l = 1 * new Date();
|
|
a = s.createElement(o),
|
|
m = s.getElementsByTagName(o)[0];
|
|
a.async = 1;
|
|
a.src = g;
|
|
m.parentNode.insertBefore(a, m)
|
|
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
|
|
|
|
ga('create', 'UA-66582-32', 'auto');
|
|
ga('send', 'pageview');
|
|
*/
|
|
</script>
|
|
<!-- End of Google Analytics -->
|
|
|
|
<!-- Bootstrap core JavaScript
|
|
================================================== -->
|
|
<!-- Placed at the end of the document so the pages load faster -->
|
|
<script src="../theme/js/bootstrap.min.js"></script>
|
|
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
|
|
<script src="../theme/js/ie10-viewport-bug-workaround.js"></script>
|
|
|
|
|
|
</body>
|
|
|
|
</html> |