starting to update notes
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<!--
|
||||
Automatically generated HTML file from DocOnce source
|
||||
(https://github.com/hplgit/doconce/)
|
||||
(https://github.com/doconce/doconce/)
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
|
||||
<meta name="generator" content="DocOnce: https://github.com/doconce/doconce/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="Week 34: Introduction to the course, Logistics and Practicalities">
|
||||
|
||||
@@ -41,67 +41,94 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Overview of first week', 2, None, '___sec0'),
|
||||
('Thursday August 20', 2, None, '___sec1'),
|
||||
('Lectures and ComputerLab', 2, None, '___sec2'),
|
||||
('Course Format', 2, None, '___sec3'),
|
||||
('Teachers', 2, None, '___sec4'),
|
||||
('Deadlines for projects (tentative)', 2, None, '___sec5'),
|
||||
('Recommended textbooks', 2, None, '___sec6'),
|
||||
('Prerequisites', 2, None, '___sec7'),
|
||||
('Learning outcomes', 2, None, '___sec8'),
|
||||
'sections': [('Overview of first week', 2, None, 'overview-of-first-week'),
|
||||
('Thursday August 26', 2, None, 'thursday-august-26'),
|
||||
('Lectures and ComputerLab', 2, None, 'lectures-and-computerlab'),
|
||||
('Course Format', 2, None, 'course-format'),
|
||||
('Teachers', 2, None, 'teachers'),
|
||||
('Deadlines for projects (tentative)',
|
||||
2,
|
||||
None,
|
||||
'deadlines-for-projects-tentative'),
|
||||
('Recommended textbooks', 2, None, 'recommended-textbooks'),
|
||||
('Prerequisites', 2, None, 'prerequisites'),
|
||||
('Learning outcomes', 2, None, 'learning-outcomes'),
|
||||
('Topics covered in this course: Statistical analysis and '
|
||||
'optimization of data',
|
||||
2,
|
||||
None,
|
||||
'___sec9'),
|
||||
'topics-covered-in-this-course-statistical-analysis-and-optimization-of-data'),
|
||||
('Topics covered in this course: Machine Learning',
|
||||
2,
|
||||
None,
|
||||
'___sec10'),
|
||||
'topics-covered-in-this-course-machine-learning'),
|
||||
('Extremely useful tools, strongly recommended',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
'extremely-useful-tools-strongly-recommended'),
|
||||
('Other courses on Data science and Machine Learning at UiO',
|
||||
2,
|
||||
None,
|
||||
'___sec12'),
|
||||
('Introduction', 2, None, '___sec13'),
|
||||
('What is Machine Learning?', 2, None, '___sec14'),
|
||||
('Types of Machine Learning', 2, None, '___sec15'),
|
||||
('Software and needed installations', 2, None, '___sec16'),
|
||||
('Python installers', 2, None, '___sec17'),
|
||||
('Useful Python libraries', 2, None, '___sec18'),
|
||||
('Installing R, C++, cython or Julia', 2, None, '___sec19'),
|
||||
('Installing R, C++, cython, Numba etc', 2, None, '___sec20'),
|
||||
'other-courses-on-data-science-and-machine-learning-at-uio'),
|
||||
('Introduction', 2, None, 'introduction'),
|
||||
('What is Machine Learning?',
|
||||
2,
|
||||
None,
|
||||
'what-is-machine-learning'),
|
||||
('Types of Machine Learning',
|
||||
2,
|
||||
None,
|
||||
'types-of-machine-learning'),
|
||||
('Software and needed installations',
|
||||
2,
|
||||
None,
|
||||
'software-and-needed-installations'),
|
||||
('Python installers', 2, None, 'python-installers'),
|
||||
('Useful Python libraries', 2, None, 'useful-python-libraries'),
|
||||
('Installing R, C++, cython or Julia',
|
||||
2,
|
||||
None,
|
||||
'installing-r-c-cython-or-julia'),
|
||||
('Installing R, C++, cython, Numba etc',
|
||||
2,
|
||||
None,
|
||||
'installing-r-c-cython-numba-etc'),
|
||||
('Numpy examples and Important Matrix and vector handling '
|
||||
'packages',
|
||||
2,
|
||||
None,
|
||||
'___sec21'),
|
||||
('Basic Matrix Features', 2, None, '___sec22'),
|
||||
('Some famous Matrices', 3, None, '___sec23'),
|
||||
('More Basic Matrix Features', 3, None, '___sec24'),
|
||||
('Numpy and arrays', 2, None, '___sec25'),
|
||||
('Matrices in Python', 2, None, '___sec26'),
|
||||
('Meet the Pandas', 2, None, '___sec27'),
|
||||
('Friday August 21', 2, None, '___sec28'),
|
||||
('Reading Data and fitting', 2, None, '___sec29'),
|
||||
('Friday August 21', 2, None, '___sec30'),
|
||||
'numpy-examples-and-important-matrix-and-vector-handling-packages'),
|
||||
('Basic Matrix Features', 2, None, 'basic-matrix-features'),
|
||||
('Some famous Matrices', 3, None, 'some-famous-matrices'),
|
||||
('More Basic Matrix Features',
|
||||
3,
|
||||
None,
|
||||
'more-basic-matrix-features'),
|
||||
('Numpy and arrays', 2, None, 'numpy-and-arrays'),
|
||||
('Matrices in Python', 2, None, 'matrices-in-python'),
|
||||
('Meet the Pandas', 2, None, 'meet-the-pandas'),
|
||||
('Friday August 21', 2, None, 'friday-august-21'),
|
||||
('Reading Data and fitting', 2, None, 'reading-data-and-fitting'),
|
||||
('Friday August 21', 2, None, 'friday-august-21'),
|
||||
('Simple linear regression model using _scikit-learn_',
|
||||
3,
|
||||
None,
|
||||
'___sec31'),
|
||||
'simple-linear-regression-model-using-_scikit-learn_'),
|
||||
('To our real data: nuclear binding energies. Brief reminder on '
|
||||
'masses and binding energies',
|
||||
3,
|
||||
None,
|
||||
'___sec32'),
|
||||
('Organizing our data', 3, None, '___sec33'),
|
||||
('Seeing the wood for the trees', 3, None, '___sec34'),
|
||||
('And what about using neural networks?', 3, None, '___sec35'),
|
||||
('A first summary', 2, None, '___sec36')]}
|
||||
'to-our-real-data-nuclear-binding-energies-brief-reminder-on-masses-and-binding-energies'),
|
||||
('Organizing our data', 3, None, 'organizing-our-data'),
|
||||
('Seeing the wood for the trees',
|
||||
3,
|
||||
None,
|
||||
'seeing-the-wood-for-the-trees'),
|
||||
('And what about using neural networks?',
|
||||
3,
|
||||
None,
|
||||
'and-what-about-using-neural-networks'),
|
||||
('A first summary', 2, None, 'a-first-summary')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -139,43 +166,43 @@ MathJax.Hub.Config({
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs001.html#___sec0" style="font-size: 80%;"><b>Overview of first week</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs002.html#___sec1" style="font-size: 80%;"><b>Thursday August 20</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs003.html#___sec2" style="font-size: 80%;"><b>Lectures and ComputerLab</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs004.html#___sec3" style="font-size: 80%;"><b>Course Format</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs005.html#___sec4" style="font-size: 80%;"><b>Teachers</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs006.html#___sec5" style="font-size: 80%;"><b>Deadlines for projects (tentative)</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs007.html#___sec6" style="font-size: 80%;"><b>Recommended textbooks</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs008.html#___sec7" style="font-size: 80%;"><b>Prerequisites</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs009.html#___sec8" style="font-size: 80%;"><b>Learning outcomes</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs010.html#___sec9" style="font-size: 80%;"><b>Topics covered in this course: Statistical analysis and optimization of data</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs011.html#___sec10" style="font-size: 80%;"><b>Topics covered in this course: Machine Learning</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs012.html#___sec11" style="font-size: 80%;"><b>Extremely useful tools, strongly recommended</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs013.html#___sec12" style="font-size: 80%;"><b>Other courses on Data science and Machine Learning at UiO</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs014.html#___sec13" style="font-size: 80%;"><b>Introduction</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs015.html#___sec14" style="font-size: 80%;"><b>What is Machine Learning?</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs016.html#___sec15" style="font-size: 80%;"><b>Types of Machine Learning</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs017.html#___sec16" style="font-size: 80%;"><b>Software and needed installations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs018.html#___sec17" style="font-size: 80%;"><b>Python installers</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs019.html#___sec18" style="font-size: 80%;"><b>Useful Python libraries</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs020.html#___sec19" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs021.html#___sec20" style="font-size: 80%;"><b>Installing R, C++, cython, Numba etc</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs022.html#___sec21" style="font-size: 80%;"><b>Numpy examples and Important Matrix and vector handling packages</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs023.html#___sec22" style="font-size: 80%;"><b>Basic Matrix Features</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs024.html#___sec23" style="font-size: 80%;"> Some famous Matrices</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs025.html#___sec24" style="font-size: 80%;"> More Basic Matrix Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs026.html#___sec25" style="font-size: 80%;"><b>Numpy and arrays</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs027.html#___sec26" style="font-size: 80%;"><b>Matrices in Python</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs028.html#___sec27" style="font-size: 80%;"><b>Meet the Pandas</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs029.html#___sec28" style="font-size: 80%;"><b>Friday August 21</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs030.html#___sec29" style="font-size: 80%;"><b>Reading Data and fitting</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs031.html#___sec30" style="font-size: 80%;"><b>Friday August 21</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#___sec31" style="font-size: 80%;"> Simple linear regression model using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#___sec32" style="font-size: 80%;"> To our real data: nuclear binding energies. Brief reminder on masses and binding energies</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#___sec33" style="font-size: 80%;"> Organizing our data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#___sec34" style="font-size: 80%;"> Seeing the wood for the trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#___sec35" style="font-size: 80%;"> And what about using neural networks?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#___sec36" style="font-size: 80%;"><b>A first summary</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs001.html#overview-of-first-week" style="font-size: 80%;"><b>Overview of first week</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs002.html#thursday-august-26" style="font-size: 80%;"><b>Thursday August 26</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs003.html#lectures-and-computerlab" style="font-size: 80%;"><b>Lectures and ComputerLab</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs004.html#course-format" style="font-size: 80%;"><b>Course Format</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs005.html#teachers" style="font-size: 80%;"><b>Teachers</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs006.html#deadlines-for-projects-tentative" style="font-size: 80%;"><b>Deadlines for projects (tentative)</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs007.html#recommended-textbooks" style="font-size: 80%;"><b>Recommended textbooks</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs008.html#prerequisites" style="font-size: 80%;"><b>Prerequisites</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs009.html#learning-outcomes" style="font-size: 80%;"><b>Learning outcomes</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs010.html#topics-covered-in-this-course-statistical-analysis-and-optimization-of-data" style="font-size: 80%;"><b>Topics covered in this course: Statistical analysis and optimization of data</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs011.html#topics-covered-in-this-course-machine-learning" style="font-size: 80%;"><b>Topics covered in this course: Machine Learning</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs012.html#extremely-useful-tools-strongly-recommended" style="font-size: 80%;"><b>Extremely useful tools, strongly recommended</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs013.html#other-courses-on-data-science-and-machine-learning-at-uio" style="font-size: 80%;"><b>Other courses on Data science and Machine Learning at UiO</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs014.html#introduction" style="font-size: 80%;"><b>Introduction</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs015.html#what-is-machine-learning" style="font-size: 80%;"><b>What is Machine Learning?</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs016.html#types-of-machine-learning" style="font-size: 80%;"><b>Types of Machine Learning</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs017.html#software-and-needed-installations" style="font-size: 80%;"><b>Software and needed installations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs018.html#python-installers" style="font-size: 80%;"><b>Python installers</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs019.html#useful-python-libraries" style="font-size: 80%;"><b>Useful Python libraries</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs020.html#installing-r-c-cython-or-julia" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs021.html#installing-r-c-cython-numba-etc" style="font-size: 80%;"><b>Installing R, C++, cython, Numba etc</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs022.html#numpy-examples-and-important-matrix-and-vector-handling-packages" style="font-size: 80%;"><b>Numpy examples and Important Matrix and vector handling packages</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs023.html#basic-matrix-features" style="font-size: 80%;"><b>Basic Matrix Features</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs024.html#some-famous-matrices" style="font-size: 80%;"> Some famous Matrices</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs025.html#more-basic-matrix-features" style="font-size: 80%;"> More Basic Matrix Features</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs026.html#numpy-and-arrays" style="font-size: 80%;"><b>Numpy and arrays</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs027.html#matrices-in-python" style="font-size: 80%;"><b>Matrices in Python</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs028.html#meet-the-pandas" style="font-size: 80%;"><b>Meet the Pandas</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs031.html#friday-august-21" style="font-size: 80%;"><b>Friday August 21</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs030.html#reading-data-and-fitting" style="font-size: 80%;"><b>Reading Data and fitting</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs031.html#friday-august-21" style="font-size: 80%;"><b>Friday August 21</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#simple-linear-regression-model-using-_scikit-learn_" style="font-size: 80%;"> Simple linear regression model using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#to-our-real-data-nuclear-binding-energies-brief-reminder-on-masses-and-binding-energies" style="font-size: 80%;"> To our real data: nuclear binding energies. Brief reminder on masses and binding energies</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#organizing-our-data" style="font-size: 80%;"> Organizing our data</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#seeing-the-wood-for-the-trees" style="font-size: 80%;"> Seeing the wood for the trees</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#and-what-about-using-neural-networks" style="font-size: 80%;"> And what about using neural networks?</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs032.html#a-first-summary" style="font-size: 80%;"><b>A first summary</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -210,7 +237,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Sep 16, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Aug 8, 2021</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -246,13 +273,13 @@ MathJax.Hub.Config({
|
||||
|
||||
<!-- Bootstrap footer
|
||||
<footer>
|
||||
<a href="http://..."><img width="250" align=right src="http://..."></a>
|
||||
<a href="https://..."><img width="250" align=right src="https://..."></a>
|
||||
</footer>
|
||||
-->
|
||||
|
||||
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
<!-- copyright --> © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
</center>
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
|
||||
<meta name="generator" content="DocOnce: https://github.com/doconce/doconce/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="Week 34: Introduction to the course, Logistics and Practicalities">
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
|
||||
<!-- reveal.js: http://lab.hakim.se/reveal-js/ -->
|
||||
<!-- reveal.js: https://lab.hakim.se/reveal-js/ -->
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
|
||||
@@ -76,10 +76,10 @@ document.getElementsByTagName( 'head' )[0].appendChild( link );
|
||||
.reveal .alert-block > p, .alert-block > ul {margin-bottom:1em}
|
||||
/*.reveal .alert li {margin-top: 1em}*/
|
||||
.reveal .alert-block p+p {margin-top:5px}
|
||||
/*.reveal .alert-notice { background-image: url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_notice.png); }
|
||||
.reveal .alert-summary { background-image:url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_summary.png); }
|
||||
.reveal .alert-warning { background-image: url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_warning.png); }
|
||||
.reveal .alert-question {background-image:url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_question.png); } */
|
||||
/*.reveal .alert-notice { background-image: url(https://hplgit.github.io/doconce/bundled/html_images/small_gray_notice.png); }
|
||||
.reveal .alert-summary { background-image:url(https://hplgit.github.io/doconce/bundled/html_images/small_gray_summary.png); }
|
||||
.reveal .alert-warning { background-image: url(https://hplgit.github.io/doconce/bundled/html_images/small_gray_warning.png); }
|
||||
.reveal .alert-question {background-image:url(https://hplgit.github.io/doconce/bundled/html_images/small_gray_question.png); } */
|
||||
|
||||
</style>
|
||||
|
||||
@@ -148,38 +148,38 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p> <br>
|
||||
<center><h4>Sep 16, 2020</h4></center> <!-- date -->
|
||||
<center><h4>Aug 8, 2021</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
<!-- copyright --> © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
</center>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec0">Overview of first week </h2>
|
||||
<h2 id="overview-of-first-week">Overview of first week </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<ul>
|
||||
|
||||
<p><li> Thursday August 20: First lecture: Presentation of the course, aims and content</li>
|
||||
<p><li> Thursday August 26: First lecture: Presentation of the course, aims and content</li>
|
||||
|
||||
<p><li> Thursday: Second Lecture: Start with simple linear regression and repetition of linear algebra and elements of statistics</li>
|
||||
|
||||
<p><li> Friday August 21: Linear regression</li>
|
||||
<p><li> Friday August 27: Linear regression</li>
|
||||
|
||||
<p><li> Computer lab: Wednesdays, 8am-6pm. First time: Wednesday August 26.</li>
|
||||
<p><li> Computer lab: Wednesdays, 8am-6pm. First time: Wednesday August 25.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec1">Thursday August 20 </h2>
|
||||
<h2 id="thursday-august-26">Thursday August 26 </h2>
|
||||
|
||||
<p>
|
||||
<a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/zoom_0.mp4?vrtx=view-as-webpage" target="_blank">Video of Lecture</a>.
|
||||
@@ -187,14 +187,14 @@ MathJax.Hub.Config({
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec2">Lectures and ComputerLab </h2>
|
||||
<h2 id="lectures-and-computerlab">Lectures and ComputerLab </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<ul>
|
||||
|
||||
<p><li> Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm). Due to the present COVID-19 situation all lectures will be online. They will be recorded and posted online at the official UiO <a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/index.html" target="_blank">website</a>.</li>
|
||||
<p><li> Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm).</li>
|
||||
|
||||
<p><li> Weekly reading assignments and videos needed to solve projects and exercises.</li>
|
||||
|
||||
@@ -211,7 +211,7 @@ MathJax.Hub.Config({
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec3">Course Format </h2>
|
||||
<h2 id="course-format">Course Format </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
@@ -239,7 +239,7 @@ MathJax.Hub.Config({
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec4">Teachers </h2>
|
||||
<h2 id="teachers">Teachers </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
@@ -264,17 +264,14 @@ MathJax.Hub.Config({
|
||||
|
||||
<p><li> <b>Office</b>: Department of Physics, University of Oslo, Eastern wing, room FØ452</li>
|
||||
</ul>
|
||||
<p><li> Michael Bitney, m.s.bitney@fys.uio.no</li>
|
||||
<p><li> Kristian Wold, kriswold@student.matnat.uio.no</li>
|
||||
<p><li> Nicolai Haug, nicoha@student.matnat.uio.no</li>
|
||||
<p><li> Per-Dimitri Sønsteland, perdimitri.bs@gmail.com</li>
|
||||
<p>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec5">Deadlines for projects (tentative) </h2>
|
||||
<h2 id="deadlines-for-projects-tentative">Deadlines for projects (tentative) </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
@@ -294,7 +291,7 @@ Projects are handed in using <b>Canvas</b>. We use Github as repository for code
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec6">Recommended textbooks </h2>
|
||||
<h2 id="recommended-textbooks">Recommended textbooks </h2>
|
||||
|
||||
<ul>
|
||||
<p><li> <a href="https://www.springer.com/gp/book/9780387848570" target="_blank">Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer</a></li>
|
||||
@@ -304,7 +301,7 @@ Projects are handed in using <b>Canvas</b>. We use Github as repository for code
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec7">Prerequisites </h2>
|
||||
<h2 id="prerequisites">Prerequisites </h2>
|
||||
|
||||
<p>
|
||||
Basic knowledge in programming and mathematics, with an emphasis on
|
||||
@@ -320,7 +317,7 @@ Python is the recurring programming language.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec8">Learning outcomes </h2>
|
||||
<h2 id="learning-outcomes">Learning outcomes </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
@@ -345,7 +342,7 @@ This course aims at giving you insights and knowledge about many of the central
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec9">Topics covered in this course: Statistical analysis and optimization of data </h2>
|
||||
<h2 id="topics-covered-in-this-course-statistical-analysis-and-optimization-of-data">Topics covered in this course: Statistical analysis and optimization of data </h2>
|
||||
|
||||
<p>
|
||||
The course has two central parts
|
||||
@@ -360,7 +357,7 @@ These topics will be scattered thorughout the course and may not necessarily be
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b>Statistical analysis and optimization of data.</b>
|
||||
<b>Statistical analysis and optimization of data</b>
|
||||
<p>
|
||||
The following topics will be covered
|
||||
|
||||
@@ -378,7 +375,7 @@ The following topics will be covered
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec10">Topics covered in this course: Machine Learning </h2>
|
||||
<h2 id="topics-covered-in-this-course-machine-learning">Topics covered in this course: Machine Learning </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
@@ -405,11 +402,11 @@ Hands-on demonstrations, exercises and projects aim at deepening your understand
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec11">Extremely useful tools, strongly recommended </h2>
|
||||
<h2 id="extremely-useful-tools-strongly-recommended">Extremely useful tools, strongly recommended </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b>and discussed at the lab sessions.</b>
|
||||
<b>and discussed at the lab sessions</b>
|
||||
<ul>
|
||||
|
||||
<p><li> GIT for version control, and GitHub or GitLab as repositories, highly recommended. This will be discussed during the first exercise session</li>
|
||||
@@ -421,7 +418,7 @@ Hands-on demonstrations, exercises and projects aim at deepening your understand
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec12">Other courses on Data science and Machine Learning at UiO </h2>
|
||||
<h2 id="other-courses-on-data-science-and-machine-learning-at-uio">Other courses on Data science and Machine Learning at UiO </h2>
|
||||
|
||||
<p>
|
||||
The link here <a href="https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/" target="_blank"><tt>https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/</tt></a> gives an excellent overview of courses on Machine learning at UiO.
|
||||
@@ -443,7 +440,7 @@ The link here <a href="https://www.mn.uio.no/english/research/about/centre-focus
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec13">Introduction </h2>
|
||||
<h2 id="introduction">Introduction </h2>
|
||||
|
||||
<p>
|
||||
Our emphasis throughout this series of lectures
|
||||
@@ -485,7 +482,7 @@ get started with programming.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec14">What is Machine Learning? </h2>
|
||||
<h2 id="what-is-machine-learning">What is Machine Learning? </h2>
|
||||
|
||||
<p>
|
||||
Statistics, data science and machine learning form important fields of
|
||||
@@ -558,7 +555,7 @@ of algorithms and methods we will discuss.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec15">Types of Machine Learning </h2>
|
||||
<h2 id="types-of-machine-learning">Types of Machine Learning </h2>
|
||||
|
||||
<p>
|
||||
The approaches to machine learning are many, but are often split into
|
||||
@@ -600,7 +597,7 @@ At the heart of basically all ML algorithms there are so-called minimization alg
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec16">Software and needed installations </h2>
|
||||
<h2 id="software-and-needed-installations">Software and needed installations </h2>
|
||||
|
||||
<p>
|
||||
We will make extensive use of Python as programming language and its
|
||||
@@ -646,7 +643,7 @@ etc etc.
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec17">Python installers </h2>
|
||||
<h2 id="python-installers">Python installers </h2>
|
||||
|
||||
<p>
|
||||
If you don't want to perform these operations separately and venture
|
||||
@@ -682,7 +679,7 @@ no setup and runs entirely in the cloud. Try it out!
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec18">Useful Python libraries </h2>
|
||||
<h2 id="useful-python-libraries">Useful Python libraries </h2>
|
||||
Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there)
|
||||
|
||||
<ul>
|
||||
@@ -702,7 +699,7 @@ Here we list several useful Python libraries we strongly recommend (if you use a
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec19">Installing R, C++, cython or Julia </h2>
|
||||
<h2 id="installing-r-c-cython-or-julia">Installing R, C++, cython or Julia </h2>
|
||||
|
||||
<p>
|
||||
You will also find it convenient to utilize <b>R</b>. We will mainly
|
||||
@@ -723,7 +720,7 @@ To install <b>R</b> with Jupyter notebook
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec20">Installing R, C++, cython, Numba etc </h2>
|
||||
<h2 id="installing-r-c-cython-numba-etc">Installing R, C++, cython, Numba etc </h2>
|
||||
|
||||
<p>
|
||||
For the C++ aficionados, Jupyter/IPython notebook allows you also to
|
||||
@@ -747,7 +744,7 @@ further processing. For example, convert to latex as
|
||||
<p>
|
||||
|
||||
<!-- code=text typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>pycod jupyter nbconvert filename.ipynb --to latex
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>pycod jupyter nbconvert filename.ipynb --to latex
|
||||
</pre></div>
|
||||
<p>
|
||||
And to add more versatility, the Python package <a href="http://www.sympy.org/en/index.html" target="_blank">SymPy</a> is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python.
|
||||
@@ -760,7 +757,7 @@ formats, ipython notebooks, latex files, pdf files etc with minimal edits. These
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec21">Numpy examples and Important Matrix and vector handling packages </h2>
|
||||
<h2 id="numpy-examples-and-important-matrix-and-vector-handling-packages">Numpy examples and Important Matrix and vector handling packages </h2>
|
||||
|
||||
<p>
|
||||
There are several central software libraries for linear algebra and eigenvalue problems. Several of the more
|
||||
@@ -780,11 +777,11 @@ developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly he
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec22">Basic Matrix Features </h2>
|
||||
<h2 id="basic-matrix-features">Basic Matrix Features </h2>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b>Matrix properties reminder.</b>
|
||||
<b>Matrix properties reminder</b>
|
||||
<p> <br>
|
||||
$$
|
||||
\mathbf{A} =
|
||||
@@ -831,7 +828,7 @@ $$
|
||||
|
||||
<section>
|
||||
|
||||
<h3 id="___sec23">Some famous Matrices </h3>
|
||||
<h3 id="some-famous-matrices">Some famous Matrices </h3>
|
||||
|
||||
<ul>
|
||||
|
||||
@@ -858,11 +855,11 @@ $$
|
||||
|
||||
<section>
|
||||
|
||||
<h3 id="___sec24">More Basic Matrix Features </h3>
|
||||
<h3 id="more-basic-matrix-features">More Basic Matrix Features </h3>
|
||||
|
||||
<p>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b>Some Equivalent Statements.</b>
|
||||
<b>Some Equivalent Statements</b>
|
||||
<p>
|
||||
For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all equivalent
|
||||
|
||||
@@ -885,22 +882,22 @@ For an \( N\times N \) matrix \( \mathbf{A} \) the following properties are all
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec25">Numpy and arrays </h2>
|
||||
<h2 id="numpy-and-arrays">Numpy and arrays </h2>
|
||||
<a href="http://www.numpy.org/" target="_blank">Numpy</a> provides an easy way to handle arrays in Python. The standard way to import this library is as
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
</pre></div>
|
||||
<p>
|
||||
Here follows a simple example where we set up an array of ten elements, all determined by random numbers drawn according to the normal distribution,
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>n = <span style="color: #B452CD">10</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>n = <span style="color: #B452CD">10</span>
|
||||
x = np.random.normal(size=n)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(x)
|
||||
<span style="color: #658b00">print</span>(x)
|
||||
</pre></div>
|
||||
<p>
|
||||
We defined a vector \( x \) with \( n=10 \) elements with its values given by the Normal distribution \( N(0,1) \).
|
||||
@@ -908,9 +905,9 @@ Another alternative is to declare a vector as follows
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
x = np.array([<span style="color: #B452CD">1</span>, <span style="color: #B452CD">2</span>, <span style="color: #B452CD">3</span>])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(x)
|
||||
<span style="color: #658b00">print</span>(x)
|
||||
</pre></div>
|
||||
<p>
|
||||
Here we have defined a vector with three elements, with \( x_0=1 \), \( x_1=2 \) and \( x_2=3 \). Note that both Python and C++
|
||||
@@ -918,9 +915,9 @@ start numbering array elements from \( 0 \) and on. This means that a vector wit
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
x = np.log(np.array([<span style="color: #B452CD">4</span>, <span style="color: #B452CD">7</span>, <span style="color: #B452CD">8</span>]))
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(x)
|
||||
<span style="color: #658b00">print</span>(x)
|
||||
</pre></div>
|
||||
<p>
|
||||
In the last example we used Numpy's unary function \( np.log \). This function is
|
||||
@@ -934,12 +931,12 @@ logarithms of a vector would be to write
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">math</span> <span style="color: #8B008B; font-weight: bold">import</span> log
|
||||
x = np.array([<span style="color: #B452CD">4</span>, <span style="color: #B452CD">7</span>, <span style="color: #B452CD">8</span>])
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">0</span>, <span style="color: #658b00">len</span>(x)):
|
||||
x[i] = log(x[i])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(x)
|
||||
<span style="color: #658b00">print</span>(x)
|
||||
</pre></div>
|
||||
<p>
|
||||
We note that our code is much longer already and we need to import the <b>log</b> function from the <b>math</b> module.
|
||||
@@ -947,33 +944,33 @@ The attentive reader will also notice that the output is \( [1, 1, 2] \). Python
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
x = np.log(np.array([<span style="color: #B452CD">4</span>, <span style="color: #B452CD">7</span>, <span style="color: #B452CD">8</span>], dtype = np.float64))
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(x)
|
||||
<span style="color: #658b00">print</span>(x)
|
||||
</pre></div>
|
||||
<p>
|
||||
or simply write them as double precision numbers (Python uses 64 bits as default for floating point type variables), that is
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
x = np.log(np.array([<span style="color: #B452CD">4.0</span>, <span style="color: #B452CD">7.0</span>, <span style="color: #B452CD">8.0</span>])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(x)
|
||||
<span style="color: #658b00">print</span>(x)
|
||||
</pre></div>
|
||||
<p>
|
||||
To check the number of bytes (remember that one byte contains eight bits for double precision variables), you can use simple use the <b>itemsize</b> functionality (the array \( x \) is actually an object which inherits the functionalities defined in Numpy) as
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
x = np.log(np.array([<span style="color: #B452CD">4.0</span>, <span style="color: #B452CD">7.0</span>, <span style="color: #B452CD">8.0</span>])
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(x.itemsize)
|
||||
<span style="color: #658b00">print</span>(x.itemsize)
|
||||
</pre></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec26">Matrices in Python </h2>
|
||||
<h2 id="matrices-in-python">Matrices in Python </h2>
|
||||
|
||||
<p>
|
||||
Having defined vectors, we are now ready to try out matrices. We can
|
||||
@@ -983,62 +980,62 @@ lowercase letters for vectors and uppercase letters for matrices)
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
A = np.log(np.array([ [<span style="color: #B452CD">4.0</span>, <span style="color: #B452CD">7.0</span>, <span style="color: #B452CD">8.0</span>], [<span style="color: #B452CD">3.0</span>, <span style="color: #B452CD">10.0</span>, <span style="color: #B452CD">11.0</span>], [<span style="color: #B452CD">4.0</span>, <span style="color: #B452CD">5.0</span>, <span style="color: #B452CD">7.0</span>] ]))
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(A)
|
||||
<span style="color: #658b00">print</span>(A)
|
||||
</pre></div>
|
||||
<p>
|
||||
If we use the <b>shape</b> function we would get \( (3, 3) \) as output, that is verifying that our matrix is a \( 3\times 3 \) matrix. We can slice the matrix and print for example the first column (Python organized matrix elements in a row-major order, see below) as
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
A = np.log(np.array([ [<span style="color: #B452CD">4.0</span>, <span style="color: #B452CD">7.0</span>, <span style="color: #B452CD">8.0</span>], [<span style="color: #B452CD">3.0</span>, <span style="color: #B452CD">10.0</span>, <span style="color: #B452CD">11.0</span>], [<span style="color: #B452CD">4.0</span>, <span style="color: #B452CD">5.0</span>, <span style="color: #B452CD">7.0</span>] ]))
|
||||
<span style="color: #228B22"># print the first column, row-major order and elements start with 0</span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(A[:,<span style="color: #B452CD">0</span>])
|
||||
<span style="color: #658b00">print</span>(A[:,<span style="color: #B452CD">0</span>])
|
||||
</pre></div>
|
||||
<p>
|
||||
We can continue this was by printing out other columns or rows. The example here prints out the second column
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
A = np.log(np.array([ [<span style="color: #B452CD">4.0</span>, <span style="color: #B452CD">7.0</span>, <span style="color: #B452CD">8.0</span>], [<span style="color: #B452CD">3.0</span>, <span style="color: #B452CD">10.0</span>, <span style="color: #B452CD">11.0</span>], [<span style="color: #B452CD">4.0</span>, <span style="color: #B452CD">5.0</span>, <span style="color: #B452CD">7.0</span>] ]))
|
||||
<span style="color: #228B22"># print the first column, row-major order and elements start with 0</span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(A[<span style="color: #B452CD">1</span>,:])
|
||||
<span style="color: #658b00">print</span>(A[<span style="color: #B452CD">1</span>,:])
|
||||
</pre></div>
|
||||
<p>
|
||||
Numpy contains many other functionalities that allow us to slice, subdivide etc etc arrays. We strongly recommend that you look up the <a href="http://www.numpy.org/" target="_blank">Numpy website for more details</a>. Useful functions when defining a matrix are the <b>np.zeros</b> function which declares a matrix of a given dimension and sets all elements to zero
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
n = <span style="color: #B452CD">10</span>
|
||||
<span style="color: #228B22"># define a matrix of dimension 10 x 10 and set all elements to zero</span>
|
||||
A = np.zeros( (n, n) )
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(A)
|
||||
<span style="color: #658b00">print</span>(A)
|
||||
</pre></div>
|
||||
<p>
|
||||
or initializing all elements to
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
n = <span style="color: #B452CD">10</span>
|
||||
<span style="color: #228B22"># define a matrix of dimension 10 x 10 and set all elements to one</span>
|
||||
A = np.ones( (n, n) )
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(A)
|
||||
<span style="color: #658b00">print</span>(A)
|
||||
</pre></div>
|
||||
<p>
|
||||
or as unitarily distributed random numbers (see the material on random number generators in the statistics part)
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
n = <span style="color: #B452CD">10</span>
|
||||
<span style="color: #228B22"># define a matrix of dimension 10 x 10 and set all elements to random numbers with x \in [0, 1]</span>
|
||||
A = np.random.rand(n, n)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(A)
|
||||
<span style="color: #658b00">print</span>(A)
|
||||
</pre></div>
|
||||
<p>
|
||||
As we will see throughout these lectures, there are several extremely useful functionalities in Numpy.
|
||||
@@ -1084,32 +1081,32 @@ covariance matrix through the <b>np.linalg.eig()</b> function.
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
|
||||
n = <span style="color: #B452CD">100</span>
|
||||
x = np.random.normal(size=n)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(x))
|
||||
<span style="color: #658b00">print</span>(np.mean(x))
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.normal(size=n)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(y))
|
||||
<span style="color: #658b00">print</span>(np.mean(y))
|
||||
z = x**<span style="color: #B452CD">3</span>+np.random.normal(size=n)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(z))
|
||||
<span style="color: #658b00">print</span>(np.mean(z))
|
||||
W = np.vstack((x, y, z))
|
||||
Sigma = np.cov(W)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(Sigma)
|
||||
<span style="color: #658b00">print</span>(Sigma)
|
||||
Eigvals, Eigvecs = np.linalg.eig(Sigma)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(Eigvals)
|
||||
<span style="color: #658b00">print</span>(Eigvals)
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> sparse
|
||||
eye = np.eye(<span style="color: #B452CD">4</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(eye)
|
||||
<span style="color: #658b00">print</span>(eye)
|
||||
sparse_mtx = sparse.csr_matrix(eye)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(sparse_mtx)
|
||||
<span style="color: #658b00">print</span>(sparse_mtx)
|
||||
x = np.linspace(-<span style="color: #B452CD">10</span>,<span style="color: #B452CD">10</span>,<span style="color: #B452CD">100</span>)
|
||||
y = np.sin(x)
|
||||
plt.plot(x,y,marker=<span style="color: #CD5555">'x'</span>)
|
||||
@@ -1119,7 +1116,7 @@ plt.show()
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec27">Meet the Pandas </h2>
|
||||
<h2 id="meet-the-pandas">Meet the Pandas </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="fig/pandas.jpg" align="bottom" width=600></p></center><br /><br />
|
||||
@@ -1138,7 +1135,7 @@ The following simple example shows how we can, in an easy way make tables of our
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
|
||||
data = {<span style="color: #CD5555">'First Name'</span>: [<span style="color: #CD5555">"Frodo"</span>, <span style="color: #CD5555">"Bilbo"</span>, <span style="color: #CD5555">"Aragorn II"</span>, <span style="color: #CD5555">"Samwise"</span>],
|
||||
<span style="color: #CD5555">'Last Name'</span>: [<span style="color: #CD5555">"Baggins"</span>, <span style="color: #CD5555">"Baggins"</span>,<span style="color: #CD5555">"Elessar"</span>,<span style="color: #CD5555">"Gamgee"</span>],
|
||||
@@ -1156,7 +1153,7 @@ Displaying these results, we see that the indices are given by the default numbe
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>data_pandas = pd.DataFrame(data,index=[<span style="color: #CD5555">'Frodo'</span>,<span style="color: #CD5555">'Bilbo'</span>,<span style="color: #CD5555">'Aragorn'</span>,<span style="color: #CD5555">'Sam'</span>])
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>data_pandas = pd.DataFrame(data,index=[<span style="color: #CD5555">'Frodo'</span>,<span style="color: #CD5555">'Bilbo'</span>,<span style="color: #CD5555">'Aragorn'</span>,<span style="color: #CD5555">'Sam'</span>])
|
||||
display(data_pandas)
|
||||
</pre></div>
|
||||
<p>
|
||||
@@ -1164,14 +1161,14 @@ Thereafter we display the content of the row which begins with the index <b>Arag
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>display(data_pandas.loc[<span style="color: #CD5555">'Aragorn'</span>])
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>display(data_pandas.loc[<span style="color: #CD5555">'Aragorn'</span>])
|
||||
</pre></div>
|
||||
<p>
|
||||
We can easily append data to this, for example
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>new_hobbit = {<span style="color: #CD5555">'First Name'</span>: [<span style="color: #CD5555">"Peregrin"</span>],
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>new_hobbit = {<span style="color: #CD5555">'First Name'</span>: [<span style="color: #CD5555">"Peregrin"</span>],
|
||||
<span style="color: #CD5555">'Last Name'</span>: [<span style="color: #CD5555">"Took"</span>],
|
||||
<span style="color: #CD5555">'Place of birth'</span>: [<span style="color: #CD5555">"Shire"</span>],
|
||||
<span style="color: #CD5555">'Date of Birth T.A.'</span>: [<span style="color: #B452CD">2990</span>]
|
||||
@@ -1185,7 +1182,7 @@ of dimensionality \( 10\times 5 \) and compute the mean value and standard devia
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
|
||||
np.random.seed(<span style="color: #B452CD">100</span>)
|
||||
@@ -1195,8 +1192,8 @@ cols = <span style="color: #B452CD">5</span>
|
||||
a = np.random.randn(rows,cols)
|
||||
df = pd.DataFrame(a)
|
||||
display(df)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(df.mean())
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(df.std())
|
||||
<span style="color: #658b00">print</span>(df.mean())
|
||||
<span style="color: #658b00">print</span>(df.std())
|
||||
display(df**<span style="color: #B452CD">2</span>)
|
||||
</pre></div>
|
||||
<p>
|
||||
@@ -1204,13 +1201,13 @@ Thereafter we can select specific columns only and plot final results
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>df.columns = [<span style="color: #CD5555">'First'</span>, <span style="color: #CD5555">'Second'</span>, <span style="color: #CD5555">'Third'</span>, <span style="color: #CD5555">'Fourth'</span>, <span style="color: #CD5555">'Fifth'</span>]
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>df.columns = [<span style="color: #CD5555">'First'</span>, <span style="color: #CD5555">'Second'</span>, <span style="color: #CD5555">'Third'</span>, <span style="color: #CD5555">'Fourth'</span>, <span style="color: #CD5555">'Fifth'</span>]
|
||||
df.index = np.arange(<span style="color: #B452CD">10</span>)
|
||||
|
||||
display(df)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(df[<span style="color: #CD5555">'Second'</span>].mean() )
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(df.info())
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(df.describe())
|
||||
<span style="color: #658b00">print</span>(df[<span style="color: #CD5555">'Second'</span>].mean() )
|
||||
<span style="color: #658b00">print</span>(df.info())
|
||||
<span style="color: #658b00">print</span>(df.describe())
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">pylab</span> <span style="color: #8B008B; font-weight: bold">import</span> plt, mpl
|
||||
plt.style.use(<span style="color: #CD5555">'seaborn'</span>)
|
||||
@@ -1228,10 +1225,10 @@ We can produce a \( 4\times 4 \) matrix
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>b = np.arange(<span style="color: #B452CD">16</span>).reshape((<span style="color: #B452CD">4</span>,<span style="color: #B452CD">4</span>))
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(b)
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>b = np.arange(<span style="color: #B452CD">16</span>).reshape((<span style="color: #B452CD">4</span>,<span style="color: #B452CD">4</span>))
|
||||
<span style="color: #658b00">print</span>(b)
|
||||
df1 = pd.DataFrame(b)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(df1)
|
||||
<span style="color: #658b00">print</span>(df1)
|
||||
</pre></div>
|
||||
<p>
|
||||
and many other operations.
|
||||
@@ -1247,7 +1244,7 @@ For multidimensional arrays, we recommend strongly <a href="http://xarray.pydata
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec28">Friday August 21 </h2>
|
||||
<h2 id="friday-august-21">Friday August 21 </h2>
|
||||
|
||||
<p>
|
||||
<a href="https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h20/forelesningsvideoer/LectureAug21.mp4?vrtx=view-as-webpage" target="_blank">Video of Lecture</a> and <a href="https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesAugust21.pdf" target="_blank">Handwritten notes</a>
|
||||
@@ -1255,7 +1252,7 @@ For multidimensional arrays, we recommend strongly <a href="http://xarray.pydata
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec29">Reading Data and fitting </h2>
|
||||
<h2 id="reading-data-and-fitting">Reading Data and fitting </h2>
|
||||
|
||||
<p>
|
||||
In order to study various Machine Learning algorithms, we need to
|
||||
@@ -1294,13 +1291,13 @@ But before we really start with nuclear physics data, let's just look at some si
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec30">Friday August 21 </h2>
|
||||
<h2 id="friday-august-21">Friday August 21 </h2>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
|
||||
<h3 id="___sec31">Simple linear regression model using <b>scikit-learn</b> </h3>
|
||||
<h3 id="simple-linear-regression-model-using-_scikit-learn_">Simple linear regression model using <b>scikit-learn</b> </h3>
|
||||
|
||||
<p>
|
||||
We start with perhaps our simplest possible example, using <b>Scikit-Learn</b> to perform linear regression analysis on a data set produced by us.
|
||||
@@ -1356,7 +1353,7 @@ The Python code follows here.
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> LinearRegression
|
||||
@@ -1458,7 +1455,7 @@ We can modify easily the above Python code and plot the relative error instead
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> LinearRegression
|
||||
|
||||
@@ -1493,7 +1490,7 @@ example of the functionality of <b>Scikit-Learn</b>.
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> LinearRegression
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.metrics</span> <span style="color: #8B008B; font-weight: bold">import</span> mean_squared_error, r2_score, mean_squared_log_error, mean_absolute_error
|
||||
@@ -1503,16 +1500,16 @@ y = <span style="color: #B452CD">2.0</span>+ <span style="color: #B452CD">5</spa
|
||||
linreg = LinearRegression()
|
||||
linreg.fit(x,y)
|
||||
ypredict = linreg.predict(x)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'The intercept alpha: \n'</span>, linreg.intercept_)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Coefficient beta : \n'</span>, linreg.coef_)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'The intercept alpha: \n'</span>, linreg.intercept_)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Coefficient beta : \n'</span>, linreg.coef_)
|
||||
<span style="color: #228B22"># The mean squared error </span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Mean squared error: %.2f"</span> % mean_squared_error(y, ypredict))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Mean squared error: %.2f"</span> % mean_squared_error(y, ypredict))
|
||||
<span style="color: #228B22"># Explained variance score: 1 is perfect prediction </span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Variance score: %.2f'</span> % r2_score(y, ypredict))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Variance score: %.2f'</span> % r2_score(y, ypredict))
|
||||
<span style="color: #228B22"># Mean squared log error </span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Mean squared log error: %.2f'</span> % mean_squared_log_error(y, ypredict) )
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Mean squared log error: %.2f'</span> % mean_squared_log_error(y, ypredict) )
|
||||
<span style="color: #228B22"># Mean absolute error </span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Mean absolute error: %.2f'</span> % mean_absolute_error(y, ypredict))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Mean absolute error: %.2f'</span> % mean_absolute_error(y, ypredict))
|
||||
plt.plot(x, ypredict, <span style="color: #CD5555">"r-"</span>)
|
||||
plt.plot(x, y ,<span style="color: #CD5555">'ro'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0.0</span>,<span style="color: #B452CD">1.0</span>,<span style="color: #B452CD">1.5</span>, <span style="color: #B452CD">7.0</span>])
|
||||
@@ -1606,7 +1603,7 @@ a linear \( x \)-dependence we study now a cubic polynomial and use the polynomi
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">random</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> Ridge
|
||||
@@ -1635,10 +1632,10 @@ plt.show()
|
||||
err=(y-yn)/yn
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> <span style="color: #658b00">abs</span>(np.sum(err))/<span style="color: #658b00">len</span>(err)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">print</span> (error(y))
|
||||
<span style="color: #658b00">print</span> (error(y))
|
||||
</pre></div>
|
||||
|
||||
<h3 id="___sec32">To our real data: nuclear binding energies. Brief reminder on masses and binding energies </h3>
|
||||
<h3 id="to-our-real-data-nuclear-binding-energies-brief-reminder-on-masses-and-binding-energies">To our real data: nuclear binding energies. Brief reminder on masses and binding energies </h3>
|
||||
|
||||
<p>
|
||||
Let us now dive into nuclear physics and remind ourselves briefly about some basic features about binding
|
||||
@@ -1732,7 +1729,7 @@ We could also add a so-called pairing term, which is a correction term that
|
||||
arises from the tendency of proton pairs and neutron pairs to
|
||||
occur. An even number of particles is more stable than an odd number.
|
||||
|
||||
<h3 id="___sec33">Organizing our data </h3>
|
||||
<h3 id="organizing-our-data">Organizing our data </h3>
|
||||
|
||||
<p>
|
||||
Let us start with reading and organizing our data.
|
||||
@@ -1744,7 +1741,7 @@ We start with preparing folders for storing our calculations and the data file o
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Common imports</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #228B22"># Common imports</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
@@ -1774,7 +1771,7 @@ DATA_ID = <span style="color: #CD5555">"DataFiles/"</span>
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">save_fig</span>(fig_id):
|
||||
plt.savefig(image_path(fig_id) + <span style="color: #CD5555">".png"</span>, format=<span style="color: #CD5555">'png'</span>)
|
||||
plt.savefig(image_path(fig_id) + <span style="color: #CD5555">".png"</span>, <span style="color: #658b00">format</span>=<span style="color: #CD5555">'png'</span>)
|
||||
|
||||
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">"MassEval2016.dat"</span>),<span style="color: #CD5555">'r'</span>)
|
||||
</pre></div>
|
||||
@@ -1783,7 +1780,7 @@ Before we proceed, we define also a function for making our plots. You can obvio
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">pylab</span> <span style="color: #8B008B; font-weight: bold">import</span> plt, mpl
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">pylab</span> <span style="color: #8B008B; font-weight: bold">import</span> plt, mpl
|
||||
plt.style.use(<span style="color: #CD5555">'seaborn'</span>)
|
||||
mpl.rcParams[<span style="color: #CD5555">'font.family'</span>] = <span style="color: #CD5555">'serif'</span>
|
||||
|
||||
@@ -1807,7 +1804,7 @@ In particular, the program that outputs the final nuclear masses is written in F
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #CD5555">""" </span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #CD5555">""" </span>
|
||||
<span style="color: #CD5555">This is taken from the data file of the mass 2016 evaluation. </span>
|
||||
<span style="color: #CD5555">All files are 3436 lines long with 124 character per line. </span>
|
||||
<span style="color: #CD5555"> Headers are 39 lines long. </span>
|
||||
@@ -1827,12 +1824,12 @@ covert them into the <b>pandas</b> DataFrame structure.
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Read the experimental data with Pandas</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #228B22"># Read the experimental data with Pandas</span>
|
||||
Masses = pd.read_fwf(infile, usecols=(<span style="color: #B452CD">2</span>,<span style="color: #B452CD">3</span>,<span style="color: #B452CD">4</span>,<span style="color: #B452CD">6</span>,<span style="color: #B452CD">11</span>),
|
||||
names=(<span style="color: #CD5555">'N'</span>, <span style="color: #CD5555">'Z'</span>, <span style="color: #CD5555">'A'</span>, <span style="color: #CD5555">'Element'</span>, <span style="color: #CD5555">'Ebinding'</span>),
|
||||
widths=(<span style="color: #B452CD">1</span>,<span style="color: #B452CD">3</span>,<span style="color: #B452CD">5</span>,<span style="color: #B452CD">5</span>,<span style="color: #B452CD">5</span>,<span style="color: #B452CD">1</span>,<span style="color: #B452CD">3</span>,<span style="color: #B452CD">4</span>,<span style="color: #B452CD">1</span>,<span style="color: #B452CD">13</span>,<span style="color: #B452CD">11</span>,<span style="color: #B452CD">11</span>,<span style="color: #B452CD">9</span>,<span style="color: #B452CD">1</span>,<span style="color: #B452CD">2</span>,<span style="color: #B452CD">11</span>,<span style="color: #B452CD">9</span>,<span style="color: #B452CD">1</span>,<span style="color: #B452CD">3</span>,<span style="color: #B452CD">1</span>,<span style="color: #B452CD">12</span>,<span style="color: #B452CD">11</span>,<span style="color: #B452CD">1</span>),
|
||||
header=<span style="color: #B452CD">39</span>,
|
||||
index_col=<span style="color: #658b00">False</span>)
|
||||
index_col=<span style="color: #8B008B; font-weight: bold">False</span>)
|
||||
|
||||
<span style="color: #228B22"># Extrapolated values are indicated by '#' in place of the decimal place, so</span>
|
||||
<span style="color: #228B22"># the Ebinding column won't be numeric. Coerce to float and drop these entries.</span>
|
||||
@@ -1861,12 +1858,12 @@ the number of nucleons \( A \), the number of protons \( Z \) and the number of
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>A = Masses[<span style="color: #CD5555">'A'</span>]
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>A = Masses[<span style="color: #CD5555">'A'</span>]
|
||||
Z = Masses[<span style="color: #CD5555">'Z'</span>]
|
||||
N = Masses[<span style="color: #CD5555">'N'</span>]
|
||||
Element = Masses[<span style="color: #CD5555">'Element'</span>]
|
||||
Energies = Masses[<span style="color: #CD5555">'Ebinding'</span>]
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(Masses)
|
||||
<span style="color: #658b00">print</span>(Masses)
|
||||
</pre></div>
|
||||
<p>
|
||||
The next step, and we will define this mathematically later, is to set up the so-called <b>design matrix</b>. We will throughout call this matrix \( \boldsymbol{X} \).
|
||||
@@ -1874,7 +1871,7 @@ It has dimensionality \( p\times n \), where \( n \) is the number of data point
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Now we set up the design matrix X</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #228B22"># Now we set up the design matrix X</span>
|
||||
X = np.zeros((<span style="color: #658b00">len</span>(A),<span style="color: #B452CD">5</span>))
|
||||
X[:,<span style="color: #B452CD">0</span>] = <span style="color: #B452CD">1</span>
|
||||
X[:,<span style="color: #B452CD">1</span>] = A
|
||||
@@ -1887,7 +1884,7 @@ With <b>scikitlearn</b> we are now ready to use linear regression and fit our da
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span>clf = skl.LinearRegression().fit(X, Energies)
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span>clf = skl.LinearRegression().fit(X, Energies)
|
||||
fity = clf.predict(X)
|
||||
</pre></div>
|
||||
<p>
|
||||
@@ -1896,13 +1893,13 @@ Now we can print measures of how our fit is doing, the coefficients from the fit
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># The mean squared error </span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">"Mean squared error: %.2f"</span> % mean_squared_error(Energies, fity))
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #228B22"># The mean squared error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Mean squared error: %.2f"</span> % mean_squared_error(Energies, fity))
|
||||
<span style="color: #228B22"># Explained variance score: 1 is perfect prediction </span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Variance score: %.2f'</span> % r2_score(Energies, fity))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Variance score: %.2f'</span> % r2_score(Energies, fity))
|
||||
<span style="color: #228B22"># Mean absolute error </span>
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">'Mean absolute error: %.2f'</span> % mean_absolute_error(Energies, fity))
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(clf.coef_, clf.intercept_)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Mean absolute error: %.2f'</span> % mean_absolute_error(Energies, fity))
|
||||
<span style="color: #658b00">print</span>(clf.coef_, clf.intercept_)
|
||||
|
||||
Masses[<span style="color: #CD5555">'Eapprox'</span>] = fity
|
||||
<span style="color: #228B22"># Generate a plot comparing the experimental with the fitted values values.</span>
|
||||
@@ -1918,7 +1915,7 @@ save_fig(<span style="color: #CD5555">"Masses2016"</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
|
||||
<h3 id="___sec34">Seeing the wood for the trees </h3>
|
||||
<h3 id="seeing-the-wood-for-the-trees">Seeing the wood for the trees </h3>
|
||||
|
||||
<p>
|
||||
As a teaser, let us now see how we can do this with decision trees using <b>scikit-learn</b>. Later we will switch to so-called <b>random forests</b>!
|
||||
@@ -1926,7 +1923,7 @@ As a teaser, let us now see how we can do this with decision trees using <b>scik
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22">#Decision Tree Regression</span>
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #228B22">#Decision Tree Regression</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> DecisionTreeRegressor
|
||||
regr_1=DecisionTreeRegressor(max_depth=<span style="color: #B452CD">5</span>)
|
||||
regr_2=DecisionTreeRegressor(max_depth=<span style="color: #B452CD">7</span>)
|
||||
@@ -1953,18 +1950,18 @@ plt.title(<span style="color: #CD5555">"Decision Tree Regression"</spa
|
||||
plt.legend()
|
||||
save_fig(<span style="color: #CD5555">"Masses2016Trees"</span>)
|
||||
plt.show()
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(Masses)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean( (Energies-y_1)**<span style="color: #B452CD">2</span>))
|
||||
<span style="color: #658b00">print</span>(Masses)
|
||||
<span style="color: #658b00">print</span>(np.mean( (Energies-y_1)**<span style="color: #B452CD">2</span>))
|
||||
</pre></div>
|
||||
|
||||
<h3 id="___sec35">And what about using neural networks? </h3>
|
||||
<h3 id="and-what-about-using-neural-networks">And what about using neural networks? </h3>
|
||||
|
||||
The <b>seaborn</b> package allows us to visualize data in an efficient way. Note that we use <b>scikit-learn</b>'s multi-layer perceptron (or feed forward neural network)
|
||||
functionality.
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.neural_network</span> <span style="color: #8B008B; font-weight: bold">import</span> MLPRegressor
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%;"><span></span><span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.neural_network</span> <span style="color: #8B008B; font-weight: bold">import</span> MLPRegressor
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.metrics</span> <span style="color: #8B008B; font-weight: bold">import</span> accuracy_score
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">seaborn</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">sns</span>
|
||||
|
||||
@@ -1988,14 +1985,14 @@ sns.set()
|
||||
train_accuracy[i][j] = dnn.score(X_train, Y_train)
|
||||
|
||||
fig, ax = plt.subplots(figsize = (<span style="color: #B452CD">10</span>, <span style="color: #B452CD">10</span>))
|
||||
sns.heatmap(train_accuracy, annot=<span style="color: #658b00">True</span>, ax=ax, cmap=<span style="color: #CD5555">"viridis"</span>)
|
||||
sns.heatmap(train_accuracy, annot=<span style="color: #8B008B; font-weight: bold">True</span>, ax=ax, cmap=<span style="color: #CD5555">"viridis"</span>)
|
||||
ax.set_title(<span style="color: #CD5555">"Training Accuracy"</span>)
|
||||
ax.set_ylabel(<span style="color: #CD5555">"$\eta$"</span>)
|
||||
ax.set_xlabel(<span style="color: #CD5555">"$\lambda$"</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
|
||||
<h2 id="___sec36">A first summary </h2>
|
||||
<h2 id="a-first-summary">A first summary </h2>
|
||||
|
||||
<p>
|
||||
The aim behind these introductory words was to present to you various
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+201
-178
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+200
-208
File diff suppressed because one or more lines are too long
@@ -8,15 +8,15 @@ DATE: today
|
||||
===== Overview of first week =====
|
||||
|
||||
!bblock
|
||||
* Thursday August 20: First lecture: Presentation of the course, aims and content
|
||||
* Thursday August 26: First lecture: Presentation of the course, aims and content
|
||||
* Thursday: Second Lecture: Start with simple linear regression and repetition of linear algebra and elements of statistics
|
||||
* Friday August 21: Linear regression
|
||||
* Computer lab: Wednesdays, 8am-6pm. First time: Wednesday August 26.
|
||||
* Friday August 27: Linear regression
|
||||
* Computer lab: Wednesdays, 8am-6pm. First time: Wednesday August 25.
|
||||
!eblock
|
||||
|
||||
|
||||
!split
|
||||
===== Thursday August 20 =====
|
||||
===== Thursday August 26 =====
|
||||
|
||||
"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/zoom_0.mp4?vrtx=view-as-webpage".
|
||||
|
||||
@@ -25,7 +25,7 @@ DATE: today
|
||||
===== Lectures and ComputerLab =====
|
||||
|
||||
!bblock
|
||||
* Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm). Due to the present COVID-19 situation all lectures will be online. They will be recorded and posted online at the official UiO "website":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/index.html".
|
||||
* Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm).
|
||||
* Weekly reading assignments and videos needed to solve projects and exercises.
|
||||
* Weekly exercises when not working on projects. You can hand in exercises if you want.
|
||||
* Detailed lecture notes, exercises, all programs presented, projects etc can be found at the homepage of the course.
|
||||
@@ -65,10 +65,6 @@ _Teachers :_
|
||||
|
||||
* Øyvind Sigmundson Schøyen, oyvinssc@student.matnat.uio.no
|
||||
* _Office_: Department of Physics, University of Oslo, Eastern wing, room FØ452
|
||||
* Michael Bitney, m.s.bitney@fys.uio.no
|
||||
* Kristian Wold, kriswold@student.matnat.uio.no
|
||||
* Nicolai Haug, nicoha@student.matnat.uio.no
|
||||
* Per-Dimitri Sønsteland, perdimitri.bs@gmail.com
|
||||
|
||||
|
||||
!eblock
|
||||
|
||||
Reference in New Issue
Block a user