Skip to content

Commit

Permalink
publish note 11
Browse files Browse the repository at this point in the history
  • Loading branch information
nsreddy16 committed Oct 3, 2024
1 parent 4660fc0 commit a37f8a5
Show file tree
Hide file tree
Showing 99 changed files with 3,660 additions and 603 deletions.
2 changes: 1 addition & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ book:
- visualization_2/visualization_2.qmd
- sampling/sampling.qmd
- intro_to_modeling/intro_to_modeling.qmd
# - constant_model_loss_transformations/loss_transformations.qmd
- constant_model_loss_transformations/loss_transformations.qmd
# - ols/ols.qmd
# - gradient_descent/gradient_descent.qmd
# - feature_engineering/feature_engineering.qmd
Expand Down
263 changes: 52 additions & 211 deletions constant_model_loss_transformations/loss_transformations.qmd

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,080 changes: 2,080 additions & 0 deletions docs/constant_model_loss_transformations/loss_transformations.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
162 changes: 84 additions & 78 deletions docs/eda/eda.html

Large diffs are not rendered by default.

Binary file modified docs/eda/eda_files/figure-pdf/cell-62-output-1.pdf
Binary file not shown.
Binary file modified docs/eda/eda_files/figure-pdf/cell-67-output-1.pdf
Binary file not shown.
Binary file modified docs/eda/eda_files/figure-pdf/cell-68-output-1.pdf
Binary file not shown.
Binary file modified docs/eda/eda_files/figure-pdf/cell-69-output-1.pdf
Binary file not shown.
Binary file modified docs/eda/eda_files/figure-pdf/cell-71-output-1.pdf
Binary file not shown.
Binary file modified docs/eda/eda_files/figure-pdf/cell-75-output-1.pdf
Binary file not shown.
Binary file modified docs/eda/eda_files/figure-pdf/cell-76-output-1.pdf
Binary file not shown.
Binary file modified docs/eda/eda_files/figure-pdf/cell-77-output-1.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@
<a href="./intro_to_modeling/intro_to_modeling.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Introduction to Modeling</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./constant_model_loss_transformations/loss_transformations.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Constant Model, Loss, and Transformations</span></span></a>
</div>
</li>
</ul>
</div>
Expand Down
6 changes: 6 additions & 0 deletions docs/intro_lec/introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@
<a href="../intro_to_modeling/intro_to_modeling.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Introduction to Modeling</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../constant_model_loss_transformations/loss_transformations.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Constant Model, Loss, and Transformations</span></span></a>
</div>
</li>
</ul>
</div>
Expand Down
26 changes: 18 additions & 8 deletions docs/intro_to_modeling/intro_to_modeling.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<script src="../site_libs/quarto-search/fuse.min.js"></script>
<script src="../site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="../">
<link href="../constant_model_loss_transformations/loss_transformations.html" rel="next">
<link href="../sampling/sampling.html" rel="prev">
<link href="../data100_logo.png" rel="icon" type="image/png">
<script src="../site_libs/quarto-html/quarto.js"></script>
Expand Down Expand Up @@ -239,6 +240,12 @@
<a href="../intro_to_modeling/intro_to_modeling.html" class="sidebar-item-text sidebar-link active">
<span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Introduction to Modeling</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="../constant_model_loss_transformations/loss_transformations.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Constant Model, Loss, and Transformations</span></span></a>
</div>
</li>
</ul>
</div>
Expand Down Expand Up @@ -387,7 +394,7 @@ <h2 data-number="10.2" class="anchored" data-anchor-id="simple-linear-regression
<li><span class="math inline">\(\text{regression estimate} = y\text{-intercept} + \text{slope}\cdot\text{}x\)</span></li>
<li><span class="math inline">\(\text{residual} =\text{observed }y - \text{regression estimate}\)</span></li>
</ul>
<div id="2342e5b1" class="cell" data-execution_count="1">
<div id="50d969cc" class="cell" data-execution_count="1">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pandas <span class="im">as</span> pd</span>
Expand Down Expand Up @@ -434,7 +441,7 @@ <h4 data-number="10.2.1.2" class="anchored" data-anchor-id="correlation"><span c
<li>Correlations range between -1 and 1: <span class="math inline">\(|r| \leq 1\)</span>, with <span class="math inline">\(r=1\)</span> indicating perfect positive linear association, and <span class="math inline">\(r=-1\)</span> indicating perfect negative association. The closer <span class="math inline">\(r\)</span> is to <span class="math inline">\(0\)</span>, the weaker the linear association is.</li>
<li>Correlation says nothing about causation and non-linear association. Correlation does <strong>not</strong> imply causation. When <span class="math inline">\(r = 0\)</span>, the two variables are uncorrelated. However, they could still be related through some non-linear relationship.</li>
</ol>
<div id="f07efd37" class="cell" data-execution_count="2">
<div id="6ce48d20" class="cell" data-execution_count="2">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> plot_and_get_corr(ax, x, y, title):</span>
Expand Down Expand Up @@ -658,7 +665,7 @@ <h2 data-number="10.7" class="anchored" data-anchor-id="evaluating-the-slr-model
<section id="four-mysterious-datasets-anscombes-quartet" class="level3" data-number="10.7.1">
<h3 data-number="10.7.1" class="anchored" data-anchor-id="four-mysterious-datasets-anscombes-quartet"><span class="header-section-number">10.7.1</span> Four Mysterious Datasets (Anscombe’s quartet)</h3>
<p>Let’s take a look at four different datasets.</p>
<div id="dc45719f" class="cell" data-execution_count="3">
<div id="77c429ab" class="cell" data-execution_count="3">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
Expand All @@ -670,7 +677,7 @@ <h3 data-number="10.7.1" class="anchored" data-anchor-id="four-mysterious-datase
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> mpl_toolkits.mplot3d <span class="im">import</span> Axes3D</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<div id="a29af7cd" class="cell" data-execution_count="4">
<div id="dcfbe15a" class="cell" data-execution_count="4">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Big font helper</span></span>
Expand Down Expand Up @@ -724,7 +731,7 @@ <h3 data-number="10.7.1" class="anchored" data-anchor-id="four-mysterious-datase
<span id="cb4-49"><a href="#cb4-49" aria-hidden="true" tabindex="-1"></a>plt.style.use(<span class="st">"default"</span>) <span class="co"># Revert style to default mpl</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<div id="40b40b77" class="cell" data-execution_count="5">
<div id="858023dc" class="cell" data-execution_count="5">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>plt.style.use(<span class="st">"default"</span>) <span class="co"># Revert style to default mpl</span></span>
Expand Down Expand Up @@ -763,7 +770,7 @@ <h3 data-number="10.7.1" class="anchored" data-anchor-id="four-mysterious-datase
<span id="cb5-34"><a href="#cb5-34" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> fig</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</details>
</div>
<div id="eeae5630" class="cell" data-execution_count="6">
<div id="2373151e" class="cell" data-execution_count="6">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Load in four different datasets: I, II, III, IV</span></span>
Expand Down Expand Up @@ -806,7 +813,7 @@ <h3 data-number="10.7.1" class="anchored" data-anchor-id="four-mysterious-datase
</div>
</div>
<p>While these four sets of datapoints look very different, they actually all have identical means <span class="math inline">\(\bar x\)</span>, <span class="math inline">\(\bar y\)</span>, standard deviations <span class="math inline">\(\sigma_x\)</span>, <span class="math inline">\(\sigma_y\)</span>, correlation <span class="math inline">\(r\)</span>, and RMSE! If we only look at these statistics, we would probably be inclined to say that these datasets are similar.</p>
<div id="831b3b49" class="cell" data-execution_count="7">
<div id="dc089a8b" class="cell" data-execution_count="7">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> dataset <span class="kw">in</span> [<span class="st">"I"</span>, <span class="st">"II"</span>, <span class="st">"III"</span>, <span class="st">"IV"</span>]:</span>
Expand Down Expand Up @@ -853,7 +860,7 @@ <h3 data-number="10.7.1" class="anchored" data-anchor-id="four-mysterious-datase
</div>
<p>We may also wish to visualize the model’s <strong>residuals</strong>, defined as the difference between the observed and predicted <span class="math inline">\(y_i\)</span> value (<span class="math inline">\(e_i = y_i - \hat{y}_i\)</span>). This gives a high-level view of how “off” each prediction is from the true observed value. Recall that you explored this concept in <a href="https://inferentialthinking.com/chapters/15/5/Visual_Diagnostics.html?highlight=heteroscedasticity#detecting-heteroscedasticity">Data 8</a>: a good regression fit should display no clear pattern in its plot of residuals. The residual plots for Anscombe’s quartet are displayed below. Note how only the first plot shows no clear pattern to the magnitude of residuals. This is an indication that SLR is not the best choice of model for the remaining three sets of points.</p>
<!-- <img src="images/residual.png" alt='residual' width='600'> -->
<div id="2a6b1d76" class="cell" data-execution_count="8">
<div id="9d85a518" class="cell" data-execution_count="8">
<details class="code-fold">
<summary>Code</summary>
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Residual visualization</span></span>
Expand Down Expand Up @@ -1337,6 +1344,9 @@ <h3 data-number="10.7.1" class="anchored" data-anchor-id="four-mysterious-datase
</a>
</div>
<div class="nav-page nav-page-next">
<a href="../constant_model_loss_transformations/loss_transformations.html" class="pagination-link" aria-label="<span class='chapter-number'>11</span>&nbsp; <span class='chapter-title'>Constant Model, Loss, and Transformations</span>">
<span class="nav-page-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Constant Model, Loss, and Transformations</span></span> <i class="bi bi-arrow-right-short"></i>
</a>
</div>
</nav><div class="modal fade" id="quarto-embedded-source-code-modal" tabindex="-1" aria-labelledby="quarto-embedded-source-code-modal-label" aria-hidden="true"><div class="modal-dialog modal-dialog-scrollable"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="quarto-embedded-source-code-modal-label">Source Code</h5><button class="btn-close" data-bs-dismiss="modal"></button></div><div class="modal-body"><div class="">
<div class="sourceCode" id="cb10" data-shortcodes="false"><pre class="sourceCode markdown code-with-copy"><code class="sourceCode markdown"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="co">---</span></span>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit a37f8a5

Please sign in to comment.