Jekyll2022-07-22T08:49:06-05:00https://unna97.github.io/maths-havard-stats-110/feed.xmlStatisticsStuff related to statisticsThe Birthday Problem2020-06-05T00:00:00-05:002020-06-05T00:00:00-05:00https://unna97.github.io/maths-havard-stats-110/birthday%20problem/jupyter/birthday%20paradox/hashing/simulations/2020/06/05/Birthday-Problem<!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: _notebooks/2020-06-05-Birthday-Problem.ipynb
-->
<div class="container" id="notebook-container">
<div class="cell border-box-sizing code_cell rendered">
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="What-is-the-Birthday-Problem-aka-Birthday-Paradox?">What is the Birthday Problem aka Birthday Paradox?<a class="anchor-link" href="#What-is-the-Birthday-Problem-aka-Birthday-Paradox?"> </a></h2><p>First of all,it is not really a parado
Suppose you are attending a party.
How big do you think the party has to be in order to be that there are two people in the party with the same birthday?
Assume, every birthday is equally likely</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="n">x</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">input</span><span class="p">(</span><span class="s2">"Put your guess in here:"</span><span class="p">))</span>
<span class="k">if</span> <span class="n">x</span> <span class="o"><</span> <span class="mi">23</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Too low..wow your intution is wrong on the opposite way than most people XD"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">x</span> <span class="o">></span> <span class="mi">23</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"That's too high,read on to find out why"</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Perfect,You have seen this problem before haven't you?"</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>Put your guess in here:185
That's too high,read on to find out why
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="The-math-(stuff-that-goes-over-my-head-on-the-first-read):">The math (stuff that goes over my head on the first read):<a class="anchor-link" href="#The-math-(stuff-that-goes-over-my-head-on-the-first-read):"> </a></h2><p>Let 'n' be the number of people at party.</p>
<p>Let's assume that everyone in the party has a different birthday.</p>
<p>What is the probablity 'q' of that happening?</p>
<p>if n = 2:</p>
<pre><code>number of choices for first birthday,b1 = 365
number of choices for second birthday,b2 = (365 - 1) = 364 (Anything other than first birthday)
probablity of choosing the particular day as first birthday = 1/365
probablity of choosing the particular day as second birthday = 1/365
reason: probablity of choosing any number from 365 choices = 1/365
q(n = 2) = (365 x (1/365)) x ((364) x (1/365)) = 364/365
</code></pre>
<p>if n = 3:</p>
<pre><code>similarly,
b1 = 365
b2 = 365 - 1 = 364
b3 = 365 - 2 = 363 (anything other than 2 already choosen)
q(n = 3) = (365 x (1/365)) x ((364) x (1/365)) x (363 x (1/365)) = (364 x 363)/(365 x 365)
</code></pre>
<p>hence:</p>
<pre><code>q(n) = (364 x 363 x 362 x .... (365 - (n - 1))) / (365)^(n - 1)
= (365!)/ ((365^n) x ((n - 1)!))
</code></pre>
<p>The above calculates the formula for party of 'n' people all with unique birthday.</p>
<p>Now the only two scenarios possible are :</p>
<p>either there is some birthday match or there is none</p>
<p>By law of total probablity:
p(n) + q(n) = 1
where, p(n) is the probablity there is a birthday match
therefore:
p(n) = 1 - q(n)</p>
<p>Using the above formulas,the</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="k">def</span> <span class="nf">q</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">choices</span> <span class="o">=</span> <span class="mi">365</span><span class="p">):</span>
<span class="n">q</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="n">choices</span> <span class="o">-</span> <span class="n">i</span><span class="p">)</span><span class="o">/</span><span class="n">choices</span>
<span class="n">q</span> <span class="o">*=</span> <span class="n">x</span>
<span class="k">return</span> <span class="p">(</span><span class="n">q</span><span class="p">)</span> <span class="c1">#at max it is 1</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="k">def</span> <span class="nf">p</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">choices</span> <span class="o">=</span> <span class="mi">365</span><span class="p">):</span>
<span class="k">return</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">q</span><span class="p">(</span><span class="n">n</span><span class="p">,</span><span class="n">choices</span><span class="p">))</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Probablity-of-your-guess-(in-%):">Probablity of your guess (in %):<a class="anchor-link" href="#Probablity-of-your-guess-(in-%):"> </a></h3><p>note: Python tends to approximate 99.99999... to 100</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"p(x):"</span><span class="p">,</span><span class="mi">100</span> <span class="o">*</span> <span class="n">p</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"q(x):"</span><span class="p">,</span><span class="mi">100</span> <span class="o">*</span><span class="n">q</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> <span class="c1">#for higher guesses comes to 100 because 99.99999</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>p(x): 100.0
q(x): 1.1819355706789237e-23
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Probablity-at-23:">Probablity at 23:<a class="anchor-link" href="#Probablity-at-23:"> </a></h3>
<pre><code>(The magic number)
If you reverse the above calculation the number that is closest for 50% is 23</code></pre>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"p(23):"</span><span class="p">,</span><span class="mi">100</span> <span class="o">*</span> <span class="n">p</span><span class="p">(</span><span class="mi">23</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"q(23):"</span><span class="p">,</span><span class="mi">100</span> <span class="o">*</span><span class="n">q</span><span class="p">(</span><span class="mi">23</span><span class="p">))</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>p(23): 50.729723432398565
q(23): 49.27027656760144
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="It-still-isn't-believable,-simulate-it:">It still isn't believable, simulate it:<a class="anchor-link" href="#It-still-isn't-believable,-simulate-it:"> </a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Why-is-(most-of-the-time)-our-guess-is-too-high?">Why is (most of the time) our guess is too high?<a class="anchor-link" href="#Why-is-(most-of-the-time)-our-guess-is-too-high?"> </a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>As,
the number of people grow linearly : n (i.e 1,2,3,4,5,6,..)
the number of pairs grow quadratically : (n x (n - 1)/2) (i.e 0,1,3,6,10..)
The animation below shows how the "pairs" (representated by edges increase) as number of people (representated by nodes) increase</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="c1">#imports</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">import</span> <span class="nn">matplotlib.animation</span>
<span class="kn">from</span> <span class="nn">moviepy.editor</span> <span class="kn">import</span> <span class="o">*</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="c1">#intializations</span>
<span class="n">birthdays_possible</span> <span class="o">=</span> <span class="mi">365</span>
<span class="n">X</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">Graph</span><span class="p">()</span>
<span class="n">X</span><span class="o">.</span><span class="n">add_node</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="n">birthdays</span> <span class="o">=</span> <span class="p">[</span><span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">birthdays_possible</span><span class="p">))]</span>
<span class="n">match</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span>
<span class="n">plt</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="n">num</span><span class="p">):</span>
<span class="n">ax</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
<span class="k">if</span> <span class="n">num</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span>
<span class="n">birthdays</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="n">birthdays_possible</span><span class="p">)))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">birthdays</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">num</span><span class="p">):</span>
<span class="n">X</span><span class="o">.</span><span class="n">add_edge</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="n">num</span><span class="p">)</span>
<span class="k">if</span> <span class="n">birthdays</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">birthdays</span><span class="p">[</span><span class="n">num</span><span class="p">]:</span>
<span class="n">match</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'r'</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">match</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'k'</span><span class="p">)</span>
<span class="n">nx</span><span class="o">.</span><span class="n">draw_circular</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">ax</span><span class="p">,</span> <span class="n">with_labels</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">node_color</span> <span class="o">=</span> <span class="n">birthdays</span><span class="p">,</span><span class="n">edged_color</span> <span class="o">=</span> <span class="n">match</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="n">ani</span> <span class="o">=</span> <span class="n">matplotlib</span><span class="o">.</span><span class="n">animation</span><span class="o">.</span><span class="n">FuncAnimation</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">update</span><span class="p">,</span> <span class="n">frames</span><span class="o">=</span> <span class="mi">25</span><span class="p">,</span> <span class="n">interval</span><span class="o">=</span> <span class="mi">2000</span><span class="p">,</span> <span class="n">repeat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"birthdays selected in the animation:"</span><span class="p">)</span>
<span class="n">ani</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s1">'birthday.mp4'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>birthdays selected in the animation:
[7]
[7]
[7, 27]
[7, 27, 18]
[7, 27, 18, 182]
[7, 27, 18, 182, 222]
[7, 27, 18, 182, 222, 295]
[7, 27, 18, 182, 222, 295, 222]
[7, 27, 18, 182, 222, 295, 222, 278]
[7, 27, 18, 182, 222, 295, 222, 278, 128]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300, 203]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300, 203, 18]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300, 203, 18, 360]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300, 203, 18, 360, 63]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300, 203, 18, 360, 63, 115]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300, 203, 18, 360, 63, 115, 219]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300, 203, 18, 360, 63, 115, 219, 158]
[7, 27, 18, 182, 222, 295, 222, 278, 128, 343, 185, 342, 110, 258, 217, 147, 300, 203, 18, 360, 63, 115, 219, 158, 242]
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="k">def</span> <span class="nf">is_there_a_match</span><span class="p">(</span><span class="n">birthdays</span><span class="p">):</span>
<span class="k">return</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">birthdays</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">birthdays</span><span class="p">)))</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="n">is_there_a_match</span><span class="p">(</span><span class="n">birthdays</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_text output_subarea output_execute_result">
<pre>True</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="n">clip</span> <span class="o">=</span> <span class="p">(</span><span class="n">VideoFileClip</span><span class="p">(</span><span class="s2">"birthday.mp4"</span><span class="p">))</span>
<span class="n">clip</span><span class="o">.</span><span class="n">write_gif</span><span class="p">(</span><span class="s2">"birthday.gif"</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><img src="https://raw.githubusercontent.com/unna97/maths-havard-stats-110/master/images/birthday.gif" alt="" /></p>
</div>
</div>
</div>
</div>Unnati PatelFastpages Notebook Blog Post2020-02-20T00:00:00-06:002020-02-20T00:00:00-06:00https://unna97.github.io/maths-havard-stats-110/jupyter/2020/02/20/test<!--
#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: _notebooks/2020-02-20-test.ipynb
-->
<div class="container" id="notebook-container">
<div class="cell border-box-sizing code_cell rendered">
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="About">About<a class="anchor-link" href="#About"> </a></h1><p>This notebook is a demonstration of some of capabilities of <a href="https://github.com/fastai/fastpages">fastpages</a> with notebooks.</p>
<p>With <code>fastpages</code> you can save your jupyter notebooks into the <code>_notebooks</code> folder at the root of your repository, and they will be automatically be converted to Jekyll compliant blog posts!</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Front-Matter">Front Matter<a class="anchor-link" href="#Front-Matter"> </a></h2><p>The first cell in your Jupyter Notebook or markdown blog post contains front matter. Front matter is metadata that can turn on/off options in your Notebook. It is formatted like this:</p>
<pre><code># Title
> Awesome summary
- toc:true- branch: master- badges: true- comments: true
- author: Hamel Husain & Jeremy Howard
- categories: [fastpages, jupyter]</code></pre>
<ul>
<li>Setting <code>toc: true</code> will automatically generate a table of contents</li>
<li>Setting <code>badges: true</code> will automatically include GitHub and Google Colab links to your notebook.</li>
<li>Setting <code>comments: true</code> will enable commenting on your blog post, powered by <a href="https://github.com/utterance/utterances">utterances</a>.</li>
</ul>
<p>More details and options for front matter can be viewed on the <a href="https://github.com/fastai/fastpages#front-matter-related-options">front matter section</a> of the README.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Markdown-Shortcuts">Markdown Shortcuts<a class="anchor-link" href="#Markdown-Shortcuts"> </a></h2>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>A <code>#hide</code> comment at the top of any code cell will hide <strong>both the input and output</strong> of that cell in your blog post.</p>
<p>A <code>#hide_input</code> comment at the top of any code cell will <strong>only hide the input</strong> of that cell.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_subarea output_stream output_stdout output_text">
<pre>The comment #hide_input was used to hide the code that produced this.
</pre>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>put a <code>#collapse-hide</code> flag at the top of any cell if you want to <strong>hide</strong> that cell by default, but give the reader the option to show it:</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-hide</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">altair</span> <span class="k">as</span> <span class="nn">alt</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>put a <code>#collapse-show</code> flag at the top of any cell if you want to <strong>show</strong> that cell by default, but give the reader the option to hide it:</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<details class="description" open="">
<summary class="btn btn-sm" data-open="Hide Code" data-close="Show Code"></summary>
<p><div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#collapse-show</span>
<span class="n">cars</span> <span class="o">=</span> <span class="s1">'https://vega.github.io/vega-datasets/data/cars.json'</span>
<span class="n">movies</span> <span class="o">=</span> <span class="s1">'https://vega.github.io/vega-datasets/data/movies.json'</span>
<span class="n">sp500</span> <span class="o">=</span> <span class="s1">'https://vega.github.io/vega-datasets/data/sp500.csv'</span>
<span class="n">stocks</span> <span class="o">=</span> <span class="s1">'https://vega.github.io/vega-datasets/data/stocks.csv'</span>
<span class="n">flights</span> <span class="o">=</span> <span class="s1">'https://vega.github.io/vega-datasets/data/flights-5k.json'</span>
</pre></div>
</div>
</div>
</div>
</p>
</details>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Interactive-Charts-With-Altair">Interactive Charts With Altair<a class="anchor-link" href="#Interactive-Charts-With-Altair"> </a></h2><p>Charts made with Altair remain interactive. Example charts taken from <a href="https://github.com/uwdata/visualization-curriculum">this repo</a>, specifically <a href="https://github.com/uwdata/visualization-curriculum/blob/master/altair_interaction.ipynb">this notebook</a>.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Example-1:-DropDown">Example 1: DropDown<a class="anchor-link" href="#Example-1:-DropDown"> </a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># single-value selection over [Major_Genre, MPAA_Rating] pairs</span>
<span class="c1"># use specific hard-wired values as the initial selected values</span>
<span class="n">selection</span> <span class="o">=</span> <span class="n">alt</span><span class="o">.</span><span class="n">selection_single</span><span class="p">(</span>
<span class="n">name</span><span class="o">=</span><span class="s1">'Select'</span><span class="p">,</span>
<span class="n">fields</span><span class="o">=</span><span class="p">[</span><span class="s1">'Major_Genre'</span><span class="p">,</span> <span class="s1">'MPAA_Rating'</span><span class="p">],</span>
<span class="n">init</span><span class="o">=</span><span class="p">{</span><span class="s1">'Major_Genre'</span><span class="p">:</span> <span class="s1">'Drama'</span><span class="p">,</span> <span class="s1">'MPAA_Rating'</span><span class="p">:</span> <span class="s1">'R'</span><span class="p">},</span>
<span class="n">bind</span><span class="o">=</span><span class="p">{</span><span class="s1">'Major_Genre'</span><span class="p">:</span> <span class="n">alt</span><span class="o">.</span><span class="n">binding_select</span><span class="p">(</span><span class="n">options</span><span class="o">=</span><span class="n">genres</span><span class="p">),</span> <span class="s1">'MPAA_Rating'</span><span class="p">:</span> <span class="n">alt</span><span class="o">.</span><span class="n">binding_radio</span><span class="p">(</span><span class="n">options</span><span class="o">=</span><span class="n">mpaa</span><span class="p">)}</span>
<span class="p">)</span>
<span class="c1"># scatter plot, modify opacity based on selection</span>
<span class="n">alt</span><span class="o">.</span><span class="n">Chart</span><span class="p">(</span><span class="n">movies</span><span class="p">)</span><span class="o">.</span><span class="n">mark_circle</span><span class="p">()</span><span class="o">.</span><span class="n">add_selection</span><span class="p">(</span>
<span class="n">selection</span>
<span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span>
<span class="n">x</span><span class="o">=</span><span class="s1">'Rotten_Tomatoes_Rating:Q'</span><span class="p">,</span>
<span class="n">y</span><span class="o">=</span><span class="s1">'IMDB_Rating:Q'</span><span class="p">,</span>
<span class="n">tooltip</span><span class="o">=</span><span class="s1">'Title:N'</span><span class="p">,</span>
<span class="n">opacity</span><span class="o">=</span><span class="n">alt</span><span class="o">.</span><span class="n">condition</span><span class="p">(</span><span class="n">selection</span><span class="p">,</span> <span class="n">alt</span><span class="o">.</span><span class="n">value</span><span class="p">(</span><span class="mf">0.75</span><span class="p">),</span> <span class="n">alt</span><span class="o">.</span><span class="n">value</span><span class="p">(</span><span class="mf">0.05</span><span class="p">))</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_html rendered_html output_subarea output_execute_result">
<div id="altair-viz-1a49e83878ce4d678d7b162f3d6b510f"></div>
<script type="text/javascript">
(function(spec, embedOpt){
const outputDiv = document.getElementById("altair-viz-1a49e83878ce4d678d7b162f3d6b510f");
const paths = {
"vega": "https://cdn.jsdelivr.net/npm//vega@5?noext",
"vega-lib": "https://cdn.jsdelivr.net/npm//vega-lib?noext",
"vega-lite": "https://cdn.jsdelivr.net/npm//vega-lite@4.0.2?noext",
"vega-embed": "https://cdn.jsdelivr.net/npm//vega-embed@6?noext",
};
function loadScript(lib) {
return new Promise(function(resolve, reject) {
var s = document.createElement('script');
s.src = paths[lib];
s.async = true;
s.onload = () => resolve(paths[lib]);
s.onerror = () => reject(`Error loading script: ${paths[lib]}`);
document.getElementsByTagName("head")[0].appendChild(s);
});
}
function showError(err) {
outputDiv.innerHTML = `<div class="error" style="color:red;">${err}</div>`;
throw err;
}
function displayChart(vegaEmbed) {
vegaEmbed(outputDiv, spec, embedOpt)
.catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));
}
if(typeof define === "function" && define.amd) {
requirejs.config({paths});
require(["vega-embed"], displayChart, err => showError(`Error loading script: ${err.message}`));
} else if (typeof vegaEmbed === "function") {
displayChart(vegaEmbed);
} else {
loadScript("vega")
.then(() => loadScript("vega-lite"))
.then(() => loadScript("vega-embed"))
.catch(showError)
.then(() => displayChart(vegaEmbed));
}
})({"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}}, "data": {"url": "https://vega.github.io/vega-datasets/data/movies.json"}, "mark": "circle", "encoding": {"opacity": {"condition": {"value": 0.75, "selection": "Select"}, "value": 0.05}, "tooltip": {"type": "nominal", "field": "Title"}, "x": {"type": "quantitative", "field": "Rotten_Tomatoes_Rating"}, "y": {"type": "quantitative", "field": "IMDB_Rating"}}, "selection": {"Select": {"type": "single", "fields": ["Major_Genre", "MPAA_Rating"], "init": {"Major_Genre": "Drama", "MPAA_Rating": "R"}, "bind": {"Major_Genre": {"input": "select", "options": ["Action", "Adventure", "Black Comedy", "Comedy", "Concert/Performance", "Documentary", "Drama", "Horror", "Musical", "Romantic Comedy", "Thriller/Suspense", "Western"]}, "MPAA_Rating": {"input": "radio", "options": ["G", "PG", "PG-13", "R", "NC-17", "Not Rated"]}}}}, "$schema": "https://vega.github.io/schema/vega-lite/v4.0.2.json"}, {"mode": "vega-lite"});
</script>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Example-2:-Tooltips">Example 2: Tooltips<a class="anchor-link" href="#Example-2:-Tooltips"> </a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">alt</span><span class="o">.</span><span class="n">Chart</span><span class="p">(</span><span class="n">movies</span><span class="p">)</span><span class="o">.</span><span class="n">mark_circle</span><span class="p">()</span><span class="o">.</span><span class="n">add_selection</span><span class="p">(</span>
<span class="n">alt</span><span class="o">.</span><span class="n">selection_interval</span><span class="p">(</span><span class="n">bind</span><span class="o">=</span><span class="s1">'scales'</span><span class="p">,</span> <span class="n">encodings</span><span class="o">=</span><span class="p">[</span><span class="s1">'x'</span><span class="p">])</span>
<span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span>
<span class="n">x</span><span class="o">=</span><span class="s1">'Rotten_Tomatoes_Rating:Q'</span><span class="p">,</span>
<span class="n">y</span><span class="o">=</span><span class="n">alt</span><span class="o">.</span><span class="n">Y</span><span class="p">(</span><span class="s1">'IMDB_Rating:Q'</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="n">alt</span><span class="o">.</span><span class="n">Axis</span><span class="p">(</span><span class="n">minExtent</span><span class="o">=</span><span class="mi">30</span><span class="p">)),</span> <span class="c1"># use min extent to stabilize axis title placement</span>
<span class="n">tooltip</span><span class="o">=</span><span class="p">[</span><span class="s1">'Title:N'</span><span class="p">,</span> <span class="s1">'Release_Date:N'</span><span class="p">,</span> <span class="s1">'IMDB_Rating:Q'</span><span class="p">,</span> <span class="s1">'Rotten_Tomatoes_Rating:Q'</span><span class="p">]</span>
<span class="p">)</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span>
<span class="n">width</span><span class="o">=</span><span class="mi">600</span><span class="p">,</span>
<span class="n">height</span><span class="o">=</span><span class="mi">400</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_html rendered_html output_subarea output_execute_result">
<div id="altair-viz-c022b476f4fb482ca6f609bf6ed082d2"></div>
<script type="text/javascript">
(function(spec, embedOpt){
const outputDiv = document.getElementById("altair-viz-c022b476f4fb482ca6f609bf6ed082d2");
const paths = {
"vega": "https://cdn.jsdelivr.net/npm//vega@5?noext",
"vega-lib": "https://cdn.jsdelivr.net/npm//vega-lib?noext",
"vega-lite": "https://cdn.jsdelivr.net/npm//vega-lite@4.0.2?noext",
"vega-embed": "https://cdn.jsdelivr.net/npm//vega-embed@6?noext",
};
function loadScript(lib) {
return new Promise(function(resolve, reject) {
var s = document.createElement('script');
s.src = paths[lib];
s.async = true;
s.onload = () => resolve(paths[lib]);
s.onerror = () => reject(`Error loading script: ${paths[lib]}`);
document.getElementsByTagName("head")[0].appendChild(s);
});
}
function showError(err) {
outputDiv.innerHTML = `<div class="error" style="color:red;">${err}</div>`;
throw err;
}
function displayChart(vegaEmbed) {
vegaEmbed(outputDiv, spec, embedOpt)
.catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));
}
if(typeof define === "function" && define.amd) {
requirejs.config({paths});
require(["vega-embed"], displayChart, err => showError(`Error loading script: ${err.message}`));
} else if (typeof vegaEmbed === "function") {
displayChart(vegaEmbed);
} else {
loadScript("vega")
.then(() => loadScript("vega-lite"))
.then(() => loadScript("vega-embed"))
.catch(showError)
.then(() => displayChart(vegaEmbed));
}
})({"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}}, "data": {"url": "https://vega.github.io/vega-datasets/data/movies.json"}, "mark": "circle", "encoding": {"tooltip": [{"type": "nominal", "field": "Title"}, {"type": "nominal", "field": "Release_Date"}, {"type": "quantitative", "field": "IMDB_Rating"}, {"type": "quantitative", "field": "Rotten_Tomatoes_Rating"}], "x": {"type": "quantitative", "field": "Rotten_Tomatoes_Rating"}, "y": {"type": "quantitative", "axis": {"minExtent": 30}, "field": "IMDB_Rating"}}, "height": 400, "selection": {"selector001": {"type": "interval", "bind": "scales", "encodings": ["x"]}}, "width": 600, "$schema": "https://vega.github.io/schema/vega-lite/v4.0.2.json"}, {"mode": "vega-lite"});
</script>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Example-3:-More-Tooltips">Example 3: More Tooltips<a class="anchor-link" href="#Example-3:-More-Tooltips"> </a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># select a point for which to provide details-on-demand</span>
<span class="n">label</span> <span class="o">=</span> <span class="n">alt</span><span class="o">.</span><span class="n">selection_single</span><span class="p">(</span>
<span class="n">encodings</span><span class="o">=</span><span class="p">[</span><span class="s1">'x'</span><span class="p">],</span> <span class="c1"># limit selection to x-axis value</span>
<span class="n">on</span><span class="o">=</span><span class="s1">'mouseover'</span><span class="p">,</span> <span class="c1"># select on mouseover events</span>
<span class="n">nearest</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="c1"># select data point nearest the cursor</span>
<span class="n">empty</span><span class="o">=</span><span class="s1">'none'</span> <span class="c1"># empty selection includes no data points</span>
<span class="p">)</span>
<span class="c1"># define our base line chart of stock prices</span>
<span class="n">base</span> <span class="o">=</span> <span class="n">alt</span><span class="o">.</span><span class="n">Chart</span><span class="p">()</span><span class="o">.</span><span class="n">mark_line</span><span class="p">()</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span>
<span class="n">alt</span><span class="o">.</span><span class="n">X</span><span class="p">(</span><span class="s1">'date:T'</span><span class="p">),</span>
<span class="n">alt</span><span class="o">.</span><span class="n">Y</span><span class="p">(</span><span class="s1">'price:Q'</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="n">alt</span><span class="o">.</span><span class="n">Scale</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="s1">'log'</span><span class="p">)),</span>
<span class="n">alt</span><span class="o">.</span><span class="n">Color</span><span class="p">(</span><span class="s1">'symbol:N'</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">alt</span><span class="o">.</span><span class="n">layer</span><span class="p">(</span>
<span class="n">base</span><span class="p">,</span> <span class="c1"># base line chart</span>
<span class="c1"># add a rule mark to serve as a guide line</span>
<span class="n">alt</span><span class="o">.</span><span class="n">Chart</span><span class="p">()</span><span class="o">.</span><span class="n">mark_rule</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="s1">'#aaa'</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span>
<span class="n">x</span><span class="o">=</span><span class="s1">'date:T'</span>
<span class="p">)</span><span class="o">.</span><span class="n">transform_filter</span><span class="p">(</span><span class="n">label</span><span class="p">),</span>
<span class="c1"># add circle marks for selected time points, hide unselected points</span>
<span class="n">base</span><span class="o">.</span><span class="n">mark_circle</span><span class="p">()</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span>
<span class="n">opacity</span><span class="o">=</span><span class="n">alt</span><span class="o">.</span><span class="n">condition</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">alt</span><span class="o">.</span><span class="n">value</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">alt</span><span class="o">.</span><span class="n">value</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
<span class="p">)</span><span class="o">.</span><span class="n">add_selection</span><span class="p">(</span><span class="n">label</span><span class="p">),</span>
<span class="c1"># add white stroked text to provide a legible background for labels</span>
<span class="n">base</span><span class="o">.</span><span class="n">mark_text</span><span class="p">(</span><span class="n">align</span><span class="o">=</span><span class="s1">'left'</span><span class="p">,</span> <span class="n">dx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">dy</span><span class="o">=-</span><span class="mi">5</span><span class="p">,</span> <span class="n">stroke</span><span class="o">=</span><span class="s1">'white'</span><span class="p">,</span> <span class="n">strokeWidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span>
<span class="n">text</span><span class="o">=</span><span class="s1">'price:Q'</span>
<span class="p">)</span><span class="o">.</span><span class="n">transform_filter</span><span class="p">(</span><span class="n">label</span><span class="p">),</span>
<span class="c1"># add text labels for stock prices</span>
<span class="n">base</span><span class="o">.</span><span class="n">mark_text</span><span class="p">(</span><span class="n">align</span><span class="o">=</span><span class="s1">'left'</span><span class="p">,</span> <span class="n">dx</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">dy</span><span class="o">=-</span><span class="mi">5</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span>
<span class="n">text</span><span class="o">=</span><span class="s1">'price:Q'</span>
<span class="p">)</span><span class="o">.</span><span class="n">transform_filter</span><span class="p">(</span><span class="n">label</span><span class="p">),</span>
<span class="n">data</span><span class="o">=</span><span class="n">stocks</span>
<span class="p">)</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span>
<span class="n">width</span><span class="o">=</span><span class="mi">700</span><span class="p">,</span>
<span class="n">height</span><span class="o">=</span><span class="mi">400</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_html rendered_html output_subarea output_execute_result">
<div id="altair-viz-9283d3681fd24aafa3d1e2f9ad193ecf"></div>
<script type="text/javascript">
(function(spec, embedOpt){
const outputDiv = document.getElementById("altair-viz-9283d3681fd24aafa3d1e2f9ad193ecf");
const paths = {
"vega": "https://cdn.jsdelivr.net/npm//vega@5?noext",
"vega-lib": "https://cdn.jsdelivr.net/npm//vega-lib?noext",
"vega-lite": "https://cdn.jsdelivr.net/npm//vega-lite@4.0.2?noext",
"vega-embed": "https://cdn.jsdelivr.net/npm//vega-embed@6?noext",
};
function loadScript(lib) {
return new Promise(function(resolve, reject) {
var s = document.createElement('script');
s.src = paths[lib];
s.async = true;
s.onload = () => resolve(paths[lib]);
s.onerror = () => reject(`Error loading script: ${paths[lib]}`);
document.getElementsByTagName("head")[0].appendChild(s);
});
}
function showError(err) {
outputDiv.innerHTML = `<div class="error" style="color:red;">${err}</div>`;
throw err;
}
function displayChart(vegaEmbed) {
vegaEmbed(outputDiv, spec, embedOpt)
.catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));
}
if(typeof define === "function" && define.amd) {
requirejs.config({paths});
require(["vega-embed"], displayChart, err => showError(`Error loading script: ${err.message}`));
} else if (typeof vegaEmbed === "function") {
displayChart(vegaEmbed);
} else {
loadScript("vega")
.then(() => loadScript("vega-lite"))
.then(() => loadScript("vega-embed"))
.catch(showError)
.then(() => displayChart(vegaEmbed));
}
})({"config": {"view": {"continuousWidth": 400, "continuousHeight": 300}}, "layer": [{"mark": "line", "encoding": {"color": {"type": "nominal", "field": "symbol"}, "x": {"type": "temporal", "field": "date"}, "y": {"type": "quantitative", "field": "price", "scale": {"type": "log"}}}}, {"mark": {"type": "rule", "color": "#aaa"}, "encoding": {"x": {"type": "temporal", "field": "date"}}, "transform": [{"filter": {"selection": "selector002"}}]}, {"mark": "circle", "encoding": {"color": {"type": "nominal", "field": "symbol"}, "opacity": {"condition": {"value": 1, "selection": "selector002"}, "value": 0}, "x": {"type": "temporal", "field": "date"}, "y": {"type": "quantitative", "field": "price", "scale": {"type": "log"}}}, "selection": {"selector002": {"type": "single", "encodings": ["x"], "on": "mouseover", "nearest": true, "empty": "none"}}}, {"mark": {"type": "text", "align": "left", "dx": 5, "dy": -5, "stroke": "white", "strokeWidth": 2}, "encoding": {"color": {"type": "nominal", "field": "symbol"}, "text": {"type": "quantitative", "field": "price"}, "x": {"type": "temporal", "field": "date"}, "y": {"type": "quantitative", "field": "price", "scale": {"type": "log"}}}, "transform": [{"filter": {"selection": "selector002"}}]}, {"mark": {"type": "text", "align": "left", "dx": 5, "dy": -5}, "encoding": {"color": {"type": "nominal", "field": "symbol"}, "text": {"type": "quantitative", "field": "price"}, "x": {"type": "temporal", "field": "date"}, "y": {"type": "quantitative", "field": "price", "scale": {"type": "log"}}}, "transform": [{"filter": {"selection": "selector002"}}]}], "data": {"url": "https://vega.github.io/vega-datasets/data/stocks.csv"}, "height": 400, "width": 700, "$schema": "https://vega.github.io/schema/vega-lite/v4.0.2.json"}, {"mode": "vega-lite"});
</script>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Data-Tables">Data Tables<a class="anchor-link" href="#Data-Tables"> </a></h2><p>You can display tables per the usual way in your blog:</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">movies</span> <span class="o">=</span> <span class="s1">'https://vega.github.io/vega-datasets/data/movies.json'</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_json</span><span class="p">(</span><span class="n">movies</span><span class="p">)</span>
<span class="c1"># display table with pandas</span>
<span class="n">df</span><span class="p">[[</span><span class="s1">'Title'</span><span class="p">,</span> <span class="s1">'Worldwide_Gross'</span><span class="p">,</span>
<span class="s1">'Production_Budget'</span><span class="p">,</span> <span class="s1">'Distributor'</span><span class="p">,</span> <span class="s1">'MPAA_Rating'</span><span class="p">,</span> <span class="s1">'IMDB_Rating'</span><span class="p">,</span> <span class="s1">'Rotten_Tomatoes_Rating'</span><span class="p">]]</span><span class="o">.</span><span class="n">head</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="output_html rendered_html output_subarea output_execute_result">
<div>
<style scoped="">
.dataframe tbody tr th:only-of-type {
vertical-align: middle;
}
.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
</style>
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>Title</th>
<th>Worldwide_Gross</th>
<th>Production_Budget</th>
<th>Distributor</th>
<th>MPAA_Rating</th>
<th>IMDB_Rating</th>
<th>Rotten_Tomatoes_Rating</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td>The Land Girls</td>
<td>146083.0</td>
<td>8000000.0</td>
<td>Gramercy</td>
<td>R</td>
<td>6.1</td>
<td>NaN</td>
</tr>
<tr>
<th>1</th>
<td>First Love, Last Rites</td>
<td>10876.0</td>
<td>300000.0</td>
<td>Strand</td>
<td>R</td>
<td>6.9</td>
<td>NaN</td>
</tr>
<tr>
<th>2</th>
<td>I Married a Strange Person</td>
<td>203134.0</td>
<td>250000.0</td>
<td>Lionsgate</td>
<td>None</td>
<td>6.8</td>
<td>NaN</td>
</tr>
<tr>
<th>3</th>
<td>Let's Talk About Sex</td>
<td>373615.0</td>
<td>300000.0</td>
<td>Fine Line</td>
<td>None</td>
<td>NaN</td>
<td>13.0</td>
</tr>
<tr>
<th>4</th>
<td>Slam</td>
<td>1087521.0</td>
<td>1000000.0</td>
<td>Trimark</td>
<td>R</td>
<td>3.4</td>
<td>62.0</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Images">Images<a class="anchor-link" href="#Images"> </a></h2><h3 id="Local-Images">Local Images<a class="anchor-link" href="#Local-Images"> </a></h3><p>You can reference local images and they will be copied and rendered on your blog automatically. You can include these with the following markdown syntax:</p>
<p><code>![](my_icons/fastai_logo.png)</code></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><img src="/maths-havard-stats-110/images/copied_from_nb/my_icons/fastai_logo.png" alt="" /></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Remote-Images">Remote Images<a class="anchor-link" href="#Remote-Images"> </a></h3><p>Remote images can be included with the following markdown syntax:</p>
<p><code>![](https://image.flaticon.com/icons/svg/36/36686.svg)</code></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><img src="https://image.flaticon.com/icons/svg/36/36686.svg" alt="" /></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Animated-Gifs">Animated Gifs<a class="anchor-link" href="#Animated-Gifs"> </a></h3><p>Animated Gifs work, too!</p>
<p><code>![](https://upload.wikimedia.org/wikipedia/commons/7/71/ChessPawnSpecialMoves.gif)</code></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p><img src="https://upload.wikimedia.org/wikipedia/commons/7/71/ChessPawnSpecialMoves.gif" alt="" /></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="Captions">Captions<a class="anchor-link" href="#Captions"> </a></h3><p>You can include captions with markdown images like this:</p>
<pre><code>![](https://www.fast.ai/images/fastai_paper/show_batch.png "Credit: https://www.fast.ai/2020/02/13/fastai-A-Layered-API-for-Deep-Learning/")</code></pre>
<p><img src="https://www.fast.ai/images/fastai_paper/show_batch.png" alt="" title="Credit: https://www.fast.ai/2020/02/13/fastai-A-Layered-API-for-Deep-Learning/" /></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="Other-Elements">Other Elements<a class="anchor-link" href="#Other-Elements"> </a></h1>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Tweetcards">Tweetcards<a class="anchor-link" href="#Tweetcards"> </a></h2><p>Typing <code>> twitter: https://twitter.com/jakevdp/status/1204765621767901185?s=20</code> will render this:
<center>
<div class="jekyll-twitter-plugin"><blockquote class="twitter-tweet"><p lang="en" dir="ltr">Altair 4.0 is released! <a href="https://t.co/PCyrIOTcvv">https://t.co/PCyrIOTcvv</a><br />Try it with:<br /><br /> pip install -U altair<br /><br />The full list of changes is at <a href="https://t.co/roXmzcsT58">https://t.co/roXmzcsT58</a> ...read on for some highlights. <a href="https://t.co/vWJ0ZveKbZ">pic.twitter.com/vWJ0ZveKbZ</a></p>— Jake VanderPlas (@jakevdp) <a href="https://twitter.com/jakevdp/status/1204765621767901185?ref_src=twsrc%5Etfw">December 11, 2019</a></blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
</center>
</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Youtube-Videos">Youtube Videos<a class="anchor-link" href="#Youtube-Videos"> </a></h2><p>Typing <code>> youtube: https://youtu.be/XfoYk_Z5AkI</code> will render this:
<center>
<iframe width="560" height="315" src="https://www.youtube.com/embed/XfoYk_Z5AkI" frameborder="0" allowfullscreen=""></iframe>
</center>
</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Boxes-/-Callouts">Boxes / Callouts<a class="anchor-link" href="#Boxes-/-Callouts"> </a></h2><p>Typing <code>> Warning: There will be no second warning!</code> will render this:
<div class="flash flash-error">
<svg class="octicon octicon-alert" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 000 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 00.01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path></svg>
<strong>Warning: </strong>There will be no second warning!
</div></p>
<p>Typing <code>> Important: Pay attention! It's important.</code> will render this:
<div class="flash flash-warn">
<svg class="octicon octicon-zap" viewBox="0 0 10 16" version="1.1" width="10" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M10 7H6l3-7-9 9h4l-3 7 9-9z"></path></svg>
<strong>Important: </strong>Pay attention! It’s important.
</div></p>
<p>Typing <code>> Tip: This is my tip.</code> will render this:
<div class="flash flash-success">
<svg class="octicon octicon-checklist" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M16 8.5l-6 6-3-3L8.5 10l1.5 1.5L14.5 7 16 8.5zM5.7 12.2l.8.8H2c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h7c.55 0 1 .45 1 1v6.5l-.8-.8c-.39-.39-1.03-.39-1.42 0L5.7 10.8a.996.996 0 000 1.41v-.01zM4 4h5V3H4v1zm0 2h5V5H4v1zm0 2h3V7H4v1zM3 9H2v1h1V9zm0-2H2v1h1V7zm0-2H2v1h1V5zm0-2H2v1h1V3z"></path></svg>
<strong>Tip: </strong>This is my tip.
</div></p>
<p>Typing <code>> Note: Take note of this.</code> will render this:
<div class="flash">
<svg class="octicon octicon-info" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 01-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 01-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg>
<strong>Note: </strong>Take note of this.
</div></p>
<p>Typing <code>> Note: A doc link to [an example website: fast.ai](https://www.fast.ai/) should also work fine.</code> will render in the docs:
<div class="flash">
<svg class="octicon octicon-info octicon octicon-info" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 01-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 01-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg>
<strong>Note: </strong>A doc link to <a href="https://www.fast.ai/">an example website: fast.ai</a> should also work fine.
</div></p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Footnotes">Footnotes<a class="anchor-link" href="#Footnotes"> </a></h2><p>You can have footnotes in notebooks, however the syntax is different compared to markdown documents. <a href="https://github.com/fastai/fastpages/blob/master/_fastpages_docs/NOTEBOOK_FOOTNOTES.md">This guide provides more detail about this syntax</a>, which looks like this:</p>
<pre><code>For example, here is a footnote {% fn 1 %}.
And another {% fn 2 %}
{{ 'This is the footnote.' | fndetail: 1 }}
{{ 'This is the other footnote. You can even have a [link](www.github.com)!' | fndetail: 2 }}</code></pre>
<p>For example, here is a footnote <sup id="fnref-1" class="footnote-ref"><a href="#fn-1">1</a></sup>.</p>
<p>And another <sup id="fnref-2" class="footnote-ref"><a href="#fn-2">2</a></sup></p>
<p><div class="footnotes"><p id="fn-1">1. This is the footnote.<a href="#fnref-1" class="footnote footnotes">↩</a></p></div>
<div class="footnotes"><p id="fn-2">2. This is the other footnote. You can even have a <a href="www.github.com">link</a>!<a href="#fnref-2" class="footnote footnotes">↩</a></p></div></p>
</div>
</div>
</div>
</div>An Example Markdown Post2020-01-14T00:00:00-06:002020-01-14T00:00:00-06:00https://unna97.github.io/maths-havard-stats-110/markdown/2020/01/14/test-markdown-post<h1 id="example-markdown-post">Example Markdown Post</h1>
<h2 id="basic-setup">Basic setup</h2>
<p>Jekyll requires blog post files to be named according to the following format:</p>
<p><code class="highlighter-rouge">YEAR-MONTH-DAY-filename.md</code></p>
<p>Where <code class="highlighter-rouge">YEAR</code> is a four-digit number, <code class="highlighter-rouge">MONTH</code> and <code class="highlighter-rouge">DAY</code> are both two-digit numbers, and <code class="highlighter-rouge">filename</code> is whatever file name you choose, to remind yourself what this post is about. <code class="highlighter-rouge">.md</code> is the file extension for markdown files.</p>
<p>The first line of the file should start with a single hash character, then a space, then your title. This is how you create a “<em>level 1 heading</em>” in markdown. Then you can create level 2, 3, etc headings as you wish but repeating the hash character, such as you see in the line <code class="highlighter-rouge">## File names</code> above.</p>
<h2 id="basic-formatting">Basic formatting</h2>
<p>You can use <em>italics</em>, <strong>bold</strong>, <code class="highlighter-rouge">code font text</code>, and create <a href="https://www.markdownguide.org/cheat-sheet/">links</a>. Here’s a footnote <sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote" rel="footnote">1</a></sup>. Here’s a horizontal rule:</p>
<hr />
<h2 id="lists">Lists</h2>
<p>Here’s a list:</p>
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
<p>And a numbered list:</p>
<ol>
<li>item 1</li>
<li>item 2</li>
</ol>
<h2 id="boxes-and-stuff">Boxes and stuff</h2>
<blockquote>
<p>This is a quotation</p>
</blockquote>
<div class="Toast Toast--warning googoo">
<span class="Toast-icon"><svg class="octicon octicon-alert" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 000 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 00.01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path></svg></span>
<span class="Toast-content">You can include alert boxes</span>
</div>
<p>…and…</p>
<div class="Toast">
<span class="Toast-icon"><svg class="octicon octicon-info" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 01-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 01-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>
<span class="Toast-content">You can include info boxes</span>
</div>
<h2 id="images">Images</h2>
<p><img src="/maths-havard-stats-110/images/logo.png" alt="" title="fast.ai's logo" /></p>
<h2 id="code">Code</h2>
<p>You can format text and code per usual</p>
<p>General preformatted text:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code># Do a thing
do_thing()
</code></pre></div></div>
<p>Python code and output:</p>
<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Prints '2'
</span><span class="k">print</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
</code></pre></div></div>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>2
</code></pre></div></div>
<p>Formatting text as shell commands:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">echo</span> <span class="s2">"hello world"</span>
./some_script.sh <span class="nt">--option</span> <span class="s2">"value"</span>
wget https://example.com/cat_photo1.png
</code></pre></div></div>
<p>Formatting text as YAML:</p>
<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">key</span><span class="pi">:</span> <span class="s">value</span>
<span class="pi">-</span> <span class="na">another_key</span><span class="pi">:</span> <span class="s2">"</span><span class="s">another</span><span class="nv"> </span><span class="s">value"</span>
</code></pre></div></div>
<h2 id="tables">Tables</h2>
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>A thing</td>
<td>Another thing</td>
</tr>
</tbody>
</table>
<h2 id="tweetcards">Tweetcards</h2>
<div class="jekyll-twitter-plugin"><blockquote class="twitter-tweet"><p lang="en" dir="ltr">Altair 4.0 is released! <a href="https://t.co/PCyrIOTcvv">https://t.co/PCyrIOTcvv</a><br />Try it with:<br /><br /> pip install -U altair<br /><br />The full list of changes is at <a href="https://t.co/roXmzcsT58">https://t.co/roXmzcsT58</a> ...read on for some highlights. <a href="https://t.co/vWJ0ZveKbZ">pic.twitter.com/vWJ0ZveKbZ</a></p>— Jake VanderPlas (@jakevdp) <a href="https://twitter.com/jakevdp/status/1204765621767901185?ref_src=twsrc%5Etfw">December 11, 2019</a></blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
<h2 id="footnotes">Footnotes</h2>
<div class="footnotes" role="doc-endnotes">
<ol>
<li id="fn:1" role="doc-endnote">
<p>This is the footnote. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
</ol>
</div>Example Markdown Post