updated book chapter
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
======= Linear Regression =======
|
||||
|
||||
"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h20/forelesningsvideoer/LectureAug21.mp4?vrtx=view-as-webpage"
|
||||
|
||||
|
||||
===== Introduction =====
|
||||
|
||||
@@ -9,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
Our emphasis throughout this series of lectures (small change)
|
||||
Our emphasis throughout this series of lectures
|
||||
is on understanding the mathematical aspects of
|
||||
different algorithms used in the fields of data analysis and machine learning.
|
||||
|
||||
|
||||
+2102
-370
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -142,12 +142,12 @@
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="chapter2.html">
|
||||
4. Resampling Methods
|
||||
4. Ridge and Lasso Regression
|
||||
</a>
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="chapter3.html">
|
||||
5. Ridge and Lasso Regression
|
||||
5. Resampling Methods
|
||||
</a>
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
|
||||
@@ -143,12 +143,12 @@
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="chapter2.html">
|
||||
4. Resampling Methods
|
||||
4. Ridge and Lasso Regression
|
||||
</a>
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="chapter3.html">
|
||||
5. Ridge and Lasso Regression
|
||||
5. Resampling Methods
|
||||
</a>
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
|
||||
Binary file not shown.
@@ -17,88 +17,21 @@ Traceback (most recent call last):
|
||||
raise CellExecutionError.from_cell_and_msg(cell, exec_reply['content'])
|
||||
nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
|
||||
------------------
|
||||
%matplotlib inline
|
||||
|
||||
from numpy import *
|
||||
from numpy.random import randint, randn
|
||||
from time import time
|
||||
import matplotlib.mlab as mlab
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Returns mean of bootstrap samples
|
||||
def stat(data):
|
||||
return mean(data)
|
||||
|
||||
# Bootstrap algorithm
|
||||
def bootstrap(data, statistic, R):
|
||||
t = zeros(R); n = len(data); inds = arange(n); t0 = time()
|
||||
# non-parametric bootstrap
|
||||
for i in range(R):
|
||||
t[i] = statistic(data[randint(0,n,n)])
|
||||
|
||||
# analysis
|
||||
print("Runtime: %g sec" % (time()-t0)); print("Bootstrap Statistics :")
|
||||
print("original bias std. error")
|
||||
print("%8g %8g %14g %15g" % (statistic(data), std(data),mean(t),std(t)))
|
||||
return t
|
||||
|
||||
|
||||
mu, sigma = 100, 15
|
||||
datapoints = 10000
|
||||
x = mu + sigma*random.randn(datapoints)
|
||||
# bootstrap returns the data sample
|
||||
t = bootstrap(x, stat, datapoints)
|
||||
# the histogram of the bootstrapped data
|
||||
n, binsboot, patches = plt.hist(t, 50, normed=1, facecolor='red', alpha=0.75)
|
||||
|
||||
# add a 'best fit' line
|
||||
y = mlab.normpdf( binsboot, mean(t), std(t))
|
||||
lt = plt.plot(binsboot, y, 'r--', linewidth=1)
|
||||
plt.xlabel('Smarts')
|
||||
plt.ylabel('Probability')
|
||||
plt.axis([99.5, 100.6, 0, 3.0])
|
||||
plt.grid(True)
|
||||
|
||||
plt.show()
|
||||
Ainv = np.linlag.pinv(A)
|
||||
------------------
|
||||
|
||||
[0;31m---------------------------------------------------------------------------[0m
|
||||
[0;31mAttributeError[0m Traceback (most recent call last)
|
||||
[0;32m<ipython-input-2-772b904ae9cb>[0m in [0;36m<module>[0;34m[0m
|
||||
[1;32m 31[0m [0mt[0m [0;34m=[0m [0mbootstrap[0m[0;34m([0m[0mx[0m[0;34m,[0m [0mstat[0m[0;34m,[0m [0mdatapoints[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
[1;32m 32[0m [0;31m# the histogram of the bootstrapped data[0m[0;34m[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0;32m---> 33[0;31m [0mn[0m[0;34m,[0m [0mbinsboot[0m[0;34m,[0m [0mpatches[0m [0;34m=[0m [0mplt[0m[0;34m.[0m[0mhist[0m[0;34m([0m[0mt[0m[0;34m,[0m [0;36m50[0m[0;34m,[0m [0mnormed[0m[0;34m=[0m[0;36m1[0m[0;34m,[0m [0mfacecolor[0m[0;34m=[0m[0;34m'red'[0m[0;34m,[0m [0malpha[0m[0;34m=[0m[0;36m0.75[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0m[1;32m 34[0m [0;34m[0m[0m
|
||||
[1;32m 35[0m [0;31m# add a 'best fit' line[0m[0;34m[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0;32m<ipython-input-6-52d2c51caad1>[0m in [0;36m<module>[0;34m[0m
|
||||
[0;32m----> 1[0;31m [0mAinv[0m [0;34m=[0m [0mnp[0m[0;34m.[0m[0mlinlag[0m[0;34m.[0m[0mpinv[0m[0;34m([0m[0mA[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0m
|
||||
[0;32m~/opt/anaconda3/lib/python3.8/site-packages/numpy/__init__.py[0m in [0;36m__getattr__[0;34m(attr)[0m
|
||||
[1;32m 212[0m [0;32mreturn[0m [0mTester[0m[0;34m[0m[0;34m[0m[0m
|
||||
[1;32m 213[0m [0;32melse[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0;32m--> 214[0;31m raise AttributeError("module {!r} has no attribute "
|
||||
[0m[1;32m 215[0m "{!r}".format(__name__, attr))
|
||||
[1;32m 216[0m [0;34m[0m[0m
|
||||
|
||||
[0;32m~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/pyplot.py[0m in [0;36mhist[0;34m(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, data, **kwargs)[0m
|
||||
[1;32m 2683[0m [0morientation[0m[0;34m=[0m[0;34m'vertical'[0m[0;34m,[0m [0mrwidth[0m[0;34m=[0m[0;32mNone[0m[0;34m,[0m [0mlog[0m[0;34m=[0m[0;32mFalse[0m[0;34m,[0m [0mcolor[0m[0;34m=[0m[0;32mNone[0m[0;34m,[0m[0;34m[0m[0;34m[0m[0m
|
||||
[1;32m 2684[0m label=None, stacked=False, *, data=None, **kwargs):
|
||||
[0;32m-> 2685[0;31m return gca().hist(
|
||||
[0m[1;32m 2686[0m [0mx[0m[0;34m,[0m [0mbins[0m[0;34m=[0m[0mbins[0m[0;34m,[0m [0mrange[0m[0;34m=[0m[0mrange[0m[0;34m,[0m [0mdensity[0m[0;34m=[0m[0mdensity[0m[0;34m,[0m [0mweights[0m[0;34m=[0m[0mweights[0m[0;34m,[0m[0;34m[0m[0;34m[0m[0m
|
||||
[1;32m 2687[0m [0mcumulative[0m[0;34m=[0m[0mcumulative[0m[0;34m,[0m [0mbottom[0m[0;34m=[0m[0mbottom[0m[0;34m,[0m [0mhisttype[0m[0;34m=[0m[0mhisttype[0m[0;34m,[0m[0;34m[0m[0;34m[0m[0m
|
||||
|
||||
[0;32m~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/__init__.py[0m in [0;36minner[0;34m(ax, data, *args, **kwargs)[0m
|
||||
[1;32m 1445[0m [0;32mdef[0m [0minner[0m[0;34m([0m[0max[0m[0;34m,[0m [0;34m*[0m[0margs[0m[0;34m,[0m [0mdata[0m[0;34m=[0m[0;32mNone[0m[0;34m,[0m [0;34m**[0m[0mkwargs[0m[0;34m)[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m
|
||||
[1;32m 1446[0m [0;32mif[0m [0mdata[0m [0;32mis[0m [0;32mNone[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0;32m-> 1447[0;31m [0;32mreturn[0m [0mfunc[0m[0;34m([0m[0max[0m[0;34m,[0m [0;34m*[0m[0mmap[0m[0;34m([0m[0msanitize_sequence[0m[0;34m,[0m [0margs[0m[0;34m)[0m[0;34m,[0m [0;34m**[0m[0mkwargs[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0m[1;32m 1448[0m [0;34m[0m[0m
|
||||
[1;32m 1449[0m [0mbound[0m [0;34m=[0m [0mnew_sig[0m[0;34m.[0m[0mbind[0m[0;34m([0m[0max[0m[0;34m,[0m [0;34m*[0m[0margs[0m[0;34m,[0m [0;34m**[0m[0mkwargs[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
|
||||
[0;32m~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_axes.py[0m in [0;36mhist[0;34m(self, x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)[0m
|
||||
[1;32m 6813[0m [0;32mif[0m [0mpatch[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m
|
||||
[1;32m 6814[0m [0mp[0m [0;34m=[0m [0mpatch[0m[0;34m[[0m[0;36m0[0m[0;34m][0m[0;34m[0m[0;34m[0m[0m
|
||||
[0;32m-> 6815[0;31m [0mp[0m[0;34m.[0m[0mupdate[0m[0;34m([0m[0mkwargs[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0m[1;32m 6816[0m [0;32mif[0m [0mlbl[0m [0;32mis[0m [0;32mnot[0m [0;32mNone[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m
|
||||
[1;32m 6817[0m [0mp[0m[0;34m.[0m[0mset_label[0m[0;34m([0m[0mlbl[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
|
||||
[0;32m~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/artist.py[0m in [0;36mupdate[0;34m(self, props)[0m
|
||||
[1;32m 994[0m [0mfunc[0m [0;34m=[0m [0mgetattr[0m[0;34m([0m[0mself[0m[0;34m,[0m [0;34mf"set_{k}"[0m[0;34m,[0m [0;32mNone[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
[1;32m 995[0m [0;32mif[0m [0;32mnot[0m [0mcallable[0m[0;34m([0m[0mfunc[0m[0;34m)[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m
|
||||
[0;32m--> 996[0;31m raise AttributeError(f"{type(self).__name__!r} object "
|
||||
[0m[1;32m 997[0m f"has no property {k!r}")
|
||||
[1;32m 998[0m [0mret[0m[0;34m.[0m[0mappend[0m[0;34m([0m[0mfunc[0m[0;34m([0m[0mv[0m[0;34m)[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m
|
||||
|
||||
[0;31mAttributeError[0m: 'Rectangle' object has no property 'normed'
|
||||
AttributeError: 'Rectangle' object has no property 'normed'
|
||||
[0;31mAttributeError[0m: module 'numpy' has no attribute 'linlag'
|
||||
AttributeError: module 'numpy' has no attribute 'linlag'
|
||||
|
||||
|
||||
@@ -147,12 +147,12 @@
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="chapter2.html">
|
||||
4. Resampling Methods
|
||||
4. Ridge and Lasso Regression
|
||||
</a>
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="chapter3.html">
|
||||
5. Ridge and Lasso Regression
|
||||
5. Resampling Methods
|
||||
</a>
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
+3960
-994
File diff suppressed because it is too large
Load Diff
+997
-1023
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user