small update on book

This commit is contained in:
Morten Hjorth-Jensen
2024-09-03 05:59:13 +02:00
parent 48d4efe695
commit 621836e70c
12 changed files with 938 additions and 909 deletions
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -271,7 +271,7 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
</ul>
+1 -1
View File
@@ -272,7 +272,7 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
</ul>
Binary file not shown.
+1 -1
View File
@@ -277,7 +277,7 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
</ul>
File diff suppressed because one or more lines are too long
+28 -7
View File
@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Week 36: Linear Rgeression and Statistical interpretations &#8212; Applied Data Analysis and Machine Learning</title>
<title>Week 36: Linear Regression and Statistical interpretations &#8212; Applied Data Analysis and Machine Learning</title>
<link href="_static/css/theme.css" rel="stylesheet">
<link href="_static/css/index.ff1ffe594081f20da1ef19478df9384b.css" rel="stylesheet">
@@ -55,6 +55,7 @@ const thebe_selector_output = ".output, .cell_output"
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Project 1 on Machine Learning, deadline October 7 (midnight), 2024" href="project1.html" />
<link rel="prev" title="Exercises week 36" href="exercisesweek36.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
@@ -274,7 +275,19 @@ const thebe_selector_output = ".output, .cell_output"
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
Week 36: Linear Rgeression and Statistical interpretations
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
</ul>
@@ -609,7 +622,7 @@ const thebe_selector_output = ".output, .cell_output"
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
<!-- Table of contents that is only displayed when printing the page -->
<div id="jb-print-docs-body" class="onlyprint">
<h1>Week 36: Linear Rgeression and Statistical interpretations</h1>
<h1>Week 36: Linear Regression and Statistical interpretations</h1>
<!-- Table of contents -->
<div id="print-main-content">
<div id="jb-print-toc">
@@ -881,8 +894,8 @@ const thebe_selector_output = ".output, .cell_output"
<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)
doconce format html week36.do.txt --no_mako -->
<!-- dom:TITLE: Week 36: Linear Rgeression and Statistical interpretations --><div class="tex2jax_ignore mathjax_ignore section" id="week-36-linear-rgeression-and-statistical-interpretations">
<h1>Week 36: Linear Rgeression and Statistical interpretations<a class="headerlink" href="#week-36-linear-rgeression-and-statistical-interpretations" title="Permalink to this headline"></a></h1>
<!-- dom:TITLE: Week 36: Linear Regression and Statistical interpretations --><div class="tex2jax_ignore mathjax_ignore section" id="week-36-linear-regression-and-statistical-interpretations">
<h1>Week 36: Linear Regression and Statistical interpretations<a class="headerlink" href="#week-36-linear-regression-and-statistical-interpretations" title="Permalink to this headline"></a></h1>
<p><strong>Morten Hjorth-Jensen</strong>, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</p>
<p>Date: <strong>September 2-6, 2024</strong></p>
<div class="section" id="plans-for-week-36">
@@ -941,6 +954,7 @@ survey of your data, with a critical assessment of them in case you need to scal
<p>If you need to scale the data, not doing so will give an <em>unfair</em>
penalization of the parameters since their magnitude depends on the
scale of their corresponding predictor.</p>
<p>The <strong>Scikit-Learn</strong> site <a class="reference external" href="https://scikit-learn.org/stable/auto_examples/preprocessing/plot_all_scaling.html#plot-all-scaling-standard-scaler-section">https://scikit-learn.org/stable/auto_examples/preprocessing/plot_all_scaling.html#plot-all-scaling-standard-scaler-section</a> has a good discussion of different ways of preprocessing data.</p>
<p>Suppose as an example that you
you have an input variable given by the heights of different persons.
Human height might be measured in inches or meters or
@@ -1142,7 +1156,7 @@ Note also that we do not split the data into training and test.</p>
<span class="n">intercept</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">y_offset</span> <span class="o">-</span> <span class="n">X_offset</span> <span class="o">@</span> <span class="n">beta</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Manual intercept: </span><span class="si">{</span><span class="n">intercept</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Fitted beta (wiothout intercept): </span><span class="si">{</span><span class="n">beta</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Fitted beta (without intercept): </span><span class="si">{</span><span class="n">beta</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Sklearn intercept: </span><span class="si">{</span><span class="n">skl</span><span class="o">.</span><span class="n">intercept_</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Sklearn fitted beta (without intercept): </span><span class="si">{</span><span class="n">skl</span><span class="o">.</span><span class="n">coef_</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">ypredictOwn</span> <span class="o">=</span> <span class="n">X</span> <span class="o">@</span> <span class="n">beta</span>
@@ -1170,7 +1184,7 @@ MSE with intercept column
MSE with intercept column from SKL
0.004113634617443147
Manual intercept: 2.083766322923899
Fitted beta (wiothout intercept): [0.19569961 3.97898392]
Fitted beta (without intercept): [0.19569961 3.97898392]
Sklearn intercept: 2.0837663229239043
Sklearn fitted beta (without intercept): [0.19569961 3.97898392]
MSE with Manual intercept
@@ -2903,6 +2917,13 @@ C(\boldsymbol{\beta})=(4-2\beta_0)^2+(2-\beta_1)^2+\lambda(\vert\beta_0\vert+\ve
<p class="prev-next-title">Exercises week 36</p>
</div>
</a>
<a class='right-next' id="next-link" href="project1.html" title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">Project 1 on Machine Learning, deadline October 7 (midnight), 2024</p>
</div>
<i class="fas fa-angle-right"></i>
</a>
</div>
</div>
File diff suppressed because it is too large Load Diff
@@ -3,9 +3,9 @@
# <!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)
# doconce format html week36.do.txt --no_mako -->
# <!-- dom:TITLE: Week 36: Linear Rgeression and Statistical interpretations -->
# <!-- dom:TITLE: Week 36: Linear Regression and Statistical interpretations -->
# # Week 36: Linear Rgeression and Statistical interpretations
# # Week 36: Linear Regression and Statistical interpretations
# **Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
#
# Date: **September 2-6, 2024**
@@ -73,6 +73,8 @@
# penalization of the parameters since their magnitude depends on the
# scale of their corresponding predictor.
#
# The **Scikit-Learn** site <https://scikit-learn.org/stable/auto_examples/preprocessing/plot_all_scaling.html#plot-all-scaling-standard-scaler-section> has a good discussion of different ways of preprocessing data.
#
# Suppose as an example that you
# you have an input variable given by the heights of different persons.
# Human height might be measured in inches or meters or
@@ -292,7 +294,7 @@ beta = fit_beta(X - X_offset, y - y_offset)
intercept = np.mean(y_offset - X_offset @ beta)
print(f"Manual intercept: {intercept}")
print(f"Fitted beta (wiothout intercept): {beta}")
print(f"Fitted beta (without intercept): {beta}")
print(f"Sklearn intercept: {skl.intercept_}")
print(f"Sklearn fitted beta (without intercept): {skl.coef_}")
ypredictOwn = X @ beta
File diff suppressed because it is too large Load Diff