update on machine learning

This commit is contained in:
mhjensen
2017-12-06 14:13:28 +01:00
parent 2111fd0fbc
commit 3eaf9e4578
70 changed files with 7950 additions and 551 deletions
@@ -46,45 +46,39 @@ Automatically generated HTML file from DocOnce source
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
@@ -128,26 +122,26 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Doing it in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Binning of data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Adding model complexity: Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">The ``new'' discrete bottom-up approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Basic (computer-friendly) mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
@@ -182,7 +176,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>Dec 1, 2017</h4></center> <!-- date -->
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -46,45 +46,39 @@ Automatically generated HTML file from DocOnce source
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
@@ -128,26 +122,26 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Doing it in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Binning of data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Adding model complexity: Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">The ``new'' discrete bottom-up approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Basic (computer-friendly) mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
@@ -0,0 +1,223 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0002"></a>
<!-- !split -->
<h2 id="___sec1" class="anchor">Types of Machine Learning </h2>
<p>
The approaches to machine learning are many, but are often split into two main categories.
In <em>supervised learning</em> we know the answer to a problem,
and let the computer deduce the logic behind it. On the other hand, <em>unsupervised learning</em>
is a method for finding patterns and relationship in data sets without any prior knowledge of the system.
Some authours also operate with a third category, namely <em>reinforcement learning</em>. This is a paradigm
of learning inspired by behavioural psychology, where learning is achieved by trial-and-error,
solely from rewards and punishment.
<p>
Another way to categorize machine learning tasks is to consider the desired output of a system.
Some of the most common tasks are:
<ul>
<li> Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.</li>
<li> Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.</li>
<li> Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.</li>
</ul>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs001.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="._How2ReadData-bs001.html">2</a></li>
<li class="active"><a href="._How2ReadData-bs002.html">3</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs003.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,224 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0003"></a>
<!-- !split -->
<h2 id="___sec2" class="anchor">Different algorithms </h2>
In this course we will build our machine learning approach on a statistical foundation, with elements
from data analysis, stochastic processes etc before we proceed with the following machine learning algorithms
<ol>
<li> Linear regression and its variants</li>
<li> Decision tree algorithms, from simpler to more complex ones</li>
<li> Nearest neighbors models</li>
<li> Bayesian statistics</li>
<li> Support vector machines and finally various variants of</li>
<li> Artifical neural networks</li>
</ol>
Before we proceed however, there are several practicalities with data analysis and software tools we would
like to present. These tools will help us in our understanding of various machine learning algorithms.
<p>
Our emphasis here is on understanding the mathematical aspects of different algorithms, however, where possible
we will emphasize the importance of using available software.
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs002.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="._How2ReadData-bs001.html">2</a></li>
<li><a href="._How2ReadData-bs002.html">3</a></li>
<li class="active"><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs004.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,237 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0004"></a>
<!-- !split -->
<h2 id="___sec3" class="anchor">Software and needed installations </h2>
We will make intensive use of python as programming language and the myriad of available libraries.
Furthermore, you will find IPython/Jupyter notebooks invaluable in your work.
You can run <b>R</b> codes in the Jupyter/IPython notebooks, with the immediate benefit of visualizing your data.
<p>
If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages,
we recommend that you install the following Python packages via <b>pip</b> as
<ol>
<li> pip install numpy scipy matplotlib ipython scikit-learn mglearn sympy pandas pillow</li>
</ol>
For Python3, replace <b>pip</b> with <b>pip3</b>.
<p>
For OSX users we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
for a seamless installation of additional software via for example
<ol>
<li> brew install python3</li>
</ol>
For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
you can use <b>pip</b> as well and simply install Python as
<ol>
<li> sudo apt-get install python3 (or python for pyhton2.7)</li>
</ol>
etc etc.
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs003.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="._How2ReadData-bs001.html">2</a></li>
<li><a href="._How2ReadData-bs002.html">3</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li class="active"><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs005.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,214 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0005"></a>
<!-- !split -->
<h2 id="___sec4" class="anchor">Python installers </h2>
If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up
all relevant dependencies for Python, namely
<ol>
<li> <a href="https://docs.anaconda.com/" target="_self">Anaconda</a> Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system <b>conda</b></li>
<li> <a href="https://www.enthought.com/product/canopy/" target="_self">Enthought canopy</a> is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.</li>
</ol>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs004.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="._How2ReadData-bs001.html">2</a></li>
<li><a href="._How2ReadData-bs002.html">3</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li class="active"><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs006.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,217 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0006"></a>
<!-- !split -->
<h2 id="___sec5" class="anchor">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R.
Jupyter/Ipython notebook allows you run <b>R</b> code interactively in your browser. The software library <b>R</b> is
tuned to statistically analysis and allows for an easy usage of the tools we will discuss in these texts.
<p>
To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-kernel-for-ipython-notebook" target="_self">following the link here</a>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs005.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="._How2ReadData-bs001.html">2</a></li>
<li><a href="._How2ReadData-bs002.html">3</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li class="active"><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs007.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,226 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0007"></a>
<!-- !split -->
<h2 id="___sec6" class="anchor">Installing R, C++, cython or Julia </h2>
<p>
For the C++ affecianodas, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for
either Python or C++ as programming languages.
<p>
To add more entropy, <b>cython</b> can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook
setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility,
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
<p>
This never ends.
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs006.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="._How2ReadData-bs001.html">2</a></li>
<li><a href="._How2ReadData-bs002.html">3</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li class="active"><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs008.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,240 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0008"></a>
<!-- !split -->
<h2 id="___sec7" class="anchor">Introduction to Jupyter notebook and available tools </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> sparse
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
eye <span style="color: #666666">=</span> np<span style="color: #666666">.</span>eye(<span style="color: #666666">4</span>)
<span style="color: #008000; font-weight: bold">print</span>(eye)
sparse_mtx <span style="color: #666666">=</span> sparse<span style="color: #666666">.</span>csr_matrix(eye)
<span style="color: #008000; font-weight: bold">print</span>(sparse_mtx)
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">-10</span>,<span style="color: #666666">10</span>,<span style="color: #666666">100</span>)
y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sin(x)
plt<span style="color: #666666">.</span>plot(x,y,marker<span style="color: #666666">=</span><span style="color: #BA2121">&#39;x&#39;</span>)
plt<span style="color: #666666">.</span>show()
data <span style="color: #666666">=</span> {<span style="color: #BA2121">&#39;Name&#39;</span>: [<span style="color: #BA2121">&quot;John&quot;</span>, <span style="color: #BA2121">&quot;Anna&quot;</span>, <span style="color: #BA2121">&quot;Peter&quot;</span>, <span style="color: #BA2121">&quot;Linda&quot;</span>], <span style="color: #BA2121">&#39;Location&#39;</span>: [<span style="color: #BA2121">&quot;Nairobi&quot;</span>, <span style="color: #BA2121">&quot;Napoli&quot;</span>, <span style="color: #BA2121">&quot;London&quot;</span>, <span style="color: #BA2121">&quot;Buenos Aires&quot;</span>], <span style="color: #BA2121">&#39;Age&#39;</span>:[<span style="color: #666666">51</span>, <span style="color: #666666">21</span>, <span style="color: #666666">34</span>, <span style="color: #666666">45</span>]}
data_pandas <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(data)
display(data_pandas)
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs007.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="._How2ReadData-bs001.html">2</a></li>
<li><a href="._How2ReadData-bs002.html">3</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li class="active"><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs009.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,239 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0009"></a>
<!-- !split -->
<h2 id="___sec8" class="anchor">Representing data, more examples </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> sparse
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">mglearn</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
x, y <span style="color: #666666">=</span> mglearn<span style="color: #666666">.</span>datasets<span style="color: #666666">.</span>make_wave(n_samples<span style="color: #666666">=100</span>)
line <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">-3</span>,<span style="color: #666666">3</span>,<span style="color: #666666">1000</span>,endpoint<span style="color: #666666">=</span><span style="color: #008000">False</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>)
reg <span style="color: #666666">=</span> DecisionTreeRegressor(min_samples_split<span style="color: #666666">=3</span>)<span style="color: #666666">.</span>fit(x,y)
plt<span style="color: #666666">.</span>plot(line, reg<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span><span style="color: #BA2121">&quot;decision tree&quot;</span>)
regline <span style="color: #666666">=</span> LinearRegression()<span style="color: #666666">.</span>fit(x,y)
plt<span style="color: #666666">.</span>plot(line, regline<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Linear Rgression&quot;</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs008.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="._How2ReadData-bs001.html">2</a></li>
<li><a href="._How2ReadData-bs002.html">3</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li class="active"><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs010.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,233 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0010"></a>
<!-- !split -->
<h2 id="___sec9" class="anchor">Predator-Prey model from ecology </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
The population dynamics of a simple predator-prey system is a
classical example shown in many biology textbooks when ecological
systems are discussed. The system contains all elements of the
scientific method:
<ul>
<li> The set up of a specific hypothesis combined with</li>
<li> the experimental methods needed (one can study existing data or perform experiments)</li>
<li> analyzing and interpreting the data and performing further experiments if needed</li>
<li> trying to extract general behaviors and extract eventual laws or patterns</li>
<li> develop mathematical relations for the uncovered regularities/laws and test these by per forming new experiments</li>
</ul>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs009.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs002.html">3</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li class="active"><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs011.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,230 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0011"></a>
<!-- !split -->
<h2 id="___sec10" class="anchor">Case study from Hudson bay </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
Here we start by
<ol>
<li> plotting the data</li>
<li> derive a simple model for the population dynamics</li>
<li> (fitting parameters in the model to the data)</li>
<li> using the model predict the evolution other predator-pray systems</li>
</ol>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs010.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs003.html">4</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li class="active"><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs012.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,263 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0012"></a>
<!-- !split -->
<h2 id="___sec11" class="anchor">Hudson bay data </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
<p>
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
<p>
<div class="row">
<div class="col-xs-3">
<table class="table table-striped table-hover table-condensed">
<thead>
<tr><td align="center"><b>Year</b></td> <td align="center"><b>Hares (x1000)</b></td> <td align="center"><b>Lynx (x1000)</b></td> </tr>
</thead>
<tbody>
<tr><td align="left"> 1900 </td> <td align="right"> 30.0 </td> <td align="right"> 4.0 </td> </tr>
<tr><td align="left"> 1901 </td> <td align="right"> 47.2 </td> <td align="right"> 6.1 </td> </tr>
<tr><td align="left"> 1902 </td> <td align="right"> 70.2 </td> <td align="right"> 9.8 </td> </tr>
<tr><td align="left"> 1903 </td> <td align="right"> 77.4 </td> <td align="right"> 35.2 </td> </tr>
<tr><td align="left"> 1904 </td> <td align="right"> 36.3 </td> <td align="right"> 59.4 </td> </tr>
<tr><td align="left"> 1905 </td> <td align="right"> 20.6 </td> <td align="right"> 41.7 </td> </tr>
<tr><td align="left"> 1906 </td> <td align="right"> 18.1 </td> <td align="right"> 19.0 </td> </tr>
<tr><td align="left"> 1907 </td> <td align="right"> 21.4 </td> <td align="right"> 13.0 </td> </tr>
<tr><td align="left"> 1908 </td> <td align="right"> 22.0 </td> <td align="right"> 8.3 </td> </tr>
<tr><td align="left"> 1909 </td> <td align="right"> 25.4 </td> <td align="right"> 9.1 </td> </tr>
<tr><td align="left"> 1910 </td> <td align="right"> 27.1 </td> <td align="right"> 7.4 </td> </tr>
<tr><td align="left"> 1911 </td> <td align="right"> 40.3 </td> <td align="right"> 8.0 </td> </tr>
<tr><td align="left"> 1912 </td> <td align="right"> 57 </td> <td align="right"> 12.3 </td> </tr>
<tr><td align="left"> 1913 </td> <td align="right"> 76.6 </td> <td align="right"> 19.5 </td> </tr>
<tr><td align="left"> 1914 </td> <td align="right"> 52.3 </td> <td align="right"> 45.7 </td> </tr>
<tr><td align="left"> 1915 </td> <td align="right"> 19.5 </td> <td align="right"> 51.1 </td> </tr>
<tr><td align="left"> 1916 </td> <td align="right"> 11.2 </td> <td align="right"> 29.7 </td> </tr>
<tr><td align="left"> 1917 </td> <td align="right"> 7.6 </td> <td align="right"> 15.8 </td> </tr>
<tr><td align="left"> 1918 </td> <td align="right"> 14.6 </td> <td align="right"> 9.7 </td> </tr>
<tr><td align="left"> 1919 </td> <td align="right"> 16.2 </td> <td align="right"> 10.1 </td> </tr>
<tr><td align="left"> 1920 </td> <td align="right"> 24.7 </td> <td align="right"> 8.6 </td> </tr>
</tbody>
</table>
</div> <!-- col-xs-3 -->
</div> <!-- cell row -->
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs011.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs004.html">5</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li class="active"><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs013.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,245 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0013"></a>
<!-- !split -->
<h2 id="___sec12" class="anchor">Plotting the data </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pypro) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
<span style="color: #408080; font-style: italic"># Load in data file</span>
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
<span style="color: #408080; font-style: italic"># Make arrays containing x-axis and hares and lynx populations</span>
year <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
hares <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
lynx <span style="color: #666666">=</span> data[:,<span style="color: #666666">2</span>]
plt<span style="color: #666666">.</span>plot(year, hares ,<span style="color: #BA2121">&#39;b-+&#39;</span>, year, lynx, <span style="color: #BA2121">&#39;r-o&#39;</span>)
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">1900</span>,<span style="color: #666666">1920</span>,<span style="color: #666666">0</span>, <span style="color: #666666">100.0</span>])
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r&#39;Year&#39;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r&#39;Numbers of hares and lynx &#39;</span>)
plt<span style="color: #666666">.</span>legend((<span style="color: #BA2121">&#39;Hares&#39;</span>,<span style="color: #BA2121">&#39;Lynx&#39;</span>), loc<span style="color: #666666">=</span><span style="color: #BA2121">&#39;upper right&#39;</span>)
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r&#39;Population of hares and lynx from 1900-1920 (x1000)}&#39;</span>)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">&#39;Hudson_Bay_data.pdf&#39;</span>)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">&#39;Hudson_Bay_data.png&#39;</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs012.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs005.html">6</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li class="active"><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs014.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,216 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0014"></a>
<!-- !split -->
<h2 id="___sec13" class="anchor">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs013.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs006.html">7</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li class="active"><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs015.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,242 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0015"></a>
<!-- !split -->
<h2 id="___sec14" class="anchor">Why now create a computer model for the hare and lynx populations? </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
predator-prey system that a rise in prey population is followed (with
a lag) by a rise in the predator population. When the predator
population is sufficiently high, then the prey population begins
dropping. After the prey population falls, then the predator
population falls, which allows the prey population to recover and
complete one cycle of this interaction. Thus, we see that
qualitatively oscillations occur. Can a mathematical model predict
this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
<ul>
<li> We see oscillations in the data</li>
<li> What causes cycles to slow or speed up?</li>
<li> What affects the amplitude of the oscillation or do you expect to see the oscillations damp to a stable equilibrium?</li>
<li> With a model we can better <em>understand the data</em></li>
<li> More important: we can understand the ecology dynamics of
predator-pray populations</li>
</ul>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs014.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs007.html">8</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li class="active"><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs016.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,242 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0016"></a>
<!-- !split -->
<h2 id="___sec15" class="anchor">The traditional (top-down) approach </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
The classical way (in all books) is to present the Lotka-Volterra equations:
$$
\begin{align*}
\frac{dH}{dt} &= H(a - b L)\\
\frac{dL}{dt} &= - L(d - c H)
\end{align*}
$$
<p>
Here,
<ul>
<li> \( H \) is the number of preys</li>
<li> \( L \) the number of predators</li>
<li> \( a \), \( b \), \( d \), \( c \) are parameters</li>
</ul>
Most books quickly establish the model and then use considerable space on
discussing the qualitative properties of this <em>nonlinear system of
ODEs</em> (which cannot be solved)
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs015.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs008.html">9</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li class="active"><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs017.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,227 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0017"></a>
<!-- !split -->
<h2 id="___sec16" class="anchor">Basic mathematics notation </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<ul>
<li> Time points: \( t_0,t_1,\ldots,t_m \)</li>
<li> Uniform distribution of time points: \( t_n=n\Delta t \)</li>
<li> \( H^n \): population of hares at time \( t_n \)</li>
<li> \( L^n \): population of lynx at time \( t_n \)</li>
<li> We want to model the changes in populations, \( \Delta H=H^{n+1}-H^n \)
and \( \Delta L=L^{n+1}-L^n \) during a general time interval \( [t_{n+1},t_n] \)
of length \( \Delta t=t_{n+1}-t_n \)</li>
</ul>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs016.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs009.html">10</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li class="active"><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs018.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,234 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0018"></a>
<!-- !split -->
<h2 id="___sec17" class="anchor">Basic dynamics of the population of hares </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
The population of hares evolves due to births and deaths exactly as a bacteria population:
$$
\Delta H = a \Delta t H^n
$$
However, hares have an additional loss in the population because
they are eaten by lynx.
All the hares and lynx can form
\( H\cdot L \) pairs in total. When such pairs meet during a time
interval \( \Delta t \), there is some
small probablity that the lynx will eat the hare.
So in fraction \( b\Delta t HL \), the lynx eat hares. This
loss of hares must be accounted for. Subtracted in the equation for hares:
$$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs017.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs010.html">11</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li class="active"><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs019.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,235 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0019"></a>
<!-- !split -->
<h2 id="___sec18" class="anchor">Basic dynamics of the population of lynx </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
We assume that the primary growth for the lynx population depends on sufficient food for raising lynx kittens, which implies an adequate source of nutrients from predation on hares. Thus, the growth of the lynx population does not only depend of how many lynx there are, but on how many hares they can eat.
In a time interval \( \Delta t HL \) hares and lynx can meet, and in a
fraction \( b\Delta t HL \) the lynx eats the hare. All of this does not
contribute to the growth of lynx, again just a fraction of
\( b\Delta t HL \) that we write as
\( d\Delta t HL \). In addition, lynx die just as in the population
dynamics with one isolated animal population, leading to a loss
\( -c\Delta t L \).
</div>
</div>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
The accounting of lynx then looks like
$$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs018.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs011.html">12</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li class="active"><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs020.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,233 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0020"></a>
<!-- !split -->
<h2 id="___sec19" class="anchor">Evolution equations </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
By writing up the definition of \( \Delta H \) and \( \Delta L \), and putting
all assumed known terms \( H^n \) and \( L^n \) on the right-hand side, we have
$$ H^{n+1} = H^n + a\Delta t H^n - b\Delta t H^n L^n $$
$$ L^{n+1} = L^n + d\Delta t H^nL^n - c\Delta t L^n $$
<p>
Note:
<ul>
<li> These equations are ready to be implemented!</li>
<li> But to start, we need \( H^0 \) and \( L^0 \) <br />
(which we can get from the data)</li>
<li> We also need values for \( a \), \( b \), \( d \), \( c \)</li>
</ul>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs019.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs012.html">13</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li class="active"><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs021.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,226 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0021"></a>
<!-- !split -->
<h2 id="___sec20" class="anchor">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<ul>
<li> As always, models tend to be general - as here, applicable
to &quot;all&quot; predator-pray systems</li>
<li> The critical issue is whether the <em>interaction</em> between hares and lynx
is sufficiently well modeled by \( \hbox{const}HL \)</li>
<li> The parameters \( a \), \( b \), \( d \), and \( c \) must be
estimated from data</li>
<li> Measure time in years</li>
<li> \( t_0=1900 \), \( t_m=1920 \)</li>
</ul>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs020.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs013.html">14</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li class="active"><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs022.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,262 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0022"></a>
<!-- !split -->
<h2 id="___sec21" class="anchor">The program </h2>
<p>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pypro) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">solver</span>(m, H0, L0, dt, a, b, c, d, t0):
<span style="color: #BA2121; font-style: italic">&quot;&quot;&quot;Solve the difference equations for H and L over m years</span>
<span style="color: #BA2121; font-style: italic"> with time step dt (measured in years.&quot;&quot;&quot;</span>
num_intervals <span style="color: #666666">=</span> <span style="color: #008000">int</span>(m<span style="color: #666666">/</span><span style="color: #008000">float</span>(dt))
t <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(t0, t0 <span style="color: #666666">+</span> m, num_intervals<span style="color: #666666">+1</span>)
H <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(t<span style="color: #666666">.</span>size)
L <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(t<span style="color: #666666">.</span>size)
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">&#39;Init:&#39;</span>, H0, L0, dt)
H[<span style="color: #666666">0</span>] <span style="color: #666666">=</span> H0
L[<span style="color: #666666">0</span>] <span style="color: #666666">=</span> L0
<span style="color: #008000; font-weight: bold">for</span> n <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">0</span>, <span style="color: #008000">len</span>(t)<span style="color: #666666">-1</span>):
H[n<span style="color: #666666">+1</span>] <span style="color: #666666">=</span> H[n] <span style="color: #666666">+</span> a<span style="color: #666666">*</span>dt<span style="color: #666666">*</span>H[n] <span style="color: #666666">-</span> b<span style="color: #666666">*</span>dt<span style="color: #666666">*</span>H[n]<span style="color: #666666">*</span>L[n]
L[n<span style="color: #666666">+1</span>] <span style="color: #666666">=</span> L[n] <span style="color: #666666">+</span> d<span style="color: #666666">*</span>dt<span style="color: #666666">*</span>H[n]<span style="color: #666666">*</span>L[n] <span style="color: #666666">-</span> c<span style="color: #666666">*</span>dt<span style="color: #666666">*</span>L[n]
<span style="color: #008000; font-weight: bold">return</span> H, L, t
<span style="color: #408080; font-style: italic"># Load in data file</span>
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
<span style="color: #408080; font-style: italic"># Make arrays containing x-axis and hares and lynx populations</span>
t_e <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
H_e <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
L_e <span style="color: #666666">=</span> data[:,<span style="color: #666666">2</span>]
<span style="color: #408080; font-style: italic"># Simulate using the model</span>
H, L, t <span style="color: #666666">=</span> solver(m<span style="color: #666666">=20</span>, H0<span style="color: #666666">=34.91</span>, L0<span style="color: #666666">=3.857</span>, dt<span style="color: #666666">=0.1</span>,
a<span style="color: #666666">=0.4807</span>, b<span style="color: #666666">=0.02482</span>, c<span style="color: #666666">=0.9272</span>, d<span style="color: #666666">=0.02756</span>,
t0<span style="color: #666666">=1900</span>)
<span style="color: #408080; font-style: italic"># Visualize simulations and data</span>
plt<span style="color: #666666">.</span>plot(t_e, H_e, <span style="color: #BA2121">&#39;b-+&#39;</span>, t_e, L_e, <span style="color: #BA2121">&#39;r-o&#39;</span>, t, H, <span style="color: #BA2121">&#39;m--&#39;</span>, t, L, <span style="color: #BA2121">&#39;k--&#39;</span>)
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">&#39;Year&#39;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&#39;Numbers of hares and lynx&#39;</span>)
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">1900</span>, <span style="color: #666666">1920</span>, <span style="color: #666666">0</span>, <span style="color: #666666">140</span>])
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r&#39;Population of hares and lynx 1900-1920 (x1000)&#39;</span>)
plt<span style="color: #666666">.</span>legend((<span style="color: #BA2121">&#39;H_e&#39;</span>, <span style="color: #BA2121">&#39;L_e&#39;</span>, <span style="color: #BA2121">&#39;H&#39;</span>, <span style="color: #BA2121">&#39;L&#39;</span>), loc<span style="color: #666666">=</span><span style="color: #BA2121">&#39;upper left&#39;</span>)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">&#39;Hudson_Bay_sim.pdf&#39;</span>)
plt<span style="color: #666666">.</span>savefig(<span style="color: #BA2121">&#39;Hudson_Bay_sim.png&#39;</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs021.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs014.html">15</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li class="active"><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs023.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,211 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0023"></a>
<!-- !split -->
<h2 id="___sec22" class="anchor">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
<p>
If we perform a least-square fitting, we can find optimal values for the parameters \( a \), \( b \), \( d \), \( c \). The optimal parameters are \( a=0.4807 \), \( b=0.02482 \), \( d=0.9272 \) and \( c=0.02756 \). These parameters result in a slightly modified initial conditions, namely \( H(0) = 34.91 \) and \( L(0)=3.857 \). With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs022.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs015.html">16</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li class="active"><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs024.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,233 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0024"></a>
<!-- !split -->
<h2 id="___sec23" class="anchor">Linear regression in Python </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
x <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
y <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
line <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">1900</span>,<span style="color: #666666">1920</span>,<span style="color: #666666">1000</span>,endpoint<span style="color: #666666">=</span><span style="color: #008000">False</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>)
reg <span style="color: #666666">=</span> DecisionTreeRegressor(min_samples_split<span style="color: #666666">=3</span>)<span style="color: #666666">.</span>fit(x<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>),y<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>))
plt<span style="color: #666666">.</span>plot(line, reg<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span><span style="color: #BA2121">&quot;decision tree&quot;</span>)
regline <span style="color: #666666">=</span> LinearRegression()<span style="color: #666666">.</span>fit(x<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>),y<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>))
plt<span style="color: #666666">.</span>plot(line, regline<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Linear Regression&quot;</span>)
plt<span style="color: #666666">.</span>plot(x, y, label<span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Linear Regression&quot;</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs023.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs016.html">17</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li class="active"><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs025.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,233 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0025"></a>
<!-- !split -->
<h2 id="___sec24" class="anchor">Linear Least squares in R </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read<span style="color: #666666">.</span>csv(<span style="color: #BA2121">&quot;src/Hudson_Bay.csv&quot;</span>,header<span style="color: #666666">=</span>T)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay$Year, HudsonBay$Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
attach(HudsonBay)
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>, col<span style="color: #666666">=</span><span style="color: #BA2121">&quot;red&quot;</span>, varwidth<span style="color: #666666">=</span>T, xlab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Years&quot;</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Haresx 1000&quot;</span>)
summary(HudsonBay)
summary(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
library(MASS)
library(ISLR)
scatter<span style="color: #666666">.</span>smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
linearMod <span style="color: #666666">=</span> lm(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span> <span style="color: #666666">~</span> Year)
<span style="color: #008000; font-weight: bold">print</span>(linearMod)
summary(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data<span style="color: #666666">.</span>frame(Year<span style="color: #666666">=</span>c(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">&quot;confidence&quot;</span>)
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs024.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs017.html">18</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li class="active"><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li><a href="._How2ReadData-bs026.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,232 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0026"></a>
<!-- !split -->
<h2 id="___sec25" class="anchor">Non-Linear Least squares in R </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set</span><span style="color: #666666">.</span>seed(<span style="color: #666666">1485</span>)
<span style="color: #008000">len</span> <span style="color: #666666">=</span> <span style="color: #666666">24</span>
x <span style="color: #666666">=</span> runif(<span style="color: #008000">len</span>)
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(<span style="color: #008000">len</span>, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
ds <span style="color: #666666">=</span> data<span style="color: #666666">.</span>frame(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
<span style="color: #008000">str</span>(ds)
plot( y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span><span style="color: #BA2121">&quot;Known cubic with noise&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=2</span>, col <span style="color: #666666">=</span><span style="color: #BA2121">&quot;green&quot;</span>)
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> I(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #008000">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> T)
class(m)
summary(m)
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
power<span style="color: #666666">.</span>se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
plot(y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Fitted power model&quot;</span>, sub <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Blue: fit; green: known&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=</span> <span style="color: #666666">2</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #008000">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;blue&quot;</span>)
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, paste(<span style="color: #BA2121">&quot;y =x^ (&quot;</span>, power, <span style="color: #BA2121">&quot; +/- &quot;</span>, power<span style="color: #666666">.</span>se, <span style="color: #BA2121">&quot;)&quot;</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;&quot;</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs025.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs018.html">19</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li class="active"><a href="._How2ReadData-bs026.html">27</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
@@ -0,0 +1,237 @@
<!--
Automatically generated HTML file from DocOnce source
(https://github.com/hplgit/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="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 2,
'sections': [('What is Machine Learning?', 2, None, '___sec0'),
('Types of Machine Learning', 2, None, '___sec1'),
('Different algorithms', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec16'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec17'),
('Basic dynamics of the population of hares',
2,
None,
'___sec18'),
('Basic dynamics of the population of lynx', 2, None, '___sec19'),
('Evolution equations', 2, None, '___sec20'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec21'),
('The program', 2, None, '___sec22'),
('The plot', 2, None, '___sec23'),
('Linear regression in Python', 2, None, '___sec24'),
('Linear Least squares in R', 2, None, '___sec25'),
('Non-Linear Least squares in R', 2, None, '___sec26')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<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="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">What is Machine Learning?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Types of Machine Learning</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs003.html#___sec2" style="font-size: 80%;">Different algorithms</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">The ``new'' discrete bottom-up approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic (computer-friendly) mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="#___sec26" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0027"></a>
<!-- !split -->
<h2 id="___sec26" class="anchor">Non-Linear Least squares in R </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set</span><span style="color: #666666">.</span>seed(<span style="color: #666666">1485</span>)
<span style="color: #008000">len</span> <span style="color: #666666">=</span> <span style="color: #666666">24</span>
x <span style="color: #666666">=</span> runif(<span style="color: #008000">len</span>)
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(<span style="color: #008000">len</span>, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
ds <span style="color: #666666">=</span> data<span style="color: #666666">.</span>frame(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
<span style="color: #008000">str</span>(ds)
plot( y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span><span style="color: #BA2121">&quot;Known cubic with noise&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=2</span>, col <span style="color: #666666">=</span><span style="color: #BA2121">&quot;green&quot;</span>)
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> I(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #008000">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> T)
class(m)
summary(m)
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
power<span style="color: #666666">.</span>se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
plot(y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Fitted power model&quot;</span>, sub <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Blue: fit; green: known&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=</span> <span style="color: #666666">2</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #008000">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;blue&quot;</span>)
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, paste(<span style="color: #BA2121">&quot;y =x^ (&quot;</span>, power, <span style="color: #BA2121">&quot; +/- &quot;</span>, power<span style="color: #666666">.</span>se, <span style="color: #BA2121">&quot;)&quot;</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;&quot;</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
</pre></div>
<p>
</div>
</div>
<p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li><a href="._How2ReadData-bs026.html">&laquo;</a></li>
<li><a href="._How2ReadData-bs000.html">1</a></li>
<li><a href="">...</a></li>
<li><a href="._How2ReadData-bs019.html">20</a></li>
<li><a href="._How2ReadData-bs020.html">21</a></li>
<li><a href="._How2ReadData-bs021.html">22</a></li>
<li><a href="._How2ReadData-bs022.html">23</a></li>
<li><a href="._How2ReadData-bs023.html">24</a></li>
<li><a href="._How2ReadData-bs024.html">25</a></li>
<li><a href="._How2ReadData-bs025.html">26</a></li>
<li><a href="._How2ReadData-bs026.html">27</a></li>
<li class="active"><a href="._How2ReadData-bs027.html">28</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="http://..."><img width="250" align=right src="http://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright only on the titlepage -->
</center>
</body>
</html>
+41 -47
View File
@@ -46,45 +46,39 @@ Automatically generated HTML file from DocOnce source
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
@@ -128,26 +122,26 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._How2ReadData-bs004.html#___sec3" style="font-size: 80%;">Software and needed installations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs005.html#___sec4" style="font-size: 80%;">Python installers</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs006.html#___sec5" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Doing it in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, overarching aims</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Binning of data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Adding model complexity: Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">The ``new'' discrete bottom-up approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Basic (computer-friendly) mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs007.html#___sec6" style="font-size: 80%;">Installing R, C++, cython or Julia</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs008.html#___sec7" style="font-size: 80%;">Introduction to Jupyter notebook and available tools</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs009.html#___sec8" style="font-size: 80%;">Representing data, more examples</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs010.html#___sec9" style="font-size: 80%;">Predator-Prey model from ecology</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs011.html#___sec10" style="font-size: 80%;">Case study from Hudson bay</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs012.html#___sec11" style="font-size: 80%;">Hudson bay data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs013.html#___sec12" style="font-size: 80%;">Plotting the data</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs014.html#___sec13" style="font-size: 80%;">Hares and lynx in Hudson bay from 1900 to 1920</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs015.html#___sec14" style="font-size: 80%;">Why now create a computer model for the hare and lynx populations?</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs016.html#___sec15" style="font-size: 80%;">The traditional (top-down) approach</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs017.html#___sec16" style="font-size: 80%;">Basic mathematics notation</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs018.html#___sec17" style="font-size: 80%;">Basic dynamics of the population of hares</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs019.html#___sec18" style="font-size: 80%;">Basic dynamics of the population of lynx</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs020.html#___sec19" style="font-size: 80%;">Evolution equations</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs021.html#___sec20" style="font-size: 80%;">Adapt the model to the Hudson Bay case</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs022.html#___sec21" style="font-size: 80%;">The program</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs023.html#___sec22" style="font-size: 80%;">The plot</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs024.html#___sec23" style="font-size: 80%;">Linear regression in Python</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs025.html#___sec24" style="font-size: 80%;">Linear Least squares in R</a></li>
<!-- navigation toc: --> <li><a href="._How2ReadData-bs026.html#___sec25" style="font-size: 80%;">Non-Linear Least squares in R</a></li>
</ul>
</li>
@@ -182,7 +176,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>Dec 1, 2017</h4></center> <!-- date -->
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>&nbsp;<br>
<center><h4>Dec 1, 2017</h4></center> <!-- date -->
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<br>
<p>
@@ -274,8 +274,8 @@ If you don't want to perform these operations separately, we recommend two widel
all relevant dependencies for Python, namely
<ol>
<p><li> anaconda</li>
<p><li> Enthought canopy</li>
<p><li> <a href="https://docs.anaconda.com/" target="_blank">Anaconda</a> Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system <b>conda</b></li>
<p><li> <a href="https://www.enthought.com/product/canopy/" target="_blank">Enthought canopy</a> is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.</li>
</ol>
</section>
@@ -284,10 +284,18 @@ all relevant dependencies for Python, namely
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R. Say more about R.
You will also find it convenient to utilize R.
Jupyter/Ipython notebook allows you run <b>R</b> code interactively in your browser. The software library <b>R</b> is
tuned to statistically analysis and allows for an easy usage of the tools we will discuss in these texts.
<p>
To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-kernel-for-ipython-notebook" target="_blank">following the link here</a>
</section>
<section>
<h2 id="___sec6">Installing R, C++, cython or Julia </h2>
<p>
For the C++ affecianodas, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for
@@ -300,27 +308,16 @@ including symbolic operations, Python offers a unique computational environment.
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
<p>
This never ends,
<p>
If you se the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
This never ends.
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
</section>
<section>
<h2 id="___sec6">Introduction to Jupyter notebook and available tools </h2>
</section>
<h2 id="___sec7">Introduction to Jupyter notebook and available tools </h2>
<section>
<h2 id="___sec7">Doing it in R </h2>
Use the Hudson bay model to load data and make plot in R and with python
</section>
<section>
<h2 id="___sec8">Representing data, overarching aims </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -339,7 +336,7 @@ x = np.linspace(-<span style="color: #B452CD">10</span>,<span style="color: #B45
y = np.sin(x)
plt.plot(x,y,marker=<span style="color: #CD5555">&#39;x&#39;</span>)
plt.show()
data = {<span style="color: #CD5555">&#39;Name&#39;</span>: [<span style="color: #CD5555">&quot;John&quot;</span>, <span style="color: #CD5555">&quot;Anna&quot;</span>, <span style="color: #CD5555">&quot;Peter&quot;</span>, <span style="color: #CD5555">&quot;Linda&quot;</span>], <span style="color: #CD5555">&#39;Location&#39;</span>: [<span style="color: #CD5555">&quot;Roma&quot;</span>, <span style="color: #CD5555">&quot;Napoli&quot;</span>, <span style="color: #CD5555">&quot;Torino&quot;</span>, <span style="color: #CD5555">&quot;Milano&quot;</span>], <span style="color: #CD5555">&#39;Age&#39;</span>:[<span style="color: #B452CD">51</span>, <span style="color: #B452CD">21</span>, <span style="color: #B452CD">34</span>, <span style="color: #B452CD">45</span>]}
data = {<span style="color: #CD5555">&#39;Name&#39;</span>: [<span style="color: #CD5555">&quot;John&quot;</span>, <span style="color: #CD5555">&quot;Anna&quot;</span>, <span style="color: #CD5555">&quot;Peter&quot;</span>, <span style="color: #CD5555">&quot;Linda&quot;</span>], <span style="color: #CD5555">&#39;Location&#39;</span>: [<span style="color: #CD5555">&quot;Nairobi&quot;</span>, <span style="color: #CD5555">&quot;Napoli&quot;</span>, <span style="color: #CD5555">&quot;London&quot;</span>, <span style="color: #CD5555">&quot;Buenos Aires&quot;</span>], <span style="color: #CD5555">&#39;Age&#39;</span>:[<span style="color: #B452CD">51</span>, <span style="color: #B452CD">21</span>, <span style="color: #B452CD">34</span>, <span style="color: #B452CD">45</span>]}
data_pandas = pd.DataFrame(data)
display(data_pandas)
</pre></div>
@@ -349,7 +346,7 @@ display(data_pandas)
<section>
<h2 id="___sec9">Representing data, more examples </h2>
<h2 id="___sec8">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -378,13 +375,7 @@ plt.show()
<section>
<h2 id="___sec10">Binning of data </h2>
Use the Hudson bay model to load data and make plot in R and with python
</section>
<section>
<h2 id="___sec11">Adding model complexity: Predator-Prey model from ecology </h2>
<h2 id="___sec9">Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -407,14 +398,14 @@ scientific method:
<section>
<h2 id="___sec12">Case study from Hudson bay </h2>
<h2 id="___sec10">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
We shall demonstrate the scientific method by
Here we start by
<ol>
<p><li> plotting the data</li>
@@ -427,18 +418,16 @@ We shall demonstrate the scientific method by
<section>
<h2 id="___sec13">Hudson bay data </h2>
<h2 id="___sec11">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
<p>
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
% endif
<p>
<table border="1">
@@ -475,7 +464,7 @@ One reason that this particular system has been so extensively studied is that t
<section>
<h2 id="___sec14">Plotting the data </h2>
<h2 id="___sec12">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -487,7 +476,7 @@ One reason that this particular system has been so extensively studied is that t
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">import</span> pyplot <span style="color: #8B008B; font-weight: bold">as</span> plt
<span style="color: #228B22"># Load in data file</span>
data = np.loadtxt(<span style="color: #CD5555">&#39;Hudson_Bay.dat&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
data = np.loadtxt(<span style="color: #CD5555">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
<span style="color: #228B22"># Make arrays containing x-axis and hares and lynx populations</span>
year = data[:,<span style="color: #B452CD">0</span>]
hares = data[:,<span style="color: #B452CD">1</span>]
@@ -505,27 +494,22 @@ plt.show()
</pre></div>
</div>
<p>
% if FORMAT != 'ipynb':
</section>
<section>
<h2 id="___sec15">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<h2 id="___sec13">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
% endif
</section>
<section>
<h2 id="___sec16">Why now create a computer model for the hare and lynx populations? </h2>
<h2 id="___sec14">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
@@ -540,7 +524,6 @@ this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
% else:
<ul>
<p><li> We see oscillations in the data</li>
@@ -550,15 +533,12 @@ climate and other complicating factors. How significant are these?
<p><li> More important: we can understand the ecology dynamics of
predator-pray populations</li>
</ul>
<p>
% endif
</div>
</section>
<section>
<h2 id="___sec17">The traditional (top-down) approach </h2>
<h2 id="___sec15">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -593,28 +573,7 @@ ODEs</em> (which cannot be solved)
<section>
<h2 id="___sec18">The &quot;new&quot; discrete bottom-up approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b>The bottom-up approach.</b>
<ul>
<p><li class="fragment"> Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.</li>
<p><li class="fragment"> Where appropriate the students should do the experiment(s) needed to collect the data.</li>
<p><li class="fragment"> The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.</li>
<p><li class="fragment"> Now we want to increase the understanding through modeling.</li>
<p><li class="fragment"> Most of the biology lies in the <em>derivation</em> of the model. We shall
focus on an intuitive discrete approach that leads to difference
equations that can be programmed <em>and solved</em> directly.</li>
</ul>
</div>
</section>
<section>
<h2 id="___sec19">Basic (computer-friendly) mathematics notation </h2>
<h2 id="___sec16">Basic mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<ul>
@@ -631,7 +590,7 @@ ODEs</em> (which cannot be solved)
<section>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<h2 id="___sec17">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -652,8 +611,7 @@ All the hares and lynx can form
interval \( \Delta t \), there is some
small probablity that the lynx will eat the hare.
So in fraction \( b\Delta t HL \), the lynx eat hares. This
loss of hares and must be accounted for:
subtracted in the equation for hares:
loss of hares must be accounted for. Subtracted in the equation for hares:
<p>&nbsp;<br>
$$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
@@ -663,7 +621,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<section>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<h2 id="___sec18">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -692,7 +650,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<section>
<h2 id="___sec22">Evolution equations </h2>
<h2 id="___sec19">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -723,7 +681,7 @@ Note:
<section>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<h2 id="___sec20">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -743,7 +701,7 @@ Note:
<section>
<h2 id="___sec24">The program </h2>
<h2 id="___sec21">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -763,7 +721,7 @@ Note:
H = np.zeros(t.size)
L = np.zeros(t.size)
<span style="color: #8B008B; font-weight: bold">print</span> <span style="color: #CD5555">&#39;Init:&#39;</span>, H0, L0, dt
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">&#39;Init:&#39;</span>, H0, L0, dt)
H[<span style="color: #B452CD">0</span>] = H0
L[<span style="color: #B452CD">0</span>] = L0
@@ -773,7 +731,7 @@ Note:
<span style="color: #8B008B; font-weight: bold">return</span> H, L, t
<span style="color: #228B22"># Load in data file</span>
data = np.loadtxt(<span style="color: #CD5555">&#39;Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
data = np.loadtxt(<span style="color: #CD5555">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
<span style="color: #228B22"># Make arrays containing x-axis and hares and lynx populations</span>
t_e = data[:,<span style="color: #B452CD">0</span>]
H_e = data[:,<span style="color: #B452CD">1</span>]
@@ -797,22 +755,112 @@ plt.show()
</pre></div>
</div>
<p>
% if FORMAT != 'ipynb':
</section>
<section>
<h2 id="___sec25">The plot </h2>
<h2 id="___sec22">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
<p>
% else:
If we perform a least-square fitting, we can find optimal values for the parameters \( a \), \( b \), \( d \), \( c \). The optimal parameters are \( a=0.4807 \), \( b=0.02482 \), \( d=0.9272 \) and \( c=0.02756 \). These parameters result in a slightly modified initial conditions, namely \( H(0) = 34.91 \) and \( L(0)=3.857 \). With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
% endif
</section>
<section>
<h2 id="___sec23">Linear regression in Python </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></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>
<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">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">sklearn</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.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> DecisionTreeRegressor
data = np.loadtxt(<span style="color: #CD5555">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
x = data[:,<span style="color: #B452CD">0</span>]
y = data[:,<span style="color: #B452CD">1</span>]
line = np.linspace(<span style="color: #B452CD">1900</span>,<span style="color: #B452CD">1920</span>,<span style="color: #B452CD">1000</span>,endpoint=<span style="color: #658b00">False</span>).reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>)
reg = DecisionTreeRegressor(min_samples_split=<span style="color: #B452CD">3</span>).fit(x.reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>),y.reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>))
plt.plot(line, reg.predict(line), label=<span style="color: #CD5555">&quot;decision tree&quot;</span>)
regline = LinearRegression().fit(x.reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>),y.reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>))
plt.plot(line, regline.predict(line), label= <span style="color: #CD5555">&quot;Linear Regression&quot;</span>)
plt.plot(x, y, label= <span style="color: #CD5555">&quot;Linear Regression&quot;</span>)
plt.show()
</pre></div>
</div>
</section>
<section>
<h2 id="___sec24">Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></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>HudsonBay = read.csv(<span style="color: #CD5555">&quot;src/Hudson_Bay.csv&quot;</span>,header=T)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Year, HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Hares..x1000.)
attach(HudsonBay)
plot(Year, Hares..x1000.)
plot(Year, Hares..x1000., col=<span style="color: #CD5555">&quot;red&quot;</span>, varwidth=T, xlab=<span style="color: #CD5555">&quot;Years&quot;</span>, ylab=<span style="color: #CD5555">&quot;Haresx 1000&quot;</span>)
summary(HudsonBay)
summary(Hares..x1000.)
library(MASS)
library(ISLR)
scatter.smooth(x=Year, y = Hares..x1000.)
linearMod = lm(Hares..x1000. ~ Year)
<span style="color: #8B008B; font-weight: bold">print</span>(linearMod)
summary(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">&quot;confidence&quot;</span>)
</pre></div>
</div>
</section>
<section>
<h2 id="___sec25">Non-Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></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: #658b00">set</span>.seed(<span style="color: #B452CD">1485</span>)
<span style="color: #658b00">len</span> = <span style="color: #B452CD">24</span>
x = runif(<span style="color: #658b00">len</span>)
y = x^<span style="color: #B452CD">3</span>+rnorm(<span style="color: #658b00">len</span>, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
ds = data.frame(x = x, y = y)
<span style="color: #658b00">str</span>(ds)
plot( y ~ x, main =<span style="color: #CD5555">&quot;Known cubic with noise&quot;</span>)
s = seq(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
lines(s, s^<span style="color: #B452CD">3</span>, lty =<span style="color: #B452CD">2</span>, col =<span style="color: #CD5555">&quot;green&quot;</span>)
m = nls(y ~ I(x^power), data = ds, start = <span style="color: #658b00">list</span>(power=<span style="color: #B452CD">1</span>), trace = T)
class(m)
summary(m)
power = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
power.se = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
plot(y ~ x, main = <span style="color: #CD5555">&quot;Fitted power model&quot;</span>, sub = <span style="color: #CD5555">&quot;Blue: fit; green: known&quot;</span>)
s = seq(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
lines(s, s^<span style="color: #B452CD">3</span>, lty = <span style="color: #B452CD">2</span>, col = <span style="color: #CD5555">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #658b00">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">&quot;blue&quot;</span>)
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, paste(<span style="color: #CD5555">&quot;y =x^ (&quot;</span>, power, <span style="color: #CD5555">&quot; +/- &quot;</span>, power.se, <span style="color: #CD5555">&quot;)&quot;</span>, sep = <span style="color: #CD5555">&quot;&quot;</span>), pos = <span style="color: #B452CD">4</span>)
</pre></div>
</div>
</section>
@@ -66,45 +66,39 @@ div { text-align: justify; text-justify: inter-word; }
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
@@ -146,7 +140,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>Dec 1, 2017</h4></center> <!-- date -->
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -258,8 +252,8 @@ If you don't want to perform these operations separately, we recommend two widel
all relevant dependencies for Python, namely
<ol>
<li> anaconda</li>
<li> Enthought canopy</li>
<li> <a href="https://docs.anaconda.com/" target="_blank">Anaconda</a> Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system <b>conda</b></li>
<li> <a href="https://www.enthought.com/product/canopy/" target="_blank">Enthought canopy</a> is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.</li>
</ol>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -267,10 +261,18 @@ all relevant dependencies for Python, namely
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R. Say more about R.
You will also find it convenient to utilize R.
Jupyter/Ipython notebook allows you run <b>R</b> code interactively in your browser. The software library <b>R</b> is
tuned to statistically analysis and allows for an easy usage of the tools we will discuss in these texts.
<p>
To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-kernel-for-ipython-notebook" target="_blank">following the link here</a>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec6">Installing R, C++, cython or Julia </h2>
<p>
For the C++ affecianodas, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for
@@ -283,27 +285,16 @@ including symbolic operations, Python offers a unique computational environment.
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
<p>
This never ends,
<p>
If you se the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
This never ends.
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec6">Introduction to Jupyter notebook and available tools </h2>
<h2 id="___sec7">Introduction to Jupyter notebook and available tools </h2>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec7">Doing it in R </h2>
Use the Hudson bay model to load data and make plot in R and with python
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, overarching aims </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -323,7 +314,7 @@ x = np.linspace(-<span style="color: #B452CD">10</span>,<span style="color: #B45
y = np.sin(x)
plt.plot(x,y,marker=<span style="color: #CD5555">&#39;x&#39;</span>)
plt.show()
data = {<span style="color: #CD5555">&#39;Name&#39;</span>: [<span style="color: #CD5555">&quot;John&quot;</span>, <span style="color: #CD5555">&quot;Anna&quot;</span>, <span style="color: #CD5555">&quot;Peter&quot;</span>, <span style="color: #CD5555">&quot;Linda&quot;</span>], <span style="color: #CD5555">&#39;Location&#39;</span>: [<span style="color: #CD5555">&quot;Roma&quot;</span>, <span style="color: #CD5555">&quot;Napoli&quot;</span>, <span style="color: #CD5555">&quot;Torino&quot;</span>, <span style="color: #CD5555">&quot;Milano&quot;</span>], <span style="color: #CD5555">&#39;Age&#39;</span>:[<span style="color: #B452CD">51</span>, <span style="color: #B452CD">21</span>, <span style="color: #B452CD">34</span>, <span style="color: #B452CD">45</span>]}
data = {<span style="color: #CD5555">&#39;Name&#39;</span>: [<span style="color: #CD5555">&quot;John&quot;</span>, <span style="color: #CD5555">&quot;Anna&quot;</span>, <span style="color: #CD5555">&quot;Peter&quot;</span>, <span style="color: #CD5555">&quot;Linda&quot;</span>], <span style="color: #CD5555">&#39;Location&#39;</span>: [<span style="color: #CD5555">&quot;Nairobi&quot;</span>, <span style="color: #CD5555">&quot;Napoli&quot;</span>, <span style="color: #CD5555">&quot;London&quot;</span>, <span style="color: #CD5555">&quot;Buenos Aires&quot;</span>], <span style="color: #CD5555">&#39;Age&#39;</span>:[<span style="color: #B452CD">51</span>, <span style="color: #B452CD">21</span>, <span style="color: #B452CD">34</span>, <span style="color: #B452CD">45</span>]}
data_pandas = pd.DataFrame(data)
display(data_pandas)
</pre></div>
@@ -334,7 +325,7 @@ display(data_pandas)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec9">Representing data, more examples </h2>
<h2 id="___sec8">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -365,13 +356,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Binning of data </h2>
Use the Hudson bay model to load data and make plot in R and with python
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Adding model complexity: Predator-Prey model from ecology </h2>
<h2 id="___sec9">Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -395,14 +380,14 @@ scientific method:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Case study from Hudson bay </h2>
<h2 id="___sec10">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
We shall demonstrate the scientific method by
Here we start by
<ol>
<li> plotting the data</li>
@@ -416,18 +401,18 @@ We shall demonstrate the scientific method by
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Hudson bay data </h2>
<h2 id="___sec11">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
<p>
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
<p>
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
% endif
<p>
<table border="1">
@@ -465,7 +450,7 @@ One reason that this particular system has been so extensively studied is that t
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Plotting the data </h2>
<h2 id="___sec12">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -478,7 +463,7 @@ One reason that this particular system has been so extensively studied is that t
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">matplotlib</span> <span style="color: #8B008B; font-weight: bold">import</span> pyplot <span style="color: #8B008B; font-weight: bold">as</span> plt
<span style="color: #228B22"># Load in data file</span>
data = np.loadtxt(<span style="color: #CD5555">&#39;Hudson_Bay.dat&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
data = np.loadtxt(<span style="color: #CD5555">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
<span style="color: #228B22"># Make arrays containing x-axis and hares and lynx populations</span>
year = data[:,<span style="color: #B452CD">0</span>]
hares = data[:,<span style="color: #B452CD">1</span>]
@@ -499,23 +484,20 @@ plt.show()
<p>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<h2 id="___sec13">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
% endif
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Why now create a computer model for the hare and lynx populations? </h2>
<h2 id="___sec14">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
@@ -530,7 +512,6 @@ this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
% else:
<ul>
<li> We see oscillations in the data</li>
@@ -540,15 +521,13 @@ climate and other complicating factors. How significant are these?
<li> More important: we can understand the ecology dynamics of
predator-pray populations</li>
</ul>
% endif
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">The traditional (top-down) approach </h2>
<h2 id="___sec15">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -581,32 +560,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">The &quot;new&quot; discrete bottom-up approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b>The bottom-up approach.</b>
<p>
<!-- !bpop -->
<ul>
<li> Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.</li>
<li> Where appropriate the students should do the experiment(s) needed to collect the data.</li>
<li> The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.</li>
<li> Now we want to increase the understanding through modeling.</li>
<li> Most of the biology lies in the <em>derivation</em> of the model. We shall
focus on an intuitive discrete approach that leads to difference
equations that can be programmed <em>and solved</em> directly.</li>
</ul>
<!-- !epop -->
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">Basic (computer-friendly) mathematics notation </h2>
<h2 id="___sec16">Basic mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -626,7 +580,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<h2 id="___sec17">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -645,8 +599,7 @@ All the hares and lynx can form
interval \( \Delta t \), there is some
small probablity that the lynx will eat the hare.
So in fraction \( b\Delta t HL \), the lynx eat hares. This
loss of hares and must be accounted for:
subtracted in the equation for hares:
loss of hares must be accounted for. Subtracted in the equation for hares:
$$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
</div>
@@ -655,7 +608,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<h2 id="___sec18">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -684,7 +637,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec22">Evolution equations </h2>
<h2 id="___sec19">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -713,7 +666,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<h2 id="___sec20">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -736,7 +689,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">The program </h2>
<h2 id="___sec21">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -757,7 +710,7 @@ Note:
H = np.zeros(t.size)
L = np.zeros(t.size)
<span style="color: #8B008B; font-weight: bold">print</span> <span style="color: #CD5555">&#39;Init:&#39;</span>, H0, L0, dt
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">&#39;Init:&#39;</span>, H0, L0, dt)
H[<span style="color: #B452CD">0</span>] = H0
L[<span style="color: #B452CD">0</span>] = L0
@@ -767,7 +720,7 @@ Note:
<span style="color: #8B008B; font-weight: bold">return</span> H, L, t
<span style="color: #228B22"># Load in data file</span>
data = np.loadtxt(<span style="color: #CD5555">&#39;Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
data = np.loadtxt(<span style="color: #CD5555">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
<span style="color: #228B22"># Make arrays containing x-axis and hares and lynx populations</span>
t_e = data[:,<span style="color: #B452CD">0</span>]
H_e = data[:,<span style="color: #B452CD">1</span>]
@@ -794,18 +747,116 @@ plt.show()
<p>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">The plot </h2>
<h2 id="___sec22">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
<p>
% else:
If we perform a least-square fitting, we can find optimal values for the parameters \( a \), \( b \), \( d \), \( c \). The optimal parameters are \( a=0.4807 \), \( b=0.02482 \), \( d=0.9272 \) and \( c=0.02756 \). These parameters result in a slightly modified initial conditions, namely \( H(0) = 34.91 \) and \( L(0)=3.857 \). With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
% endif
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Linear regression in Python </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="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">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">sklearn</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.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> DecisionTreeRegressor
data = np.loadtxt(<span style="color: #CD5555">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter=<span style="color: #CD5555">&#39;,&#39;</span>, skiprows=<span style="color: #B452CD">1</span>)
x = data[:,<span style="color: #B452CD">0</span>]
y = data[:,<span style="color: #B452CD">1</span>]
line = np.linspace(<span style="color: #B452CD">1900</span>,<span style="color: #B452CD">1920</span>,<span style="color: #B452CD">1000</span>,endpoint=<span style="color: #658b00">False</span>).reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>)
reg = DecisionTreeRegressor(min_samples_split=<span style="color: #B452CD">3</span>).fit(x.reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>),y.reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>))
plt.plot(line, reg.predict(line), label=<span style="color: #CD5555">&quot;decision tree&quot;</span>)
regline = LinearRegression().fit(x.reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>),y.reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>))
plt.plot(line, regline.predict(line), label= <span style="color: #CD5555">&quot;Linear Regression&quot;</span>)
plt.plot(x, y, label= <span style="color: #CD5555">&quot;Linear Regression&quot;</span>)
plt.show()
</pre></div>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span>HudsonBay = read.csv(<span style="color: #CD5555">&quot;src/Hudson_Bay.csv&quot;</span>,header=T)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Year, HudsonBay<span style="color: #a61717; background-color: #e3d2d2">$</span>Hares..x1000.)
attach(HudsonBay)
plot(Year, Hares..x1000.)
plot(Year, Hares..x1000., col=<span style="color: #CD5555">&quot;red&quot;</span>, varwidth=T, xlab=<span style="color: #CD5555">&quot;Years&quot;</span>, ylab=<span style="color: #CD5555">&quot;Haresx 1000&quot;</span>)
summary(HudsonBay)
summary(Hares..x1000.)
library(MASS)
library(ISLR)
scatter.smooth(x=Year, y = Hares..x1000.)
linearMod = lm(Hares..x1000. ~ Year)
<span style="color: #8B008B; font-weight: bold">print</span>(linearMod)
summary(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data.frame(Year=c(<span style="color: #B452CD">1910</span>,<span style="color: #B452CD">1914</span>,<span style="color: #B452CD">1920</span>)),interval=<span style="color: #CD5555">&quot;confidence&quot;</span>)
</pre></div>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">Non-Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #658b00">set</span>.seed(<span style="color: #B452CD">1485</span>)
<span style="color: #658b00">len</span> = <span style="color: #B452CD">24</span>
x = runif(<span style="color: #658b00">len</span>)
y = x^<span style="color: #B452CD">3</span>+rnorm(<span style="color: #658b00">len</span>, <span style="color: #B452CD">0</span>,<span style="color: #B452CD">0.06</span>)
ds = data.frame(x = x, y = y)
<span style="color: #658b00">str</span>(ds)
plot( y ~ x, main =<span style="color: #CD5555">&quot;Known cubic with noise&quot;</span>)
s = seq(<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>,length =<span style="color: #B452CD">100</span>)
lines(s, s^<span style="color: #B452CD">3</span>, lty =<span style="color: #B452CD">2</span>, col =<span style="color: #CD5555">&quot;green&quot;</span>)
m = nls(y ~ I(x^power), data = ds, start = <span style="color: #658b00">list</span>(power=<span style="color: #B452CD">1</span>), trace = T)
class(m)
summary(m)
power = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">1</span>], <span style="color: #B452CD">3</span>)
power.se = <span style="color: #658b00">round</span>(summary(m)<span style="color: #a61717; background-color: #e3d2d2">$</span>coefficients[<span style="color: #B452CD">2</span>], <span style="color: #B452CD">3</span>)
plot(y ~ x, main = <span style="color: #CD5555">&quot;Fitted power model&quot;</span>, sub = <span style="color: #CD5555">&quot;Blue: fit; green: known&quot;</span>)
s = seq(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, length = <span style="color: #B452CD">100</span>)
lines(s, s^<span style="color: #B452CD">3</span>, lty = <span style="color: #B452CD">2</span>, col = <span style="color: #CD5555">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #658b00">list</span>(x = s)), lty = <span style="color: #B452CD">1</span>, col = <span style="color: #CD5555">&quot;blue&quot;</span>)
text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</span>, paste(<span style="color: #CD5555">&quot;y =x^ (&quot;</span>, power, <span style="color: #CD5555">&quot; +/- &quot;</span>, power.se, <span style="color: #CD5555">&quot;)&quot;</span>, sep = <span style="color: #CD5555">&quot;&quot;</span>), pos = <span style="color: #B452CD">4</span>)
</pre></div>
</div>
<p>
+159 -108
View File
@@ -71,45 +71,39 @@ div { text-align: justify; text-justify: inter-word; }
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec6'),
('Doing it in R', 2, None, '___sec7'),
('Representing data, overarching aims', 2, None, '___sec8'),
('Representing data, more examples', 2, None, '___sec9'),
('Binning of data', 2, None, '___sec10'),
('Adding model complexity: Predator-Prey model from ecology',
2,
None,
'___sec11'),
('Case study from Hudson bay', 2, None, '___sec12'),
('Hudson bay data', 2, None, '___sec13'),
('Plotting the data', 2, None, '___sec14'),
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Predator-Prey model from ecology', 2, None, '___sec9'),
('Case study from Hudson bay', 2, None, '___sec10'),
('Hudson bay data', 2, None, '___sec11'),
('Plotting the data', 2, None, '___sec12'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec15'),
'___sec13'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec16'),
('The traditional (top-down) approach', 2, None, '___sec17'),
("The ``new'' discrete bottom-up approach", 2, None, '___sec18'),
('Basic (computer-friendly) mathematics notation',
2,
None,
'___sec19'),
'___sec14'),
('The traditional (top-down) approach', 2, None, '___sec15'),
('Basic mathematics notation', 2, None, '___sec16'),
('Basic dynamics of the population of hares',
2,
None,
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25')]}
'___sec17'),
('Basic dynamics of the population of lynx', 2, None, '___sec18'),
('Evolution equations', 2, None, '___sec19'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec20'),
('The program', 2, None, '___sec21'),
('The plot', 2, None, '___sec22'),
('Linear regression in Python', 2, None, '___sec23'),
('Linear Least squares in R', 2, None, '___sec24'),
('Non-Linear Least squares in R', 2, None, '___sec25')]}
end of tocinfo -->
<body>
@@ -151,7 +145,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>Dec 1, 2017</h4></center> <!-- date -->
<center><h4>Dec 6, 2017</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -263,8 +257,8 @@ If you don't want to perform these operations separately, we recommend two widel
all relevant dependencies for Python, namely
<ol>
<li> anaconda</li>
<li> Enthought canopy</li>
<li> <a href="https://docs.anaconda.com/" target="_blank">Anaconda</a> Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system <b>conda</b></li>
<li> <a href="https://www.enthought.com/product/canopy/" target="_blank">Enthought canopy</a> is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.</li>
</ol>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -272,10 +266,18 @@ all relevant dependencies for Python, namely
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R. Say more about R.
You will also find it convenient to utilize R.
Jupyter/Ipython notebook allows you run <b>R</b> code interactively in your browser. The software library <b>R</b> is
tuned to statistically analysis and allows for an easy usage of the tools we will discuss in these texts.
<p>
To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-kernel-for-ipython-notebook" target="_blank">following the link here</a>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec6">Installing R, C++, cython or Julia </h2>
<p>
For the C++ affecianodas, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for
@@ -288,27 +290,16 @@ including symbolic operations, Python offers a unique computational environment.
can easily be converted into a nicely rendered <b>PDF</b> file or a Latex file for further processing.
<p>
This never ends,
<p>
If you se the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
This never ends.
If you use the light mark-up language <b>doconce</b> you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec6">Introduction to Jupyter notebook and available tools </h2>
<h2 id="___sec7">Introduction to Jupyter notebook and available tools </h2>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec7">Doing it in R </h2>
Use the Hudson bay model to load data and make plot in R and with python
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, overarching aims </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -328,7 +319,7 @@ x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>l
y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sin(x)
plt<span style="color: #666666">.</span>plot(x,y,marker<span style="color: #666666">=</span><span style="color: #BA2121">&#39;x&#39;</span>)
plt<span style="color: #666666">.</span>show()
data <span style="color: #666666">=</span> {<span style="color: #BA2121">&#39;Name&#39;</span>: [<span style="color: #BA2121">&quot;John&quot;</span>, <span style="color: #BA2121">&quot;Anna&quot;</span>, <span style="color: #BA2121">&quot;Peter&quot;</span>, <span style="color: #BA2121">&quot;Linda&quot;</span>], <span style="color: #BA2121">&#39;Location&#39;</span>: [<span style="color: #BA2121">&quot;Roma&quot;</span>, <span style="color: #BA2121">&quot;Napoli&quot;</span>, <span style="color: #BA2121">&quot;Torino&quot;</span>, <span style="color: #BA2121">&quot;Milano&quot;</span>], <span style="color: #BA2121">&#39;Age&#39;</span>:[<span style="color: #666666">51</span>, <span style="color: #666666">21</span>, <span style="color: #666666">34</span>, <span style="color: #666666">45</span>]}
data <span style="color: #666666">=</span> {<span style="color: #BA2121">&#39;Name&#39;</span>: [<span style="color: #BA2121">&quot;John&quot;</span>, <span style="color: #BA2121">&quot;Anna&quot;</span>, <span style="color: #BA2121">&quot;Peter&quot;</span>, <span style="color: #BA2121">&quot;Linda&quot;</span>], <span style="color: #BA2121">&#39;Location&#39;</span>: [<span style="color: #BA2121">&quot;Nairobi&quot;</span>, <span style="color: #BA2121">&quot;Napoli&quot;</span>, <span style="color: #BA2121">&quot;London&quot;</span>, <span style="color: #BA2121">&quot;Buenos Aires&quot;</span>], <span style="color: #BA2121">&#39;Age&#39;</span>:[<span style="color: #666666">51</span>, <span style="color: #666666">21</span>, <span style="color: #666666">34</span>, <span style="color: #666666">45</span>]}
data_pandas <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(data)
display(data_pandas)
</pre></div>
@@ -339,7 +330,7 @@ display(data_pandas)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec9">Representing data, more examples </h2>
<h2 id="___sec8">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -370,13 +361,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Binning of data </h2>
Use the Hudson bay model to load data and make plot in R and with python
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Adding model complexity: Predator-Prey model from ecology </h2>
<h2 id="___sec9">Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -400,14 +385,14 @@ scientific method:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Case study from Hudson bay </h2>
<h2 id="___sec10">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
We shall demonstrate the scientific method by
Here we start by
<ol>
<li> plotting the data</li>
@@ -421,18 +406,18 @@ We shall demonstrate the scientific method by
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Hudson bay data </h2>
<h2 id="___sec11">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
<p>
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
<p>
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
% endif
<p>
<table border="1">
@@ -470,7 +455,7 @@ One reason that this particular system has been so extensively studied is that t
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Plotting the data </h2>
<h2 id="___sec12">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -483,7 +468,7 @@ One reason that this particular system has been so extensively studied is that t
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
<span style="color: #408080; font-style: italic"># Load in data file</span>
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;Hudson_Bay.dat&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
<span style="color: #408080; font-style: italic"># Make arrays containing x-axis and hares and lynx populations</span>
year <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
hares <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
@@ -504,23 +489,20 @@ plt<span style="color: #666666">.</span>show()
<p>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<h2 id="___sec13">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
% endif
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Why now create a computer model for the hare and lynx populations? </h2>
<h2 id="___sec14">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
% if FORMAT == 'ipynb':
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
@@ -535,7 +517,6 @@ this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
% else:
<ul>
<li> We see oscillations in the data</li>
@@ -545,15 +526,13 @@ climate and other complicating factors. How significant are these?
<li> More important: we can understand the ecology dynamics of
predator-pray populations</li>
</ul>
% endif
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">The traditional (top-down) approach </h2>
<h2 id="___sec15">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -586,32 +565,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">The &quot;new&quot; discrete bottom-up approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
<b>The bottom-up approach.</b>
<p>
<!-- !bpop -->
<ul>
<li> Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.</li>
<li> Where appropriate the students should do the experiment(s) needed to collect the data.</li>
<li> The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.</li>
<li> Now we want to increase the understanding through modeling.</li>
<li> Most of the biology lies in the <em>derivation</em> of the model. We shall
focus on an intuitive discrete approach that leads to difference
equations that can be programmed <em>and solved</em> directly.</li>
</ul>
<!-- !epop -->
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">Basic (computer-friendly) mathematics notation </h2>
<h2 id="___sec16">Basic mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -631,7 +585,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<h2 id="___sec17">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -650,8 +604,7 @@ All the hares and lynx can form
interval \( \Delta t \), there is some
small probablity that the lynx will eat the hare.
So in fraction \( b\Delta t HL \), the lynx eat hares. This
loss of hares and must be accounted for:
subtracted in the equation for hares:
loss of hares must be accounted for. Subtracted in the equation for hares:
$$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
</div>
@@ -660,7 +613,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<h2 id="___sec18">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -689,7 +642,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec22">Evolution equations </h2>
<h2 id="___sec19">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -718,7 +671,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<h2 id="___sec20">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -741,7 +694,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">The program </h2>
<h2 id="___sec21">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -762,7 +715,7 @@ Note:
H <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(t<span style="color: #666666">.</span>size)
L <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(t<span style="color: #666666">.</span>size)
<span style="color: #008000; font-weight: bold">print</span> <span style="color: #BA2121">&#39;Init:&#39;</span>, H0, L0, dt
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">&#39;Init:&#39;</span>, H0, L0, dt)
H[<span style="color: #666666">0</span>] <span style="color: #666666">=</span> H0
L[<span style="color: #666666">0</span>] <span style="color: #666666">=</span> L0
@@ -772,7 +725,7 @@ Note:
<span style="color: #008000; font-weight: bold">return</span> H, L, t
<span style="color: #408080; font-style: italic"># Load in data file</span>
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;Hudson_Bay.csv&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
<span style="color: #408080; font-style: italic"># Make arrays containing x-axis and hares and lynx populations</span>
t_e <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
H_e <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
@@ -799,18 +752,116 @@ plt<span style="color: #666666">.</span>show()
<p>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">The plot </h2>
<h2 id="___sec22">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
<p>
% else:
If we perform a least-square fitting, we can find optimal values for the parameters \( a \), \( b \), \( d \), \( c \). The optimal parameters are \( a=0.4807 \), \( b=0.02482 \), \( d=0.9272 \) and \( c=0.02756 \). These parameters result in a slightly modified initial conditions, namely \( H(0) = 34.91 \) and \( L(0)=3.857 \). With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
% endif
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Linear regression in Python </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">&#39;src/Hudson_Bay.csv&#39;</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">&#39;,&#39;</span>, skiprows<span style="color: #666666">=1</span>)
x <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
y <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
line <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">1900</span>,<span style="color: #666666">1920</span>,<span style="color: #666666">1000</span>,endpoint<span style="color: #666666">=</span><span style="color: #008000">False</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>)
reg <span style="color: #666666">=</span> DecisionTreeRegressor(min_samples_split<span style="color: #666666">=3</span>)<span style="color: #666666">.</span>fit(x<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>),y<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>))
plt<span style="color: #666666">.</span>plot(line, reg<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span><span style="color: #BA2121">&quot;decision tree&quot;</span>)
regline <span style="color: #666666">=</span> LinearRegression()<span style="color: #666666">.</span>fit(x<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>),y<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>))
plt<span style="color: #666666">.</span>plot(line, regline<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Linear Regression&quot;</span>)
plt<span style="color: #666666">.</span>plot(x, y, label<span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Linear Regression&quot;</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span>HudsonBay <span style="color: #666666">=</span> read<span style="color: #666666">.</span>csv(<span style="color: #BA2121">&quot;src/Hudson_Bay.csv&quot;</span>,header<span style="color: #666666">=</span>T)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay$Year, HudsonBay$Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
attach(HudsonBay)
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
plot(Year, Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>, col<span style="color: #666666">=</span><span style="color: #BA2121">&quot;red&quot;</span>, varwidth<span style="color: #666666">=</span>T, xlab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Years&quot;</span>, ylab<span style="color: #666666">=</span><span style="color: #BA2121">&quot;Haresx 1000&quot;</span>)
summary(HudsonBay)
summary(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
library(MASS)
library(ISLR)
scatter<span style="color: #666666">.</span>smooth(x<span style="color: #666666">=</span>Year, y <span style="color: #666666">=</span> Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span>)
linearMod <span style="color: #666666">=</span> lm(Hares<span style="color: #666666">..</span>x1000<span style="color: #666666">.</span> <span style="color: #666666">~</span> Year)
<span style="color: #008000; font-weight: bold">print</span>(linearMod)
summary(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data<span style="color: #666666">.</span>frame(Year<span style="color: #666666">=</span>c(<span style="color: #666666">1910</span>,<span style="color: #666666">1914</span>,<span style="color: #666666">1920</span>)),interval<span style="color: #666666">=</span><span style="color: #BA2121">&quot;confidence&quot;</span>)
</pre></div>
</div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">Non-Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000">set</span><span style="color: #666666">.</span>seed(<span style="color: #666666">1485</span>)
<span style="color: #008000">len</span> <span style="color: #666666">=</span> <span style="color: #666666">24</span>
x <span style="color: #666666">=</span> runif(<span style="color: #008000">len</span>)
y <span style="color: #666666">=</span> x<span style="color: #666666">^3+</span>rnorm(<span style="color: #008000">len</span>, <span style="color: #666666">0</span>,<span style="color: #666666">0.06</span>)
ds <span style="color: #666666">=</span> data<span style="color: #666666">.</span>frame(x <span style="color: #666666">=</span> x, y <span style="color: #666666">=</span> y)
<span style="color: #008000">str</span>(ds)
plot( y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span><span style="color: #BA2121">&quot;Known cubic with noise&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,length <span style="color: #666666">=100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=2</span>, col <span style="color: #666666">=</span><span style="color: #BA2121">&quot;green&quot;</span>)
m <span style="color: #666666">=</span> nls(y <span style="color: #666666">~</span> I(x<span style="color: #666666">^</span>power), data <span style="color: #666666">=</span> ds, start <span style="color: #666666">=</span> <span style="color: #008000">list</span>(power<span style="color: #666666">=1</span>), trace <span style="color: #666666">=</span> T)
class(m)
summary(m)
power <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">1</span>], <span style="color: #666666">3</span>)
power<span style="color: #666666">.</span>se <span style="color: #666666">=</span> <span style="color: #008000">round</span>(summary(m)$coefficients[<span style="color: #666666">2</span>], <span style="color: #666666">3</span>)
plot(y <span style="color: #666666">~</span> x, main <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Fitted power model&quot;</span>, sub <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Blue: fit; green: known&quot;</span>)
s <span style="color: #666666">=</span> seq(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, length <span style="color: #666666">=</span> <span style="color: #666666">100</span>)
lines(s, s<span style="color: #666666">^3</span>, lty <span style="color: #666666">=</span> <span style="color: #666666">2</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;green&quot;</span>)
lines(s, predict(m, <span style="color: #008000">list</span>(x <span style="color: #666666">=</span> s)), lty <span style="color: #666666">=</span> <span style="color: #666666">1</span>, col <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;blue&quot;</span>)
text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</span>, paste(<span style="color: #BA2121">&quot;y =x^ (&quot;</span>, power, <span style="color: #BA2121">&quot; +/- &quot;</span>, power<span style="color: #666666">.</span>se, <span style="color: #BA2121">&quot;)&quot;</span>, sep <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;&quot;</span>), pos <span style="color: #666666">=</span> <span style="color: #666666">4</span>)
</pre></div>
</div>
<p>
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

@@ -0,0 +1,22 @@
Year,Hares (x1000),Lynx (x1000)
1900,30.0,4.0
1901,47.2,6.1
1902,70.2,9.8
1903,77.4,35.2
1904,36.3,59.4
1905,20.6,41.7
1906,18.1,19.0
1907,21.4,13.0
1908,22.0,8.3
1909,25.4,9.1
1910,27.1,7.4
1911,40.3,8.0
1912,57,12.3
1913,76.6,19.5
1914,52.3,45.7
1915,19.5,51.1
1916,11.2,29.7
1917,7.6,15.8
1918,14.6,9.7
1919,16.2,10.1
1920,24.7,8.6
1 Year Hares (x1000) Lynx (x1000)
2 1900 30.0 4.0
3 1901 47.2 6.1
4 1902 70.2 9.8
5 1903 77.4 35.2
6 1904 36.3 59.4
7 1905 20.6 41.7
8 1906 18.1 19.0
9 1907 21.4 13.0
10 1908 22.0 8.3
11 1909 25.4 9.1
12 1910 27.1 7.4
13 1911 40.3 8.0
14 1912 57 12.3
15 1913 76.6 19.5
16 1914 52.3 45.7
17 1915 19.5 51.1
18 1916 11.2 29.7
19 1917 7.6 15.8
20 1918 14.6 9.7
21 1919 16.2 10.1
22 1920 24.7 8.6
@@ -0,0 +1,43 @@
import numpy as np
import matplotlib.pyplot as plt
def solver(m, H0, L0, dt, a, b, c, d, t0):
"""Solve the difference equations for H and L over m years
with time step dt (measured in years."""
num_intervals = int(m/float(dt))
t = np.linspace(t0, t0 + m, num_intervals+1)
H = np.zeros(t.size)
L = np.zeros(t.size)
print('Init:', H0, L0, dt)
H[0] = H0
L[0] = L0
for n in range(0, len(t)-1):
H[n+1] = H[n] + a*dt*H[n] - b*dt*H[n]*L[n]
L[n+1] = L[n] + d*dt*H[n]*L[n] - c*dt*L[n]
return H, L, t
# Load in data file
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
# Make arrays containing x-axis and hares and lynx populations
t_e = data[:,0]
H_e = data[:,1]
L_e = data[:,2]
# Simulate using the model
H, L, t = solver(m=20, H0=34.91, L0=3.857, dt=0.1,
a=0.4807, b=0.02482, c=0.9272, d=0.02756,
t0=1900)
# Visualize simulations and data
plt.plot(t_e, H_e, 'b-+', t_e, L_e, 'r-o', t, H, 'm--', t, L, 'k--')
plt.xlabel('Year')
plt.ylabel('Numbers of hares and lynx')
plt.axis([1900, 1920, 0, 140])
plt.title(r'Population of hares and lynx 1900-1920 (x1000)')
plt.legend(('H_e', 'L_e', 'H', 'L'), loc='upper left')
plt.savefig('Hudson_Bay_sim.pdf')
plt.savefig('Hudson_Bay_sim.png')
plt.show()
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

+12
View File
@@ -0,0 +1,12 @@
import numpy as np
t = np.linspace(0, 10, 21) # 20 intervals in [0, 10]
dt = t[1] - t[0]
N = np.zeros(t.size)
N[0] = 1
r = 0.5
for n in range(0, N.size-1, 1):
N[n+1] = N[n] + r*dt*N[n]
print 'N[%d]=%.1f' % (n+1, N[n+1])
+11
View File
@@ -0,0 +1,11 @@
0,100
600,140
1200,250
1800,360
2400,480
3000,820
3600,1300
4200,1700
4800,2900
5400,3900
6000,7000
1 0 100
2 600 140
3 1200 250
4 1800 360
5 2400 480
6 3000 820
7 3600 1300
8 4200 1700
9 4800 2900
10 5400 3900
11 6000 7000
+27
View File
@@ -0,0 +1,27 @@
import numpy as np
# Estimate r
data = np.loadtxt('ecoli.csv', delimiter=',')
t_e = data[:,0]
N_e = data[:,1]
i = 2 # Data point (i,i+1) used to estimate r
r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i]))
print 'Estimated r=%.5f' % r
# Can experiment with r values and see if the model can
# match the data better
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, 1000)
dt = t[1] - t[0]
N = np.zeros(t.size)
N[0] = 100
for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
import matplotlib.pyplot as plt
plt.plot(t, N, 'r-', t_e, N_e, 'bo')
plt.xlabel('time [s]'); plt.ylabel('N')
plt.legend(['model', 'experiment'], loc='upper left')
plt.show()
@@ -0,0 +1,27 @@
import numpy as np
data = np.loadtxt('ecoli.csv', delimiter=',')
t_experiment = data[:,0]
N_experiment = data[:,1]
def error(p):
r = p[0]
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, len(t_experiment))
dt = (t[1] - t[0])
N = np.zeros(t.size)
N[0] = 100
for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
e = np.sqrt(np.sum((N - N_experiment)**2))/N[0] # error measure
e = abs(N[-1] - N_experiment[-1])/N[0]
print 'r=', r, 'e=',e
return e
from scipy.optimize import minimize
p = minimize(error, [0.0006], tol=1E-5)
print p
@@ -0,0 +1,19 @@
import numpy as np
from matplotlib import pyplot as plt
# Load in data file
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
# Make arrays containing x-axis and hares and lynx populations
year = data[:,0]
hares = data[:,1]
lynx = data[:,2]
plt.plot(year, hares ,'b-+', year, lynx, 'r-o')
plt.axis([1900,1920,0, 100.0])
plt.xlabel(r'Year')
plt.ylabel(r'Numbers of hares and lynx ')
plt.legend(('Hares','Lynx'), loc='upper right')
plt.title(r'Population of hares and lynx from 1900-1920 (x1000)}')
plt.savefig('Hudson_Bay_data.pdf')
plt.savefig('Hudson_Bay_data.png')
plt.show()
+129 -55
View File
@@ -10,7 +10,7 @@
"<!-- Author: --> \n",
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
"\n",
"Date: **Dec 1, 2017**\n",
"Date: **Dec 6, 2017**\n",
"\n",
"Copyright 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
@@ -101,16 +101,23 @@
"## Python installers\n",
"If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up \n",
"all relevant dependencies for Python, namely\n",
"1. anaconda\n",
"1. [Anaconda](https://docs.anaconda.com/) Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system **conda**\n",
"\n",
"2. Enthought canopy\n",
"2. [Enthought canopy](https://www.enthought.com/product/canopy/) is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.\n",
"\n",
"## Installing R, C++, cython or Julia\n",
"\n",
"You will also find it convenient to utilize R. Say more about R. \n",
"You will also find it convenient to utilize R. \n",
"Jupyter/Ipython notebook allows you run **R** code interactively in your browser. The software library **R** is \n",
"tuned to statistically analysis and allows for an easy usage of the tools we will discuss in these texts.\n",
"\n",
"To install **R** with Jupyter notebook [following the link here](https://mpacer.org/maths/r-kernel-for-ipython-notebook)\n",
"\n",
"\n",
"\n",
"## Installing R, C++, cython or Julia\n",
"\n",
"\n",
"For the C++ affecianodas, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language \n",
"interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for\n",
"either Python or C++ as programming languages. \n",
@@ -120,18 +127,13 @@
"including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook \n",
"can easily be converted into a nicely rendered **PDF** file or a Latex file for further processing.\n",
"\n",
"This never ends, \n",
"\n",
"If you se the light mark-up language **doconce** you can convert a standard ascii text file into various HTML \n",
"This never ends.\n",
"If you use the light mark-up language **doconce** you can convert a standard ascii text file into various HTML \n",
"formats, ipython notebooks, latex files, pdf files etc. \n",
"\n",
"## Introduction to Jupyter notebook and available tools\n",
"\n",
"## Doing it in R\n",
"Use the Hudson bay model to load data and make plot in R and with python\n",
"\n",
"\n",
"## Representing data, overarching aims"
"## Introduction to Jupyter notebook and available tools"
]
},
{
@@ -157,7 +159,7 @@
"y = np.sin(x)\n",
"plt.plot(x,y,marker='x')\n",
"plt.show()\n",
"data = {'Name': [\"John\", \"Anna\", \"Peter\", \"Linda\"], 'Location': [\"Roma\", \"Napoli\", \"Torino\", \"Milano\"], 'Age':[51, 21, 34, 45]}\n",
"data = {'Name': [\"John\", \"Anna\", \"Peter\", \"Linda\"], 'Location': [\"Nairobi\", \"Napoli\", \"London\", \"Buenos Aires\"], 'Age':[51, 21, 34, 45]}\n",
"data_pandas = pd.DataFrame(data)\n",
"display(data_pandas)"
]
@@ -199,13 +201,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Binning of data\n",
"Use the Hudson bay model to load data and make plot in R and with python\n",
"\n",
"\n",
"\n",
"\n",
"## Adding model complexity: Predator-Prey model from ecology\n",
"## Predator-Prey model from ecology\n",
"\n",
"The population dynamics of a simple predator-prey system is a\n",
"classical example shown in many biology textbooks when ecological\n",
@@ -228,7 +224,7 @@
"## Case study from Hudson bay\n",
"\n",
"Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?\n",
"We shall demonstrate the scientific method by\n",
"Here we start by\n",
"\n",
"1. plotting the data\n",
"\n",
@@ -243,11 +239,11 @@
"## Hudson bay data\n",
"\n",
"\n",
"% if FORMAT == 'ipynb':\n",
"\n",
"Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.\n",
"\n",
"One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.\n",
"% endif\n",
"\n",
"\n",
"<table border=\"1\">\n",
"<thead>\n",
@@ -297,7 +293,7 @@
"from matplotlib import pyplot as plt\n",
"\n",
"# Load in data file\n",
"data = np.loadtxt('Hudson_Bay.dat', delimiter=',', skiprows=1)\n",
"data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)\n",
"# Make arrays containing x-axis and hares and lynx populations\n",
"year = data[:,0]\n",
"hares = data[:,1]\n",
@@ -318,7 +314,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"% if FORMAT != 'ipynb':\n",
"## Hares and lynx in Hudson bay from 1900 to 1920\n",
"\n",
"<!-- dom:FIGURE: [fig/Hudson_Bay_data.png, width=700 frac=0.9] -->\n",
@@ -329,11 +324,10 @@
"\n",
"<!-- end figure -->\n",
"\n",
"% endif\n",
"\n",
"\n",
"\n",
"## Why now create a computer model for the hare and lynx populations?\n",
"% if FORMAT == 'ipynb':\n",
"We see from the plot that there are indeed fluctuations.\n",
"We would like to create a mathematical model that explains these\n",
"population fluctuations. Ecologists have predicted that in a simple\n",
@@ -348,7 +342,7 @@
"amplitude of the oscillation or do you expect to see the oscillations\n",
"damp to a stable equilibrium? The models tend to ignore factors like\n",
"climate and other complicating factors. How significant are these?\n",
"% else:\n",
"\n",
" * We see oscillations in the data\n",
"\n",
" * What causes cycles to slow or speed up?\n",
@@ -360,8 +354,6 @@
" * More important: we can understand the ecology dynamics of\n",
" predator-pray populations\n",
"\n",
"% endif\n",
"\n",
"\n",
"\n",
"\n",
@@ -401,25 +393,8 @@
"\n",
"\n",
"\n",
"## The \"new\" discrete bottom-up approach\n",
"\n",
"**The bottom-up approach.**\n",
"\n",
" * Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.\n",
"\n",
" * Where appropriate the students should do the experiment(s) needed to collect the data.\n",
"\n",
" * The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.\n",
"\n",
" * Now we want to increase the understanding through modeling.\n",
"\n",
" * Most of the biology lies in the *derivation* of the model. We shall\n",
" focus on an intuitive discrete approach that leads to difference\n",
" equations that can be programmed *and solved* directly.\n",
"\n",
"\n",
"\n",
"## Basic (computer-friendly) mathematics notation\n",
"## Basic mathematics notation\n",
" * Time points: $t_0,t_1,\\ldots,t_m$\n",
"\n",
" * Uniform distribution of time points: $t_n=n\\Delta t$\n",
@@ -459,8 +434,7 @@
"interval $\\Delta t$, there is some\n",
"small probablity that the lynx will eat the hare.\n",
"So in fraction $b\\Delta t HL$, the lynx eat hares. This\n",
"loss of hares and must be accounted for:\n",
"subtracted in the equation for hares:"
"loss of hares must be accounted for. Subtracted in the equation for hares:"
]
},
{
@@ -584,7 +558,7 @@
" H = np.zeros(t.size)\n",
" L = np.zeros(t.size)\n",
"\n",
" print 'Init:', H0, L0, dt\n",
" print('Init:', H0, L0, dt)\n",
" H[0] = H0\n",
" L[0] = L0\n",
"\n",
@@ -594,7 +568,7 @@
" return H, L, t\n",
"\n",
"# Load in data file\n",
"data = np.loadtxt('Hudson_Bay.csv', delimiter=',', skiprows=1)\n",
"data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)\n",
"# Make arrays containing x-axis and hares and lynx populations\n",
"t_e = data[:,0]\n",
"H_e = data[:,1]\n",
@@ -621,7 +595,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"% if FORMAT != 'ipynb':\n",
"## The plot\n",
"\n",
"<!-- dom:FIGURE: [fig/Hudson_Bay_sim.png, width=700 frac=0.9] -->\n",
@@ -633,9 +606,110 @@
"<!-- end figure -->\n",
"\n",
"\n",
"% else:\n",
"If we perform a least-square fitting, we can find optimal values for the parameters $a$, $b$, $d$, $c$. The optimal parameters are $a=0.4807$, $b=0.02482$, $d=0.9272$ and $c=0.02756$. These parameters result in a slightly modified initial conditions, namely $H(0) = 34.91$ and $L(0)=3.857$. With these parameters we are now ready to solve the equations and plot these data together with the experimental values.\n",
"% endif"
"\n",
"\n",
"## Linear regression in Python"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from IPython.display import display\n",
"import sklearn\n",
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.tree import DecisionTreeRegressor\n",
"\n",
"\n",
"data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)\n",
"x = data[:,0]\n",
"y = data[:,1]\n",
"line = np.linspace(1900,1920,1000,endpoint=False).reshape(-1,1)\n",
"reg = DecisionTreeRegressor(min_samples_split=3).fit(x.reshape(-1,1),y.reshape(-1,1))\n",
"plt.plot(line, reg.predict(line), label=\"decision tree\")\n",
"regline = LinearRegression().fit(x.reshape(-1,1),y.reshape(-1,1))\n",
"plt.plot(line, regline.predict(line), label= \"Linear Regression\")\n",
"plt.plot(x, y, label= \"Linear Regression\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Linear Least squares in R"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"HudsonBay = read.csv(\"src/Hudson_Bay.csv\",header=T)\n",
"fix(HudsonBay)\n",
"dim(HudsonBay)\n",
"names(HudsonBay)\n",
"plot(HudsonBay$Year, HudsonBay$Hares..x1000.)\n",
"attach(HudsonBay)\n",
"plot(Year, Hares..x1000.)\n",
"plot(Year, Hares..x1000., col=\"red\", varwidth=T, xlab=\"Years\", ylab=\"Haresx 1000\")\n",
"summary(HudsonBay)\n",
"summary(Hares..x1000.)\n",
"library(MASS)\n",
"library(ISLR)\n",
"scatter.smooth(x=Year, y = Hares..x1000.)\n",
"linearMod = lm(Hares..x1000. ~ Year)\n",
"print(linearMod)\n",
"summary(linearMod)\n",
"plot(linearMod)\n",
"confint(linearMod)\n",
"predict(linearMod,data.frame(Year=c(1910,1914,1920)),interval=\"confidence\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Non-Linear Least squares in R"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"set.seed(1485)\n",
"len = 24\n",
"x = runif(len)\n",
"y = x^3+rnorm(len, 0,0.06)\n",
"ds = data.frame(x = x, y = y)\n",
"str(ds)\n",
"plot( y ~ x, main =\"Known cubic with noise\")\n",
"s = seq(0,1,length =100)\n",
"lines(s, s^3, lty =2, col =\"green\")\n",
"m = nls(y ~ I(x^power), data = ds, start = list(power=1), trace = T)\n",
"class(m)\n",
"summary(m)\n",
"power = round(summary(m)$coefficients[1], 3)\n",
"power.se = round(summary(m)$coefficients[2], 3)\n",
"plot(y ~ x, main = \"Fitted power model\", sub = \"Blue: fit; green: known\")\n",
"s = seq(0, 1, length = 100)\n",
"lines(s, s^3, lty = 2, col = \"green\")\n",
"lines(s, predict(m, list(x = s)), lty = 1, col = \"blue\")\n",
"text(0, 0.5, paste(\"y =x^ (\", power, \" +/- \", power.se, \")\", sep = \"\"), pos = 4)"
]
}
],
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

@@ -0,0 +1,22 @@
Year,Hares (x1000),Lynx (x1000)
1900,30.0,4.0
1901,47.2,6.1
1902,70.2,9.8
1903,77.4,35.2
1904,36.3,59.4
1905,20.6,41.7
1906,18.1,19.0
1907,21.4,13.0
1908,22.0,8.3
1909,25.4,9.1
1910,27.1,7.4
1911,40.3,8.0
1912,57,12.3
1913,76.6,19.5
1914,52.3,45.7
1915,19.5,51.1
1916,11.2,29.7
1917,7.6,15.8
1918,14.6,9.7
1919,16.2,10.1
1920,24.7,8.6
1 Year Hares (x1000) Lynx (x1000)
2 1900 30.0 4.0
3 1901 47.2 6.1
4 1902 70.2 9.8
5 1903 77.4 35.2
6 1904 36.3 59.4
7 1905 20.6 41.7
8 1906 18.1 19.0
9 1907 21.4 13.0
10 1908 22.0 8.3
11 1909 25.4 9.1
12 1910 27.1 7.4
13 1911 40.3 8.0
14 1912 57 12.3
15 1913 76.6 19.5
16 1914 52.3 45.7
17 1915 19.5 51.1
18 1916 11.2 29.7
19 1917 7.6 15.8
20 1918 14.6 9.7
21 1919 16.2 10.1
22 1920 24.7 8.6
@@ -0,0 +1,43 @@
import numpy as np
import matplotlib.pyplot as plt
def solver(m, H0, L0, dt, a, b, c, d, t0):
"""Solve the difference equations for H and L over m years
with time step dt (measured in years."""
num_intervals = int(m/float(dt))
t = np.linspace(t0, t0 + m, num_intervals+1)
H = np.zeros(t.size)
L = np.zeros(t.size)
print('Init:', H0, L0, dt)
H[0] = H0
L[0] = L0
for n in range(0, len(t)-1):
H[n+1] = H[n] + a*dt*H[n] - b*dt*H[n]*L[n]
L[n+1] = L[n] + d*dt*H[n]*L[n] - c*dt*L[n]
return H, L, t
# Load in data file
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
# Make arrays containing x-axis and hares and lynx populations
t_e = data[:,0]
H_e = data[:,1]
L_e = data[:,2]
# Simulate using the model
H, L, t = solver(m=20, H0=34.91, L0=3.857, dt=0.1,
a=0.4807, b=0.02482, c=0.9272, d=0.02756,
t0=1900)
# Visualize simulations and data
plt.plot(t_e, H_e, 'b-+', t_e, L_e, 'r-o', t, H, 'm--', t, L, 'k--')
plt.xlabel('Year')
plt.ylabel('Numbers of hares and lynx')
plt.axis([1900, 1920, 0, 140])
plt.title(r'Population of hares and lynx 1900-1920 (x1000)')
plt.legend(('H_e', 'L_e', 'H', 'L'), loc='upper left')
plt.savefig('Hudson_Bay_sim.pdf')
plt.savefig('Hudson_Bay_sim.png')
plt.show()
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

+12
View File
@@ -0,0 +1,12 @@
import numpy as np
t = np.linspace(0, 10, 21) # 20 intervals in [0, 10]
dt = t[1] - t[0]
N = np.zeros(t.size)
N[0] = 1
r = 0.5
for n in range(0, N.size-1, 1):
N[n+1] = N[n] + r*dt*N[n]
print 'N[%d]=%.1f' % (n+1, N[n+1])
+11
View File
@@ -0,0 +1,11 @@
0,100
600,140
1200,250
1800,360
2400,480
3000,820
3600,1300
4200,1700
4800,2900
5400,3900
6000,7000
1 0 100
2 600 140
3 1200 250
4 1800 360
5 2400 480
6 3000 820
7 3600 1300
8 4200 1700
9 4800 2900
10 5400 3900
11 6000 7000
+27
View File
@@ -0,0 +1,27 @@
import numpy as np
# Estimate r
data = np.loadtxt('ecoli.csv', delimiter=',')
t_e = data[:,0]
N_e = data[:,1]
i = 2 # Data point (i,i+1) used to estimate r
r = (N_e[i+1] - N_e[i])/(N_e[i]*(t_e[i+1] - t_e[i]))
print 'Estimated r=%.5f' % r
# Can experiment with r values and see if the model can
# match the data better
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, 1000)
dt = t[1] - t[0]
N = np.zeros(t.size)
N[0] = 100
for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
import matplotlib.pyplot as plt
plt.plot(t, N, 'r-', t_e, N_e, 'bo')
plt.xlabel('time [s]'); plt.ylabel('N')
plt.legend(['model', 'experiment'], loc='upper left')
plt.show()
@@ -0,0 +1,27 @@
import numpy as np
data = np.loadtxt('ecoli.csv', delimiter=',')
t_experiment = data[:,0]
N_experiment = data[:,1]
def error(p):
r = p[0]
T = 1200 # cell can divide after T sec
t_max = 5*T # 5 generations in experiment
t = np.linspace(0, t_max, len(t_experiment))
dt = (t[1] - t[0])
N = np.zeros(t.size)
N[0] = 100
for n in range(0, len(t)-1, 1):
N[n+1] = N[n] + r*dt*N[n]
e = np.sqrt(np.sum((N - N_experiment)**2))/N[0] # error measure
e = abs(N[-1] - N_experiment[-1])/N[0]
print 'r=', r, 'e=',e
return e
from scipy.optimize import minimize
p = minimize(error, [0.0006], tol=1E-5)
print p
@@ -0,0 +1,19 @@
import numpy as np
from matplotlib import pyplot as plt
# Load in data file
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
# Make arrays containing x-axis and hares and lynx populations
year = data[:,0]
hares = data[:,1]
lynx = data[:,2]
plt.plot(year, hares ,'b-+', year, lynx, 'r-o')
plt.axis([1900,1920,0, 100.0])
plt.xlabel(r'Year')
plt.ylabel(r'Numbers of hares and lynx ')
plt.legend(('Hares','Lynx'), loc='upper right')
plt.title(r'Population of hares and lynx from 1900-1920 (x1000)}')
plt.savefig('Hudson_Bay_data.pdf')
plt.savefig('Hudson_Bay_data.png')
plt.show()
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,728 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- dom:TITLE: Data Analysis and Machine Learning: Introduction and Representing data -->\n",
"# Data Analysis and Machine Learning: Introduction and Representing data\n",
"<!-- dom:AUTHOR: Morten Hjorth-Jensen at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University -->\n",
"<!-- Author: --> \n",
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
"\n",
"Date: **Dec 6, 2017**\n",
"\n",
"Copyright 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
"\n",
"\n",
"\n",
"## What is Machine Learning?\n",
"\n",
"Machine learning is the science of giving computers the ability to\n",
"learn without being explicitly programmed. The idea is that there\n",
"exist generic algorithms which can be used to find patterns in a broad\n",
"class of data sets without having to write code specifically for each\n",
"problem. The algorithm will build its own logic based on the data.\n",
"\n",
"Machine learning is a subfield of computer science, and is closely\n",
"related to computational statistics. It evolved from the study of\n",
"pattern recognition in artificial intelligence (AI) research, and has\n",
"made contributions to AI tasks like computer vision, natural language\n",
"processing and speech recognition. It has also, especially in later\n",
"years, found applications in a wide variety of other areas, including\n",
"bioinformatics, economy, physics, finance and marketing.\n",
"\n",
"## Types of Machine Learning\n",
"\n",
"\n",
"The approaches to machine learning are many, but are often split into two main categories. \n",
"In *supervised learning* we know the answer to a problem,\n",
"and let the computer deduce the logic behind it. On the other hand, *unsupervised learning*\n",
"is a method for finding patterns and relationship in data sets without any prior knowledge of the system.\n",
"Some authours also operate with a third category, namely *reinforcement learning*. This is a paradigm \n",
"of learning inspired by behavioural psychology, where learning is achieved by trial-and-error, \n",
"solely from rewards and punishment.\n",
"\n",
"Another way to categorize machine learning tasks is to consider the desired output of a system.\n",
"Some of the most common tasks are:\n",
"\n",
" * Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.\n",
"\n",
" * Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.\n",
"\n",
" * Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.\n",
"\n",
"## Different algorithms\n",
"In this course we will build our machine learning approach on a statistical foundation, with elements \n",
"from data analysis, stochastic processes etc before we proceed with the following machine learning algorithms\n",
"\n",
"1. Linear regression and its variants\n",
"\n",
"2. Decision tree algorithms, from simpler to more complex ones\n",
"\n",
"3. Nearest neighbors models\n",
"\n",
"4. Bayesian statistics \n",
"\n",
"5. Support vector machines and finally various variants of\n",
"\n",
"6. Artifical neural networks\n",
"\n",
"Before we proceed however, there are several practicalities with data analysis and software tools we would \n",
"like to present. These tools will help us in our understanding of various machine learning algorithms. \n",
"\n",
"Our emphasis here is on understanding the mathematical aspects of different algorithms, however, where possible \n",
"we will emphasize the importance of using available software. \n",
"\n",
"\n",
"## Software and needed installations\n",
"We will make intensive use of python as programming language and the myriad of available libraries. \n",
"Furthermore, you will find IPython/Jupyter notebooks invaluable in your work. \n",
"You can run **R** codes in the Jupyter/IPython notebooks, with the immediate benefit of visualizing your data.\n",
"\n",
"\n",
"If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages, \n",
"we recommend that you install the following Python packages via **pip** as\n",
"1. pip install numpy scipy matplotlib ipython scikit-learn mglearn sympy pandas pillow\n",
"\n",
"For Python3, replace **pip** with **pip3**.\n",
"\n",
"For OSX users we recommend also, after having installed Xcode, to install **brew**. Brew allows \n",
"for a seamless installation of additional software via for example\n",
"1. brew install python3\n",
"\n",
"For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution\n",
"you can use **pip** as well and simply install Python as \n",
"1. sudo apt-get install python3 (or python for pyhton2.7)\n",
"\n",
"etc etc. \n",
"\n",
"## Python installers\n",
"If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up \n",
"all relevant dependencies for Python, namely\n",
"1. [Anaconda](https://docs.anaconda.com/) Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system **conda**\n",
"\n",
"2. [Enthought canopy](https://www.enthought.com/product/canopy/) is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.\n",
"\n",
"## Installing R, C++, cython or Julia\n",
"\n",
"You will also find it convenient to utilize R. \n",
"Jupyter/Ipython notebook allows you run **R** code interactively in your browser. The software library **R** is \n",
"tuned to statistically analysis and allows for an easy usage of the tools we will discuss in these texts.\n",
"\n",
"To install **R** with Jupyter notebook [following the link here](https://mpacer.org/maths/r-kernel-for-ipython-notebook)\n",
"\n",
"\n",
"\n",
"## Installing R, C++, cython or Julia\n",
"\n",
"\n",
"For the C++ affecianodas, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language \n",
"interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for\n",
"either Python or C++ as programming languages. \n",
"\n",
"To add more entropy, **cython** can also be used when running your notebooks. It means that Python with the Jupyter/IPython notebook \n",
"setup allows you to integrate widely popular softwares and tools for scientific computing. With its versatility, \n",
"including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook \n",
"can easily be converted into a nicely rendered **PDF** file or a Latex file for further processing.\n",
"\n",
"This never ends.\n",
"If you use the light mark-up language **doconce** you can convert a standard ascii text file into various HTML \n",
"formats, ipython notebooks, latex files, pdf files etc. \n",
"\n",
"\n",
"## Useful packages\n",
"\n",
"If you already have a Python installation set up, you can use **pip** or **pip3** to install \n",
"1. pip3 install numpy scipy ipython \n",
"\n",
"2. pip3 install pandas matplotlib scikit-learn pillow \n",
"\n",
"Another useful package is **mglearn**. \n",
"\n",
"## Introduction to Jupyter notebook and available tools"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy import sparse\n",
"import pandas as pd\n",
"from IPython.display import display\n",
"eye = np.eye(4)\n",
"print(eye)\n",
"sparse_mtx = sparse.csr_matrix(eye)\n",
"print(sparse_mtx)\n",
"x = np.linspace(-10,10,100)\n",
"y = np.sin(x)\n",
"plt.plot(x,y,marker='x')\n",
"plt.show()\n",
"data = {'Name': [\"John\", \"Anna\", \"Peter\", \"Linda\"], 'Location': [\"Nairobi\", \"Napoli\", \"London\", \"Buenos Aires\"], 'Age':[51, 21, 34, 45]}\n",
"data_pandas = pd.DataFrame(data)\n",
"display(data_pandas)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Representing data, more examples"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy import sparse\n",
"import pandas as pd\n",
"from IPython.display import display\n",
"import mglearn\n",
"import sklearn\n",
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.tree import DecisionTreeRegressor\n",
"x, y = mglearn.datasets.make_wave(n_samples=100)\n",
"line = np.linspace(-3,3,1000,endpoint=False).reshape(-1,1)\n",
"reg = DecisionTreeRegressor(min_samples_split=3).fit(x,y)\n",
"plt.plot(line, reg.predict(line), label=\"decision tree\")\n",
"regline = LinearRegression().fit(x,y)\n",
"plt.plot(line, regline.predict(line), label= \"Linear Rgression\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Predator-Prey model from ecology\n",
"\n",
"The population dynamics of a simple predator-prey system is a\n",
"classical example shown in many biology textbooks when ecological\n",
"systems are discussed. The system contains all elements of the\n",
"scientific method:\n",
"\n",
" * The set up of a specific hypothesis combined with\n",
"\n",
" * the experimental methods needed (one can study existing data or perform experiments)\n",
"\n",
" * analyzing and interpreting the data and performing further experiments if needed\n",
"\n",
" * trying to extract general behaviors and extract eventual laws or patterns\n",
"\n",
" * develop mathematical relations for the uncovered regularities/laws and test these by per forming new experiments\n",
"\n",
"\n",
"\n",
"\n",
"## Case study from Hudson bay\n",
"\n",
"Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?\n",
"Here we start by\n",
"\n",
"1. plotting the data\n",
"\n",
"2. derive a simple model for the population dynamics\n",
"\n",
"3. (fitting parameters in the model to the data)\n",
"\n",
"4. using the model predict the evolution other predator-pray systems\n",
"\n",
"\n",
"\n",
"## Hudson bay data\n",
"\n",
"\n",
"% if FORMAT == 'ipynb':\n",
"Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.\n",
"\n",
"One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.\n",
"% endif\n",
"\n",
"<table border=\"1\">\n",
"<thead>\n",
"<tr><th align=\"center\">Year</th> <th align=\"center\">Hares (x1000)</th> <th align=\"center\">Lynx (x1000)</th> </tr>\n",
"</thead>\n",
"<tbody>\n",
"<tr><td align=\"left\"> 1900 </td> <td align=\"right\"> 30.0 </td> <td align=\"right\"> 4.0 </td> </tr>\n",
"<tr><td align=\"left\"> 1901 </td> <td align=\"right\"> 47.2 </td> <td align=\"right\"> 6.1 </td> </tr>\n",
"<tr><td align=\"left\"> 1902 </td> <td align=\"right\"> 70.2 </td> <td align=\"right\"> 9.8 </td> </tr>\n",
"<tr><td align=\"left\"> 1903 </td> <td align=\"right\"> 77.4 </td> <td align=\"right\"> 35.2 </td> </tr>\n",
"<tr><td align=\"left\"> 1904 </td> <td align=\"right\"> 36.3 </td> <td align=\"right\"> 59.4 </td> </tr>\n",
"<tr><td align=\"left\"> 1905 </td> <td align=\"right\"> 20.6 </td> <td align=\"right\"> 41.7 </td> </tr>\n",
"<tr><td align=\"left\"> 1906 </td> <td align=\"right\"> 18.1 </td> <td align=\"right\"> 19.0 </td> </tr>\n",
"<tr><td align=\"left\"> 1907 </td> <td align=\"right\"> 21.4 </td> <td align=\"right\"> 13.0 </td> </tr>\n",
"<tr><td align=\"left\"> 1908 </td> <td align=\"right\"> 22.0 </td> <td align=\"right\"> 8.3 </td> </tr>\n",
"<tr><td align=\"left\"> 1909 </td> <td align=\"right\"> 25.4 </td> <td align=\"right\"> 9.1 </td> </tr>\n",
"<tr><td align=\"left\"> 1910 </td> <td align=\"right\"> 27.1 </td> <td align=\"right\"> 7.4 </td> </tr>\n",
"<tr><td align=\"left\"> 1911 </td> <td align=\"right\"> 40.3 </td> <td align=\"right\"> 8.0 </td> </tr>\n",
"<tr><td align=\"left\"> 1912 </td> <td align=\"right\"> 57 </td> <td align=\"right\"> 12.3 </td> </tr>\n",
"<tr><td align=\"left\"> 1913 </td> <td align=\"right\"> 76.6 </td> <td align=\"right\"> 19.5 </td> </tr>\n",
"<tr><td align=\"left\"> 1914 </td> <td align=\"right\"> 52.3 </td> <td align=\"right\"> 45.7 </td> </tr>\n",
"<tr><td align=\"left\"> 1915 </td> <td align=\"right\"> 19.5 </td> <td align=\"right\"> 51.1 </td> </tr>\n",
"<tr><td align=\"left\"> 1916 </td> <td align=\"right\"> 11.2 </td> <td align=\"right\"> 29.7 </td> </tr>\n",
"<tr><td align=\"left\"> 1917 </td> <td align=\"right\"> 7.6 </td> <td align=\"right\"> 15.8 </td> </tr>\n",
"<tr><td align=\"left\"> 1918 </td> <td align=\"right\"> 14.6 </td> <td align=\"right\"> 9.7 </td> </tr>\n",
"<tr><td align=\"left\"> 1919 </td> <td align=\"right\"> 16.2 </td> <td align=\"right\"> 10.1 </td> </tr>\n",
"<tr><td align=\"left\"> 1920 </td> <td align=\"right\"> 24.7 </td> <td align=\"right\"> 8.6 </td> </tr>\n",
"</tbody>\n",
"</table>\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"## Plotting the data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"\n",
"# Load in data file\n",
"data = np.loadtxt('Hudson_Bay.dat', delimiter=',', skiprows=1)\n",
"# Make arrays containing x-axis and hares and lynx populations\n",
"year = data[:,0]\n",
"hares = data[:,1]\n",
"lynx = data[:,2]\n",
"\n",
"plt.plot(year, hares ,'b-+', year, lynx, 'r-o')\n",
"plt.axis([1900,1920,0, 100.0])\n",
"plt.xlabel(r'Year')\n",
"plt.ylabel(r'Numbers of hares and lynx ')\n",
"plt.legend(('Hares','Lynx'), loc='upper right')\n",
"plt.title(r'Population of hares and lynx from 1900-1920 (x1000)}')\n",
"plt.savefig('Hudson_Bay_data.pdf')\n",
"plt.savefig('Hudson_Bay_data.png')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"% if FORMAT != 'ipynb':\n",
"## Hares and lynx in Hudson bay from 1900 to 1920\n",
"\n",
"<!-- dom:FIGURE: [fig/Hudson_Bay_data.png, width=700 frac=0.9] -->\n",
"<!-- begin figure -->\n",
"\n",
"<p></p>\n",
"<img src=\"fig/Hudson_Bay_data.png\" width=700>\n",
"\n",
"<!-- end figure -->\n",
"\n",
"% endif\n",
"\n",
"\n",
"## Why now create a computer model for the hare and lynx populations?\n",
"% if FORMAT == 'ipynb':\n",
"We see from the plot that there are indeed fluctuations.\n",
"We would like to create a mathematical model that explains these\n",
"population fluctuations. Ecologists have predicted that in a simple\n",
"predator-prey system that a rise in prey population is followed (with\n",
"a lag) by a rise in the predator population. When the predator\n",
"population is sufficiently high, then the prey population begins\n",
"dropping. After the prey population falls, then the predator\n",
"population falls, which allows the prey population to recover and\n",
"complete one cycle of this interaction. Thus, we see that\n",
"qualitatively oscillations occur. Can a mathematical model predict\n",
"this? What causes cycles to slow or speed up? What affects the\n",
"amplitude of the oscillation or do you expect to see the oscillations\n",
"damp to a stable equilibrium? The models tend to ignore factors like\n",
"climate and other complicating factors. How significant are these?\n",
"% else:\n",
" * We see oscillations in the data\n",
"\n",
" * What causes cycles to slow or speed up?\n",
"\n",
" * What affects the amplitude of the oscillation or do you expect to see the oscillations damp to a stable equilibrium?\n",
"\n",
" * With a model we can better *understand the data*\n",
"\n",
" * More important: we can understand the ecology dynamics of\n",
" predator-pray populations\n",
"\n",
"% endif\n",
"\n",
"\n",
"\n",
"\n",
"## The traditional (top-down) approach\n",
"\n",
"The classical way (in all books) is to present the Lotka-Volterra equations:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\begin{align*}\n",
"\\frac{dH}{dt} &= H(a - b L)\\\\\n",
"\\frac{dL}{dt} &= - L(d - c H)\n",
"\\end{align*}\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here,\n",
"\n",
" * $H$ is the number of preys\n",
"\n",
" * $L$ the number of predators\n",
"\n",
" * $a$, $b$, $d$, $c$ are parameters\n",
"\n",
"Most books quickly establish the model and then use considerable space on\n",
"discussing the qualitative properties of this *nonlinear system of\n",
"ODEs* (which cannot be solved)\n",
"\n",
"\n",
"\n",
"\n",
"## The \"new\" discrete bottom-up approach\n",
"\n",
"**The bottom-up approach.**\n",
"\n",
" * Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.\n",
"\n",
" * Where appropriate the students should do the experiment(s) needed to collect the data.\n",
"\n",
" * The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.\n",
"\n",
" * Now we want to increase the understanding through modeling.\n",
"\n",
" * Most of the biology lies in the *derivation* of the model. We shall\n",
" focus on an intuitive discrete approach that leads to difference\n",
" equations that can be programmed *and solved* directly.\n",
"\n",
"\n",
"\n",
"## Basic (computer-friendly) mathematics notation\n",
" * Time points: $t_0,t_1,\\ldots,t_m$\n",
"\n",
" * Uniform distribution of time points: $t_n=n\\Delta t$\n",
"\n",
" * $H^n$: population of hares at time $t_n$\n",
"\n",
" * $L^n$: population of lynx at time $t_n$\n",
"\n",
" * We want to model the changes in populations, $\\Delta H=H^{n+1}-H^n$\n",
" and $\\Delta L=L^{n+1}-L^n$ during a general time interval $[t_{n+1},t_n]$\n",
" of length $\\Delta t=t_{n+1}-t_n$\n",
"\n",
"\n",
"\n",
"## Basic dynamics of the population of hares\n",
"\n",
"The population of hares evolves due to births and deaths exactly as a bacteria population:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\Delta H = a \\Delta t H^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"However, hares have an additional loss in the population because\n",
"they are eaten by lynx.\n",
"All the hares and lynx can form\n",
"$H\\cdot L$ pairs in total. When such pairs meet during a time\n",
"interval $\\Delta t$, there is some\n",
"small probablity that the lynx will eat the hare.\n",
"So in fraction $b\\Delta t HL$, the lynx eat hares. This\n",
"loss of hares and must be accounted for:\n",
"subtracted in the equation for hares:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\Delta H = a\\Delta t H^n - b \\Delta t H^nL^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic dynamics of the population of lynx\n",
"\n",
"We assume that the primary growth for the lynx population depends on sufficient food for raising lynx kittens, which implies an adequate source of nutrients from predation on hares. Thus, the growth of the lynx population does not only depend of how many lynx there are, but on how many hares they can eat.\n",
"In a time interval $\\Delta t HL$ hares and lynx can meet, and in a\n",
"fraction $b\\Delta t HL$ the lynx eats the hare. All of this does not\n",
"contribute to the growth of lynx, again just a fraction of\n",
"$b\\Delta t HL$ that we write as\n",
"$d\\Delta t HL$. In addition, lynx die just as in the population\n",
"dynamics with one isolated animal population, leading to a loss\n",
"$-c\\Delta t L$.\n",
"\n",
"\n",
"\n",
"The accounting of lynx then looks like"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\Delta L = d\\Delta t H^nL^n - c\\Delta t L^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Evolution equations\n",
"\n",
"By writing up the definition of $\\Delta H$ and $\\Delta L$, and putting\n",
"all assumed known terms $H^n$ and $L^n$ on the right-hand side, we have"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"H^{n+1} = H^n + a\\Delta t H^n - b\\Delta t H^n L^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"L^{n+1} = L^n + d\\Delta t H^nL^n - c\\Delta t L^n\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note:\n",
"\n",
" * These equations are ready to be implemented!\n",
"\n",
" * But to start, we need $H^0$ and $L^0$ \n",
" (which we can get from the data)\n",
"\n",
" * We also need values for $a$, $b$, $d$, $c$\n",
"\n",
"\n",
"\n",
"## Adapt the model to the Hudson Bay case\n",
"\n",
" * As always, models tend to be general - as here, applicable\n",
" to \"all\" predator-pray systems\n",
"\n",
" * The critical issue is whether the *interaction* between hares and lynx\n",
" is sufficiently well modeled by $\\hbox{const}HL$\n",
"\n",
" * The parameters $a$, $b$, $d$, and $c$ must be\n",
" estimated from data\n",
"\n",
" * Measure time in years\n",
"\n",
" * $t_0=1900$, $t_m=1920$\n",
"\n",
"\n",
"\n",
"## The program"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"def solver(m, H0, L0, dt, a, b, c, d, t0):\n",
" \"\"\"Solve the difference equations for H and L over m years\n",
" with time step dt (measured in years.\"\"\"\n",
"\n",
" num_intervals = int(m/float(dt))\n",
" t = np.linspace(t0, t0 + m, num_intervals+1)\n",
" H = np.zeros(t.size)\n",
" L = np.zeros(t.size)\n",
"\n",
" print 'Init:', H0, L0, dt\n",
" H[0] = H0\n",
" L[0] = L0\n",
"\n",
" for n in range(0, len(t)-1):\n",
" H[n+1] = H[n] + a*dt*H[n] - b*dt*H[n]*L[n]\n",
" L[n+1] = L[n] + d*dt*H[n]*L[n] - c*dt*L[n]\n",
" return H, L, t\n",
"\n",
"# Load in data file\n",
"data = np.loadtxt('Hudson_Bay.csv', delimiter=',', skiprows=1)\n",
"# Make arrays containing x-axis and hares and lynx populations\n",
"t_e = data[:,0]\n",
"H_e = data[:,1]\n",
"L_e = data[:,2]\n",
"\n",
"# Simulate using the model\n",
"H, L, t = solver(m=20, H0=34.91, L0=3.857, dt=0.1,\n",
" a=0.4807, b=0.02482, c=0.9272, d=0.02756,\n",
" t0=1900)\n",
"\n",
"# Visualize simulations and data\n",
"plt.plot(t_e, H_e, 'b-+', t_e, L_e, 'r-o', t, H, 'm--', t, L, 'k--')\n",
"plt.xlabel('Year')\n",
"plt.ylabel('Numbers of hares and lynx')\n",
"plt.axis([1900, 1920, 0, 140])\n",
"plt.title(r'Population of hares and lynx 1900-1920 (x1000)')\n",
"plt.legend(('H_e', 'L_e', 'H', 'L'), loc='upper left')\n",
"plt.savefig('Hudson_Bay_sim.pdf')\n",
"plt.savefig('Hudson_Bay_sim.png')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"% if FORMAT != 'ipynb':\n",
"## The plot\n",
"\n",
"<!-- dom:FIGURE: [fig/Hudson_Bay_sim.png, width=700 frac=0.9] -->\n",
"<!-- begin figure -->\n",
"\n",
"<p></p>\n",
"<img src=\"fig/Hudson_Bay_sim.png\" width=700>\n",
"\n",
"<!-- end figure -->\n",
"\n",
"\n",
"% else:\n",
"If we perform a least-square fitting, we can find optimal values for the parameters $a$, $b$, $d$, $c$. The optimal parameters are $a=0.4807$, $b=0.02482$, $d=0.9272$ and $c=0.02756$. These parameters result in a slightly modified initial conditions, namely $H(0) = 34.91$ and $L(0)=3.857$. With these parameters we are now ready to solve the equations and plot these data together with the experimental values.\n",
"% endif\n",
"\n",
"\n",
"\n",
"## Linear Least squares in R"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" HudsonBay = read.csv(\"src/Hudson_Bay.csv\",header=T)\n",
" fix(HudsonBay)\n",
" dim(HudsonBay)\n",
" names(HudsonBay)\n",
" plot(HudsonBay$Year, HudsonBay$Hares..x1000.)\n",
" attach(HudsonBay)\n",
" plot(Year, Hares..x1000.)\n",
" plot(Year, Hares..x1000., col=\"red\", varwidth=T, xlab=\"Years\", ylab=\"Haresx 1000\")\n",
" summary(HudsonBay)\n",
" summary(Hares..x1000.)\n",
" library(MASS)\n",
" library(ISLR)\n",
" scatter.smooth(x=Year, y = Hares..x1000.)\n",
" linearMod = lm(Hares..x1000. ~ Year)\n",
" print(linearMod)\n",
" summary(linearMod)\n",
" plot(linearMod)\n",
" confint(linearMod)\n",
" predict(linearMod,data.frame(Year=c(1910,1914,1920)),interval=\"confidence\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Linear Least squares in R"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" set.seed(1485)\n",
" len = 24\n",
" x = runif(len)\n",
" y = x^3+rnorm(len, 0,0.06)\n",
" ds = data.frame(x = x, y = y)\n",
" str(ds)\n",
" plot( y ~ x, main =\"Known cubic with noise\")\n",
" s = seq(0,1,length =100)\n",
" lines(s, s^3, lty =2, col =\"green\")\n",
" m = nls(y ~ I(x^power), data = ds, start = list(power=1), trace = T)\n",
" class(m)\n",
" summary(m)\n",
" power = round(summary(m)$coefficients[1], 3)\n",
" power.se = round(summary(m)$coefficients[2], 3)\n",
" plot(y ~ x, main = \"Fitted power model\", sub = \"Blue: fit; green: known\")\n",
" s = seq(0, 1, length = 100)\n",
" lines(s, s^3, lty = 2, col = \"green\")\n",
" lines(s, predict(m, list(x = s)), lty = 1, col = \"blue\")\n",
" text(0, 0.5, paste(\"y =x^ (\", power, \" +/- \", power.se, \")\", sep = \"\"), pos = 4)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
+109 -53
View File
@@ -86,17 +86,25 @@ etc etc.
===== Python installers =====
If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up
all relevant dependencies for Python, namely
o anaconda
o Enthought canopy
o "Anaconda":"https://docs.anaconda.com/" Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system _conda_
o "Enthought canopy":"https://www.enthought.com/product/canopy/" is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.
!split
===== Installing R, C++, cython or Julia =====
You will also find it convenient to utilize R. Say more about R.
You will also find it convenient to utilize R.
Jupyter/Ipython notebook allows you run _R_ code interactively in your browser. The software library _R_ is
tuned to statistically analysis and allows for an easy usage of the tools we will discuss in these texts.
To install _R_ with Jupyter notebook "following the link here":"https://mpacer.org/maths/r-kernel-for-ipython-notebook"
!split
===== Installing R, C++, cython or Julia =====
For the C++ affecianodas, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
interactively in the browser. Since we will emphasize writing many of the algorithms yourself, you can thus opt for
either Python or C++ as programming languages.
@@ -106,21 +114,15 @@ setup allows you to integrate widely popular softwares and tools for scientific
including symbolic operations, Python offers a unique computational environment. Your Jupyter/IPython notebook
can easily be converted into a nicely rendered _PDF_ file or a Latex file for further processing.
This never ends,
If you se the light mark-up language _doconce_ you can convert a standard ascii text file into various HTML
This never ends.
If you use the light mark-up language _doconce_ you can convert a standard ascii text file into various HTML
formats, ipython notebooks, latex files, pdf files etc.
!split
===== Introduction to Jupyter notebook and available tools =====
!split
===== Doing it in R =====
Use the Hudson bay model to load data and make plot in R and with python
!split
===== Representing data, overarching aims =====
!bblock
!bc pycod
import numpy as np
@@ -136,14 +138,12 @@ x = np.linspace(-10,10,100)
y = np.sin(x)
plt.plot(x,y,marker='x')
plt.show()
data = {'Name': ["John", "Anna", "Peter", "Linda"], 'Location': ["Roma", "Napoli", "Torino", "Milano"], 'Age':[51, 21, 34, 45]}
data = {'Name': ["John", "Anna", "Peter", "Linda"], 'Location': ["Nairobi", "Napoli", "London", "Buenos Aires"], 'Age':[51, 21, 34, 45]}
data_pandas = pd.DataFrame(data)
display(data_pandas)
!ec
!eblock
!split
===== Representing data, more examples =====
!bblock
@@ -167,16 +167,8 @@ plt.show()
!ec
!eblock
!split
===== Binning of data =====
Use the Hudson bay model to load data and make plot in R and with python
Use LSQ first, then neural networks with R and scikt-learn
!split
===== Adding model complexity: Predator-Prey model from ecology =====
===== Predator-Prey model from ecology =====
!bblock
The population dynamics of a simple predator-prey system is a
@@ -197,7 +189,7 @@ scientific method:
!bblock
Lots of data about populations of hares and lynx collected from furs in Hudson Bay, Canada, are available. It is known that the populations oscillate. Why?
We shall demonstrate the scientific method by
Here we start by
o plotting the data
o derive a simple model for the population dynamics
@@ -210,11 +202,11 @@ We shall demonstrate the scientific method by
!bblock
% if FORMAT == 'ipynb':
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
% endif
|------------------------------------------------------|
| Year | Hares (x1000) | Lynx (x1000)|
@@ -253,18 +245,16 @@ One reason that this particular system has been so extensively studied is that t
@@@CODE src/plot_Hudson.py
!eblock
% if FORMAT != 'ipynb':
!split
===== Hares and lynx in Hudson bay from 1900 to 1920 =====
FIGURE: [fig/Hudson_Bay_data, width=700 frac=0.9]
% endif
!split
===== Why now create a computer model for the hare and lynx populations? =====
!bblock
% if FORMAT == 'ipynb':
We see from the plot that there are indeed fluctuations.
We would like to create a mathematical model that explains these
population fluctuations. Ecologists have predicted that in a simple
@@ -279,14 +269,13 @@ this? What causes cycles to slow or speed up? What affects the
amplitude of the oscillation or do you expect to see the oscillations
damp to a stable equilibrium? The models tend to ignore factors like
climate and other complicating factors. How significant are these?
% else:
* We see oscillations in the data
* What causes cycles to slow or speed up?
* What affects the amplitude of the oscillation or do you expect to see the oscillations damp to a stable equilibrium?
* With a model we can better *understand the data*
* More important: we can understand the ecology dynamics of
predator-pray populations
% endif
!eblock
@@ -315,23 +304,9 @@ ODEs* (which cannot be solved)
!eblock
!split
===== The ``new'' discrete bottom-up approach =====
!bblock The bottom-up approach
!bpop
* Start with experimental data and discuss the methods which have been used to collect the data, the assumptions, the electronic devices, the aims etc. That is, expose the students to the theory and assumptions behind the data that have been collected and motivate for the scientific method.
* Where appropriate the students should do the experiment(s) needed to collect the data.
* The first programming tasks are to read and visualize the data to see if there are patterns or regularities. This strengthens a research-driven intuition.
* Now we want to increase the understanding through modeling.
* Most of the biology lies in the *derivation* of the model. We shall
focus on an intuitive discrete approach that leads to difference
equations that can be programmed *and solved* directly.
!epop
!eblock
!split
===== Basic (computer-friendly) mathematics notation =====
===== Basic mathematics notation =====
!bblock
* Time points: $t_0,t_1,\ldots,t_m$
* Uniform distribution of time points: $t_n=n\Delta t$
@@ -360,8 +335,7 @@ $H\cdot L$ pairs in total. When such pairs meet during a time
interval $\Delta t$, there is some
small probablity that the lynx will eat the hare.
So in fraction $b\Delta t HL$, the lynx eat hares. This
loss of hares and must be accounted for:
subtracted in the equation for hares:
loss of hares must be accounted for. Subtracted in the equation for hares:
!bt
\[ \Delta H = a\Delta t H^n - b \Delta t H^nL^n\]
@@ -433,15 +407,97 @@ Note:
@@@CODE src/Hudson_Bay.py
!eblock
% if FORMAT != 'ipynb':
!split
===== The plot =====
FIGURE: [fig/Hudson_Bay_sim, width=700 frac=0.9]
% else:
If we perform a least-square fitting, we can find optimal values for the parameters $a$, $b$, $d$, $c$. The optimal parameters are $a=0.4807$, $b=0.02482$, $d=0.9272$ and $c=0.02756$. These parameters result in a slightly modified initial conditions, namely $H(0) = 34.91$ and $L(0)=3.857$. With these parameters we are now ready to solve the equations and plot these data together with the experimental values.
% endif
!split
===== Linear regression in Python =====
!bblock
!bc pycod
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
import sklearn
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
x = data[:,0]
y = data[:,1]
line = np.linspace(1900,1920,1000,endpoint=False).reshape(-1,1)
reg = DecisionTreeRegressor(min_samples_split=3).fit(x.reshape(-1,1),y.reshape(-1,1))
plt.plot(line, reg.predict(line), label="decision tree")
regline = LinearRegression().fit(x.reshape(-1,1),y.reshape(-1,1))
plt.plot(line, regline.predict(line), label= "Linear Regression")
plt.plot(x, y, label= "Linear Regression")
plt.show()
!ec
!eblock
!split
===== Linear Least squares in R =====
!bblock
!bc pycod
HudsonBay = read.csv("src/Hudson_Bay.csv",header=T)
fix(HudsonBay)
dim(HudsonBay)
names(HudsonBay)
plot(HudsonBay$Year, HudsonBay$Hares..x1000.)
attach(HudsonBay)
plot(Year, Hares..x1000.)
plot(Year, Hares..x1000., col="red", varwidth=T, xlab="Years", ylab="Haresx 1000")
summary(HudsonBay)
summary(Hares..x1000.)
library(MASS)
library(ISLR)
scatter.smooth(x=Year, y = Hares..x1000.)
linearMod = lm(Hares..x1000. ~ Year)
print(linearMod)
summary(linearMod)
plot(linearMod)
confint(linearMod)
predict(linearMod,data.frame(Year=c(1910,1914,1920)),interval="confidence")
!ec
!eblock
!split
===== Non-Linear Least squares in R =====
!bblock
!bc pycod
set.seed(1485)
len = 24
x = runif(len)
y = x^3+rnorm(len, 0,0.06)
ds = data.frame(x = x, y = y)
str(ds)
plot( y ~ x, main ="Known cubic with noise")
s = seq(0,1,length =100)
lines(s, s^3, lty =2, col ="green")
m = nls(y ~ I(x^power), data = ds, start = list(power=1), trace = T)
class(m)
summary(m)
power = round(summary(m)$coefficients[1], 3)
power.se = round(summary(m)$coefficients[2], 3)
plot(y ~ x, main = "Fitted power model", sub = "Blue: fit; green: known")
s = seq(0, 1, length = 100)
lines(s, s^3, lty = 2, col = "green")
lines(s, predict(m, list(x = s)), lty = 1, col = "blue")
text(0, 0.5, paste("y =x^ (", power, " +/- ", power.se, ")", sep = ""), pos = 4)
!ec
!eblock
+2 -2
View File
@@ -10,7 +10,7 @@ def solver(m, H0, L0, dt, a, b, c, d, t0):
H = np.zeros(t.size)
L = np.zeros(t.size)
print 'Init:', H0, L0, dt
print('Init:', H0, L0, dt)
H[0] = H0
L[0] = L0
@@ -20,7 +20,7 @@ def solver(m, H0, L0, dt, a, b, c, d, t0):
return H, L, t
# Load in data file
data = np.loadtxt('Hudson_Bay.csv', delimiter=',', skiprows=1)
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
# Make arrays containing x-axis and hares and lynx populations
t_e = data[:,0]
H_e = data[:,1]
+1 -1
View File
@@ -2,7 +2,7 @@ import numpy as np
from matplotlib import pyplot as plt
# Load in data file
data = np.loadtxt('Hudson_Bay.dat', delimiter=',', skiprows=1)
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
# Make arrays containing x-axis and hares and lynx populations
year = data[:,0]
hares = data[:,1]
+21
View File
@@ -0,0 +1,21 @@
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import display
import sklearn
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(x, y, random_state=0)
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
x = data[:,0]
y = data[:,1]
x_train, y_train = train_test_split(x, y, random_state=0)
line = np.linspace(1900,1930,1000,endpoint=False).reshape(-1,1)
reg = DecisionTreeRegressor(min_samples_split=3).fit(x.reshape(-1,1),y.reshape(-1,1))
plt.plot(line, reg.predict(line), label="decision tree")
regline = LinearRegression().fit(x.reshape(-1,1),y.reshape(-1,1))
plt.plot(line, regline.predict(line), label= "Linear Regression")
plt.plot(x, y, label= "Linear Regression")
plt.show()