374 lines
26 KiB
HTML
374 lines
26 KiB
HTML
<!--
|
|
HTML file automatically generated from DocOnce source
|
|
(https://github.com/doconce/doconce/)
|
|
doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=week38-bs --no_mako
|
|
-->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="generator" content="DocOnce: https://github.com/doconce/doconce/" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<meta name="description" content="Week 38: Statistical analysis, bias-variance tradeoff and resampling methods">
|
|
<title>Week 38: Statistical analysis, bias-variance tradeoff and resampling methods</title>
|
|
<!-- Bootstrap style: bootstrap -->
|
|
<!-- doconce format html week38.do.txt --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=week38-bs --no_mako -->
|
|
<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': [('Plans for week 38, lecture Monday September 15',
|
|
2,
|
|
None,
|
|
'plans-for-week-38-lecture-monday-september-15'),
|
|
('Readings and Videos', 2, None, 'readings-and-videos'),
|
|
('Linking the regression analysis with a statistical '
|
|
'interpretation',
|
|
2,
|
|
None,
|
|
'linking-the-regression-analysis-with-a-statistical-interpretation'),
|
|
('Assumptions made', 2, None, 'assumptions-made'),
|
|
('Expectation value and variance',
|
|
2,
|
|
None,
|
|
'expectation-value-and-variance'),
|
|
('Expectation value and variance for $\\boldsymbol{\\beta}$',
|
|
2,
|
|
None,
|
|
'expectation-value-and-variance-for-boldsymbol-beta'),
|
|
('Deriving OLS from a probability distribution',
|
|
2,
|
|
None,
|
|
'deriving-ols-from-a-probability-distribution'),
|
|
('Independent and Identically Distributed (iid)',
|
|
2,
|
|
None,
|
|
'independent-and-identically-distributed-iid'),
|
|
('Maximum Likelihood Estimation (MLE)',
|
|
2,
|
|
None,
|
|
'maximum-likelihood-estimation-mle'),
|
|
('A new Cost Function', 2, None, 'a-new-cost-function'),
|
|
('Why resampling methods', 2, None, 'why-resampling-methods'),
|
|
('Resampling methods', 2, None, 'resampling-methods'),
|
|
('Resampling approaches can be computationally expensive',
|
|
2,
|
|
None,
|
|
'resampling-approaches-can-be-computationally-expensive'),
|
|
('Why resampling methods ?', 2, None, 'why-resampling-methods'),
|
|
('Statistical analysis', 2, None, 'statistical-analysis'),
|
|
('Resampling methods', 2, None, 'resampling-methods'),
|
|
('Resampling methods: Bootstrap',
|
|
2,
|
|
None,
|
|
'resampling-methods-bootstrap'),
|
|
('The Central Limit Theorem',
|
|
2,
|
|
None,
|
|
'the-central-limit-theorem'),
|
|
('Finding the Limit', 2, None, 'finding-the-limit'),
|
|
('Rewriting the $\\delta$-function',
|
|
2,
|
|
None,
|
|
'rewriting-the-delta-function'),
|
|
('Identifying Terms', 2, None, 'identifying-terms'),
|
|
('Wrapping it up', 2, None, 'wrapping-it-up'),
|
|
('Confidence Intervals', 2, None, 'confidence-intervals'),
|
|
('Standard Approach based on the Normal Distribution',
|
|
2,
|
|
None,
|
|
'standard-approach-based-on-the-normal-distribution'),
|
|
('Resampling methods: Bootstrap background',
|
|
2,
|
|
None,
|
|
'resampling-methods-bootstrap-background'),
|
|
('Resampling methods: More Bootstrap background',
|
|
2,
|
|
None,
|
|
'resampling-methods-more-bootstrap-background'),
|
|
('Resampling methods: Bootstrap approach',
|
|
2,
|
|
None,
|
|
'resampling-methods-bootstrap-approach'),
|
|
('Resampling methods: Bootstrap steps',
|
|
2,
|
|
None,
|
|
'resampling-methods-bootstrap-steps'),
|
|
('Code example for the Bootstrap method',
|
|
2,
|
|
None,
|
|
'code-example-for-the-bootstrap-method'),
|
|
('Plotting the Histogram', 2, None, 'plotting-the-histogram'),
|
|
('The bias-variance tradeoff',
|
|
2,
|
|
None,
|
|
'the-bias-variance-tradeoff'),
|
|
('A way to Read the Bias-Variance Tradeoff',
|
|
2,
|
|
None,
|
|
'a-way-to-read-the-bias-variance-tradeoff'),
|
|
('Example code for Bias-Variance tradeoff',
|
|
2,
|
|
None,
|
|
'example-code-for-bias-variance-tradeoff'),
|
|
('Understanding what happens',
|
|
2,
|
|
None,
|
|
'understanding-what-happens'),
|
|
('Summing up', 2, None, 'summing-up'),
|
|
("Another Example from Scikit-Learn's Repository",
|
|
2,
|
|
None,
|
|
'another-example-from-scikit-learn-s-repository'),
|
|
('Various steps in cross-validation',
|
|
2,
|
|
None,
|
|
'various-steps-in-cross-validation'),
|
|
('Cross-validation in brief',
|
|
2,
|
|
None,
|
|
'cross-validation-in-brief'),
|
|
('Code Example for Cross-validation and $k$-fold '
|
|
'Cross-validation',
|
|
2,
|
|
None,
|
|
'code-example-for-cross-validation-and-k-fold-cross-validation'),
|
|
('More examples on bootstrap and cross-validation and errors',
|
|
2,
|
|
None,
|
|
'more-examples-on-bootstrap-and-cross-validation-and-errors'),
|
|
('The same example but now with cross-validation',
|
|
2,
|
|
None,
|
|
'the-same-example-but-now-with-cross-validation'),
|
|
('Material for the lab sessions',
|
|
2,
|
|
None,
|
|
'material-for-the-lab-sessions')]}
|
|
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="week38-bs.html">Week 38: Statistical analysis, bias-variance tradeoff and resampling methods</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="._week38-bs001.html#plans-for-week-38-lecture-monday-september-15" style="font-size: 80%;">Plans for week 38, lecture Monday September 15</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs002.html#readings-and-videos" style="font-size: 80%;">Readings and Videos</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs003.html#linking-the-regression-analysis-with-a-statistical-interpretation" style="font-size: 80%;">Linking the regression analysis with a statistical interpretation</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs004.html#assumptions-made" style="font-size: 80%;">Assumptions made</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs005.html#expectation-value-and-variance" style="font-size: 80%;">Expectation value and variance</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs006.html#expectation-value-and-variance-for-boldsymbol-beta" style="font-size: 80%;">Expectation value and variance for \( \boldsymbol{\beta} \)</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs007.html#deriving-ols-from-a-probability-distribution" style="font-size: 80%;">Deriving OLS from a probability distribution</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs008.html#independent-and-identically-distributed-iid" style="font-size: 80%;">Independent and Identically Distributed (iid)</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs009.html#maximum-likelihood-estimation-mle" style="font-size: 80%;">Maximum Likelihood Estimation (MLE)</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs010.html#a-new-cost-function" style="font-size: 80%;">A new Cost Function</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs014.html#why-resampling-methods" style="font-size: 80%;">Why resampling methods</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs016.html#resampling-methods" style="font-size: 80%;">Resampling methods</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs013.html#resampling-approaches-can-be-computationally-expensive" style="font-size: 80%;">Resampling approaches can be computationally expensive</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs014.html#why-resampling-methods" style="font-size: 80%;">Why resampling methods ?</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs015.html#statistical-analysis" style="font-size: 80%;">Statistical analysis</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs016.html#resampling-methods" style="font-size: 80%;">Resampling methods</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs017.html#resampling-methods-bootstrap" style="font-size: 80%;">Resampling methods: Bootstrap</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs018.html#the-central-limit-theorem" style="font-size: 80%;">The Central Limit Theorem</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs019.html#finding-the-limit" style="font-size: 80%;">Finding the Limit</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs020.html#rewriting-the-delta-function" style="font-size: 80%;">Rewriting the \( \delta \)-function</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs021.html#identifying-terms" style="font-size: 80%;">Identifying Terms</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs022.html#wrapping-it-up" style="font-size: 80%;">Wrapping it up</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs023.html#confidence-intervals" style="font-size: 80%;">Confidence Intervals</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs024.html#standard-approach-based-on-the-normal-distribution" style="font-size: 80%;">Standard Approach based on the Normal Distribution</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs025.html#resampling-methods-bootstrap-background" style="font-size: 80%;">Resampling methods: Bootstrap background</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs026.html#resampling-methods-more-bootstrap-background" style="font-size: 80%;">Resampling methods: More Bootstrap background</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs027.html#resampling-methods-bootstrap-approach" style="font-size: 80%;">Resampling methods: Bootstrap approach</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs028.html#resampling-methods-bootstrap-steps" style="font-size: 80%;">Resampling methods: Bootstrap steps</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs029.html#code-example-for-the-bootstrap-method" style="font-size: 80%;">Code example for the Bootstrap method</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs030.html#plotting-the-histogram" style="font-size: 80%;">Plotting the Histogram</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs031.html#the-bias-variance-tradeoff" style="font-size: 80%;">The bias-variance tradeoff</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs032.html#a-way-to-read-the-bias-variance-tradeoff" style="font-size: 80%;">A way to Read the Bias-Variance Tradeoff</a></li>
|
|
<!-- navigation toc: --> <li><a href="#example-code-for-bias-variance-tradeoff" style="font-size: 80%;">Example code for Bias-Variance tradeoff</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs034.html#understanding-what-happens" style="font-size: 80%;">Understanding what happens</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs035.html#summing-up" style="font-size: 80%;">Summing up</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs036.html#another-example-from-scikit-learn-s-repository" style="font-size: 80%;">Another Example from Scikit-Learn's Repository</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs037.html#various-steps-in-cross-validation" style="font-size: 80%;">Various steps in cross-validation</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs038.html#cross-validation-in-brief" style="font-size: 80%;">Cross-validation in brief</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs039.html#code-example-for-cross-validation-and-k-fold-cross-validation" style="font-size: 80%;">Code Example for Cross-validation and \( k \)-fold Cross-validation</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs040.html#more-examples-on-bootstrap-and-cross-validation-and-errors" style="font-size: 80%;">More examples on bootstrap and cross-validation and errors</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs041.html#the-same-example-but-now-with-cross-validation" style="font-size: 80%;">The same example but now with cross-validation</a></li>
|
|
<!-- navigation toc: --> <li><a href="._week38-bs042.html#material-for-the-lab-sessions" style="font-size: 80%;">Material for the lab sessions</a></li>
|
|
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div> <!-- end of navigation bar -->
|
|
<div class="container">
|
|
<p> </p><p> </p><p> </p> <!-- add vertical space -->
|
|
<a name="part0033"></a>
|
|
<!-- !split -->
|
|
<h2 id="example-code-for-bias-variance-tradeoff" class="anchor">Example code for Bias-Variance tradeoff </h2>
|
|
|
|
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
|
<div class="cell border-box-sizing code_cell rendered">
|
|
<div class="input">
|
|
<div class="inner_cell">
|
|
<div class="input_area">
|
|
<div class="highlight" style="background: #f8f8f8">
|
|
<pre style="line-height: 125%;"><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">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">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression, Ridge, Lasso
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> PolynomialFeatures
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.pipeline</span> <span style="color: #008000; font-weight: bold">import</span> make_pipeline
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.utils</span> <span style="color: #008000; font-weight: bold">import</span> resample
|
|
|
|
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">2018</span>)
|
|
|
|
n <span style="color: #666666">=</span> <span style="color: #666666">500</span>
|
|
n_boostraps <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
|
degree <span style="color: #666666">=</span> <span style="color: #666666">18</span> <span style="color: #408080; font-style: italic"># A quite high value, just to show.</span>
|
|
noise <span style="color: #666666">=</span> <span style="color: #666666">0.1</span>
|
|
|
|
<span style="color: #408080; font-style: italic"># Make data set.</span>
|
|
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">-1</span>, <span style="color: #666666">3</span>, n)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>)
|
|
y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>x<span style="color: #666666">**2</span>) <span style="color: #666666">+</span> <span style="color: #666666">1.5</span> <span style="color: #666666">*</span> np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>(x<span style="color: #666666">-2</span>)<span style="color: #666666">**2</span>) <span style="color: #666666">+</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>normal(<span style="color: #666666">0</span>, <span style="color: #666666">0.1</span>, x<span style="color: #666666">.</span>shape)
|
|
|
|
<span style="color: #408080; font-style: italic"># Hold out some test data that is never used in training.</span>
|
|
x_train, x_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(x, y, test_size<span style="color: #666666">=0.2</span>)
|
|
|
|
<span style="color: #408080; font-style: italic"># Combine x transformation and model into one operation.</span>
|
|
<span style="color: #408080; font-style: italic"># Not neccesary, but convenient.</span>
|
|
model <span style="color: #666666">=</span> make_pipeline(PolynomialFeatures(degree<span style="color: #666666">=</span>degree), LinearRegression(fit_intercept<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>))
|
|
|
|
<span style="color: #408080; font-style: italic"># The following (m x n_bootstraps) matrix holds the column vectors y_pred</span>
|
|
<span style="color: #408080; font-style: italic"># for each bootstrap iteration.</span>
|
|
y_pred <span style="color: #666666">=</span> np<span style="color: #666666">.</span>empty((y_test<span style="color: #666666">.</span>shape[<span style="color: #666666">0</span>], n_boostraps))
|
|
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(n_boostraps):
|
|
x_, y_ <span style="color: #666666">=</span> resample(x_train, y_train)
|
|
|
|
<span style="color: #408080; font-style: italic"># Evaluate the new model on the same test data each time.</span>
|
|
y_pred[:, i] <span style="color: #666666">=</span> model<span style="color: #666666">.</span>fit(x_, y_)<span style="color: #666666">.</span>predict(x_test)<span style="color: #666666">.</span>ravel()
|
|
|
|
<span style="color: #408080; font-style: italic"># Note: Expectations and variances taken w.r.t. different training</span>
|
|
<span style="color: #408080; font-style: italic"># data sets, hence the axis=1. Subsequent means are taken across the test data</span>
|
|
<span style="color: #408080; font-style: italic"># set in order to obtain a total value, but before this we have error/bias/variance</span>
|
|
<span style="color: #408080; font-style: italic"># calculated per data point in the test set.</span>
|
|
<span style="color: #408080; font-style: italic"># Note 2: The use of keepdims=True is important in the calculation of bias as this </span>
|
|
<span style="color: #408080; font-style: italic"># maintains the column vector form. Dropping this yields very unexpected results.</span>
|
|
error <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> y_pred)<span style="color: #666666">**2</span>, axis<span style="color: #666666">=1</span>, keepdims<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>) )
|
|
bias <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( (y_test <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y_pred, axis<span style="color: #666666">=1</span>, keepdims<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>))<span style="color: #666666">**2</span> )
|
|
variance <span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>var(y_pred, axis<span style="color: #666666">=1</span>, keepdims<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">True</span>) )
|
|
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Error:'</span>, error)
|
|
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Bias^2:'</span>, bias)
|
|
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Var:'</span>, variance)
|
|
<span style="color: #008000">print</span>(<span style="color: #BA2121">'</span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> >= </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> + </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> = </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">'</span><span style="color: #666666">.</span>format(error, bias, variance, bias<span style="color: #666666">+</span>variance))
|
|
|
|
plt<span style="color: #666666">.</span>plot(x[::<span style="color: #666666">5</span>, :], y[::<span style="color: #666666">5</span>, :], label<span style="color: #666666">=</span><span style="color: #BA2121">'f(x)'</span>)
|
|
plt<span style="color: #666666">.</span>scatter(x_test, y_test, label<span style="color: #666666">=</span><span style="color: #BA2121">'Data points'</span>)
|
|
plt<span style="color: #666666">.</span>scatter(x_test, np<span style="color: #666666">.</span>mean(y_pred, axis<span style="color: #666666">=1</span>), label<span style="color: #666666">=</span><span style="color: #BA2121">'Pred'</span>)
|
|
plt<span style="color: #666666">.</span>legend()
|
|
plt<span style="color: #666666">.</span>show()
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="output_wrapper">
|
|
<div class="output">
|
|
<div class="output_area">
|
|
<div class="output_subarea output_stream output_stdout output_text">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- navigation buttons at the bottom of the page -->
|
|
<ul class="pagination">
|
|
<li><a href="._week38-bs032.html">«</a></li>
|
|
<li><a href="._week38-bs000.html">1</a></li>
|
|
<li><a href="">...</a></li>
|
|
<li><a href="._week38-bs025.html">26</a></li>
|
|
<li><a href="._week38-bs026.html">27</a></li>
|
|
<li><a href="._week38-bs027.html">28</a></li>
|
|
<li><a href="._week38-bs028.html">29</a></li>
|
|
<li><a href="._week38-bs029.html">30</a></li>
|
|
<li><a href="._week38-bs030.html">31</a></li>
|
|
<li><a href="._week38-bs031.html">32</a></li>
|
|
<li><a href="._week38-bs032.html">33</a></li>
|
|
<li class="active"><a href="._week38-bs033.html">34</a></li>
|
|
<li><a href="._week38-bs034.html">35</a></li>
|
|
<li><a href="._week38-bs035.html">36</a></li>
|
|
<li><a href="._week38-bs036.html">37</a></li>
|
|
<li><a href="._week38-bs037.html">38</a></li>
|
|
<li><a href="._week38-bs038.html">39</a></li>
|
|
<li><a href="._week38-bs039.html">40</a></li>
|
|
<li><a href="._week38-bs040.html">41</a></li>
|
|
<li><a href="._week38-bs041.html">42</a></li>
|
|
<li><a href="._week38-bs042.html">43</a></li>
|
|
<li><a href="._week38-bs034.html">»</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="https://..."><img width="250" align=right src="https://..."></a>
|
|
</footer>
|
|
-->
|
|
<center style="font-size:80%">
|
|
<!-- copyright only on the titlepage -->
|
|
</center>
|
|
</body>
|
|
</html>
|
|
|