diff --git a/doc/pub/DecisionTrees/html/DecisionTrees-bs.html b/doc/pub/DecisionTrees/html/DecisionTrees-bs.html index 01b0bb12e..1e27744ca 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees-bs.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees-bs.html @@ -6,9 +6,9 @@ Automatically generated HTML file from DocOnce source
- + -@@ -132,7 +132,7 @@ td.padding {
-
@@ -151,6 +151,167 @@ td.padding {
+
+
+
+
+
+
+Nearest Neighbors
+import mglearn
+import numpy as np
+from sklearn import linear_model
+from sklearn.linear_model import LinearRegression
+import matplotlib.pyplot as plt
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.pipeline import Pipeline
+from sklearn.neighbors import KNeighborsClassifier
+
+# Generate sample data
+X = np.sort(5*np.random.rand(40,1), axis=0)
+y = X**3
+y=y.ravel()
+
+# Add noise to targets
+X[::4] +=(0.5 - np.random.rand(1))
+y[::5] +=(0.5 - np.random.rand(8))
+
+a=np.array(X)
+b=np.array(y)
+
+X_train=a[:19]
+X_test=a[19:]
+y_train=b[:19]
+y_test=b[19:]
+
+model=Pipeline([('poly', PolynomialFeatures(degree=3)),('linear', LinearRegression(fit_intercept=False))])
+model=model.fit(X_train, y_train)
+pred=model.predict(X_test)
+
+
+poly=PolynomialFeatures(degree=3)
+poly.fit_transform(X_train, y_train)
+plt.scatter(X_test, y_test)
+plt.plot(X_test, pred, color='green')
+plt.show()
+
+print (model.score(X_test,y_test))
+
+print ("---------K-Nearest Neighbors-------")
+"""neighbors_settings=range(1,11)
+for n_neighbors in neighbors_settings:
+ clf=KNeighborsClassifier(n_neighbors=n_neighbors)
+ clf.fit(X_train, y_train)
+ training_accuracy.append(clf.score(X_train, y_train))
+ test_accuracy.append(clf.score(X_test, y_test))
+
+
+print (mglearn.plots.plot_knn_regression(n_neighbors=3))"""
+
+from sklearn.neighbors import KNeighborsRegressor
+
+X, y=mglearn.datasets.make_wave(n_samples=40)
+reg = KNeighborsRegressor(n_neighbors=3)
+reg.fit(X_train, y_train)
+
Decision trees and Regression
+import numpy as np
+import matplotlib.pyplot as plt
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.linear_model import LinearRegression
+
+steps=250
+
+distance=0
+x=0
+distance_list=[]
+steps_list=[]
+while x<steps:
+ distance+=np.random.randint(-1,2)
+ distance_list.append(distance)
+ x+=1
+ steps_list.append(x)
+plt.plot(steps_list,distance_list, color='green', label="Random Walk Data")
+
+steps_list=np.asarray(steps_list)
+distance_list=np.asarray(distance_list)
+
+X=steps_list[:,np.newaxis]
+
+#Polynomial fits
+
+#Degree 2
+poly_features=PolynomialFeatures(degree=2, include_bias=False)
+X_poly=poly_features.fit_transform(X)
+
+lin_reg=LinearRegression()
+poly_fit=lin_reg.fit(X_poly,distance_list)
+b=lin_reg.coef_
+c=lin_reg.intercept_
+print ("2nd degree coefficients:")
+print ("zero power: ",c)
+print ("first power: ", b[0])
+print ("second power: ",b[1])
+
+z = np.arange(0, steps, .01)
+z_mod=b[1]*z**2+b[0]*z+c
+
+fit_mod=b[1]*X**2+b[0]*X+c
+plt.plot(z, z_mod, color='r', label="2nd Degree Fit")
+plt.title("Polynomial Regression")
+
+plt.xlabel("Steps")
+plt.ylabel("Distance")
+
+#Degree 10
+poly_features10=PolynomialFeatures(degree=10, include_bias=False)
+X_poly10=poly_features10.fit_transform(X)
+
+poly_fit10=lin_reg.fit(X_poly10,distance_list)
+
+y_plot=poly_fit10.predict(X_poly10)
+plt.plot(X, y_plot, color='black', label="10th Degree Fit")
+
+plt.legend()
+plt.show()
+
+
+#Decision Tree Regression
+from sklearn.tree import DecisionTreeRegressor
+regr_1=DecisionTreeRegressor(max_depth=2)
+regr_2=DecisionTreeRegressor(max_depth=5)
+regr_3=DecisionTreeRegressor(max_depth=7)
+regr_1.fit(X, distance_list)
+regr_2.fit(X, distance_list)
+regr_3.fit(X, distance_list)
+
+X_test = np.arange(0.0, steps, 0.01)[:, np.newaxis]
+y_1 = regr_1.predict(X_test)
+y_2 = regr_2.predict(X_test)
+y_3=regr_3.predict(X_test)
+
+# Plot the results
+plt.figure()
+plt.scatter(X, distance_list, s=2.5, c="black", label="data")
+plt.plot(X_test, y_1, color="red",
+ label="max_depth=2", linewidth=2)
+plt.plot(X_test, y_2, color="green", label="max_depth=5", linewidth=2)
+plt.plot(X_test, y_3, color="m", label="max_depth=7", linewidth=2)
+
+plt.xlabel("Data")
+plt.ylabel("Darget")
+plt.title("Decision Tree Regression")
+plt.legend()
+plt.show()
+
@@ -86,7 +88,7 @@ end of tocinfo -->
-
@@ -100,6 +102,167 @@ end of tocinfo -->
+
+
+
+
+ + +
import mglearn
+import numpy as np
+from sklearn import linear_model
+from sklearn.linear_model import LinearRegression
+import matplotlib.pyplot as plt
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.pipeline import Pipeline
+from sklearn.neighbors import KNeighborsClassifier
+
+# Generate sample data
+X = np.sort(5*np.random.rand(40,1), axis=0)
+y = X**3
+y=y.ravel()
+
+# Add noise to targets
+X[::4] +=(0.5 - np.random.rand(1))
+y[::5] +=(0.5 - np.random.rand(8))
+
+a=np.array(X)
+b=np.array(y)
+
+X_train=a[:19]
+X_test=a[19:]
+y_train=b[:19]
+y_test=b[19:]
+
+model=Pipeline([('poly', PolynomialFeatures(degree=3)),('linear', LinearRegression(fit_intercept=False))])
+model=model.fit(X_train, y_train)
+pred=model.predict(X_test)
+
+
+poly=PolynomialFeatures(degree=3)
+poly.fit_transform(X_train, y_train)
+plt.scatter(X_test, y_test)
+plt.plot(X_test, pred, color='green')
+plt.show()
+
+print (model.score(X_test,y_test))
+
+print ("---------K-Nearest Neighbors-------")
+"""neighbors_settings=range(1,11)
+for n_neighbors in neighbors_settings:
+ clf=KNeighborsClassifier(n_neighbors=n_neighbors)
+ clf.fit(X_train, y_train)
+ training_accuracy.append(clf.score(X_train, y_train))
+ test_accuracy.append(clf.score(X_test, y_test))
+
+
+print (mglearn.plots.plot_knn_regression(n_neighbors=3))"""
+
+from sklearn.neighbors import KNeighborsRegressor
+
+X, y=mglearn.datasets.make_wave(n_samples=40)
+reg = KNeighborsRegressor(n_neighbors=3)
+reg.fit(X_train, y_train)
+
+
+
+
+ + +
import numpy as np
+import matplotlib.pyplot as plt
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.linear_model import LinearRegression
+
+steps=250
+
+distance=0
+x=0
+distance_list=[]
+steps_list=[]
+while x<steps:
+ distance+=np.random.randint(-1,2)
+ distance_list.append(distance)
+ x+=1
+ steps_list.append(x)
+plt.plot(steps_list,distance_list, color='green', label="Random Walk Data")
+
+steps_list=np.asarray(steps_list)
+distance_list=np.asarray(distance_list)
+
+X=steps_list[:,np.newaxis]
+
+#Polynomial fits
+
+#Degree 2
+poly_features=PolynomialFeatures(degree=2, include_bias=False)
+X_poly=poly_features.fit_transform(X)
+
+lin_reg=LinearRegression()
+poly_fit=lin_reg.fit(X_poly,distance_list)
+b=lin_reg.coef_
+c=lin_reg.intercept_
+print ("2nd degree coefficients:")
+print ("zero power: ",c)
+print ("first power: ", b[0])
+print ("second power: ",b[1])
+
+z = np.arange(0, steps, .01)
+z_mod=b[1]*z**2+b[0]*z+c
+
+fit_mod=b[1]*X**2+b[0]*X+c
+plt.plot(z, z_mod, color='r', label="2nd Degree Fit")
+plt.title("Polynomial Regression")
+
+plt.xlabel("Steps")
+plt.ylabel("Distance")
+
+#Degree 10
+poly_features10=PolynomialFeatures(degree=10, include_bias=False)
+X_poly10=poly_features10.fit_transform(X)
+
+poly_fit10=lin_reg.fit(X_poly10,distance_list)
+
+y_plot=poly_fit10.predict(X_poly10)
+plt.plot(X, y_plot, color='black', label="10th Degree Fit")
+
+plt.legend()
+plt.show()
+
+
+#Decision Tree Regression
+from sklearn.tree import DecisionTreeRegressor
+regr_1=DecisionTreeRegressor(max_depth=2)
+regr_2=DecisionTreeRegressor(max_depth=5)
+regr_3=DecisionTreeRegressor(max_depth=7)
+regr_1.fit(X, distance_list)
+regr_2.fit(X, distance_list)
+regr_3.fit(X, distance_list)
+
+X_test = np.arange(0.0, steps, 0.01)[:, np.newaxis]
+y_1 = regr_1.predict(X_test)
+y_2 = regr_2.predict(X_test)
+y_3=regr_3.predict(X_test)
+
+# Plot the results
+plt.figure()
+plt.scatter(X, distance_list, s=2.5, c="black", label="data")
+plt.plot(X_test, y_1, color="red",
+ label="max_depth=2", linewidth=2)
+plt.plot(X_test, y_2, color="green", label="max_depth=5", linewidth=2)
+plt.plot(X_test, y_3, color="m", label="max_depth=7", linewidth=2)
+
+plt.xlabel("Data")
+plt.ylabel("Darget")
+plt.title("Decision Tree Regression")
+plt.legend()
+plt.show()
++ diff --git a/doc/pub/DecisionTrees/html/DecisionTrees.html b/doc/pub/DecisionTrees/html/DecisionTrees.html index c37f064bc..caf1002f0 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees.html @@ -6,9 +6,9 @@ Automatically generated HTML file from DocOnce source
- + -"+s(c.message+"",!0)+"";throw c}}var p={newline:/^\n+/,code:/^( {4}[^\n]+\n*)+/,fences:o,hr:/^( *[-*_]){3,} *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,nptable:o,lheading:/^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,blockquote:/^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,list:/^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,html:/^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,def:/^ *\[([^\]]+)\]: *([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,table:o,paragraph:/^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,text:/^[^\n]+/};p.bullet=/(?:[*+-]|\d+\.)/,p.item=/^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/,p.item=l(p.item,"gm")(/bull/g,p.bullet)(),p.list=l(p.list)(/bull/g,p.bullet)("hr","\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))")("def","\\n+(?="+p.def.source+")")(),p.blockquote=l(p.blockquote)("def",p.def)(),p._tag="(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b",p.html=l(p.html)("comment",//)("closed",/<(tag)[\s\S]+?<\/\1>/)("closing",/
'+(n?e:s(e,!0))+"\n\n":""+(n?e:s(e,!0))+"\n"},n.prototype.blockquote=function(e){return"\n"+e+"\n"},n.prototype.html=function(e){return e},n.prototype.heading=function(e,t,n){return"
"+e+"
\n"},n.prototype.table=function(e,t){return""+e+""},n.prototype.br=function(){return this.options.xhtml?""+(escaped?code:escape(code,true))+"\n"}return''+(escaped?code:escape(code,true))+"\n\n"};Renderer.prototype.blockquote=function(quote){return"\n"+quote+"\n"};Renderer.prototype.html=function(html){return html};Renderer.prototype.heading=function(text,level,raw){return"
"+text+"
\n"};Renderer.prototype.table=function(header,body){return""+text+""};Renderer.prototype.br=function(){return this.options.xhtml?""+escape(e.message+"",true)+""}throw e}}marked.options=marked.setOptions=function(opt){merge(marked.defaults,opt);return marked};marked.defaults={gfm:true,tables:true,breaks:false,pedantic:false,sanitize:false,sanitizer:null,mangle:true,smartLists:false,silent:false,highlight:null,langPrefix:"lang-",smartypants:false,headerPrefix:"",renderer:new Renderer,xhtml:false};marked.Parser=Parser;marked.parser=Parser.parse;marked.Renderer=Renderer;marked.Lexer=Lexer;marked.lexer=Lexer.lex;marked.InlineLexer=InlineLexer;marked.inlineLexer=InlineLexer.output;marked.parse=marked;if(typeof module!=="undefined"&&typeof exports==="object"){module.exports=marked}else if(typeof define==="function"&&define.amd){define(function(){return marked})}else{this.marked=marked}}).call(function(){return this||(typeof window!=="undefined"?window:global)}()); \ No newline at end of file diff --git a/doc/pub/NeuralNet/html/reveal.js/plugin/math/math.js b/doc/pub/NeuralNet/html/reveal.js/plugin/math/math.js index 25b751637..e3b408981 100644 --- a/doc/pub/NeuralNet/html/reveal.js/plugin/math/math.js +++ b/doc/pub/NeuralNet/html/reveal.js/plugin/math/math.js @@ -7,14 +7,17 @@ var RevealMath = window.RevealMath || (function(){ var options = Reveal.getConfig().math || {}; - options.mathjax = options.mathjax || 'https://cdn.mathjax.org/mathjax/latest/MathJax.js'; + options.mathjax = options.mathjax || 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js'; options.config = options.config || 'TeX-AMS_HTML-full'; loadScript( options.mathjax + '?config=' + options.config, function() { MathJax.Hub.Config({ messageStyle: 'none', - tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }, + tex2jax: { + inlineMath: [['$','$'],['\\(','\\)']] , + skipTags: ['script','noscript','style','textarea','pre'] + }, skipStartupTypeset: true }); diff --git a/doc/pub/NeuralNet/html/reveal.js/plugin/multiplex/client.js b/doc/pub/NeuralNet/html/reveal.js/plugin/multiplex/client.js index e6179f6de..3ffd1e033 100644 --- a/doc/pub/NeuralNet/html/reveal.js/plugin/multiplex/client.js +++ b/doc/pub/NeuralNet/html/reveal.js/plugin/multiplex/client.js @@ -8,6 +8,6 @@ if (data.socketId !== socketId) { return; } if( window.location.host === 'localhost:1947' ) return; - Reveal.slide(data.indexh, data.indexv, data.indexf, 'remote'); + Reveal.setState(data.state); }); }()); diff --git a/doc/pub/NeuralNet/html/reveal.js/plugin/multiplex/index.js b/doc/pub/NeuralNet/html/reveal.js/plugin/multiplex/index.js index af058ed2f..8195f046d 100644 --- a/doc/pub/NeuralNet/html/reveal.js/plugin/multiplex/index.js +++ b/doc/pub/NeuralNet/html/reveal.js/plugin/multiplex/index.js @@ -1,37 +1,45 @@ +var http = require('http'); var express = require('express'); var fs = require('fs'); var io = require('socket.io'); var crypto = require('crypto'); -var app = express.createServer(); -var staticDir = express.static; +var app = express(); +var staticDir = express.static; +var server = http.createServer(app); -io = io.listen(app); +io = io(server); var opts = { port: process.env.PORT || 1948, baseDir : __dirname + '/../../' }; -io.sockets.on('connection', function(socket) { - socket.on('slidechanged', function(slideData) { - if (typeof slideData.secret == 'undefined' || slideData.secret == null || slideData.secret === '') return; - if (createHash(slideData.secret) === slideData.socketId) { - slideData.secret = null; - socket.broadcast.emit(slideData.socketId, slideData); +io.on( 'connection', function( socket ) { + socket.on('multiplex-statechanged', function(data) { + if (typeof data.secret == 'undefined' || data.secret == null || data.secret === '') return; + if (createHash(data.secret) === data.socketId) { + data.secret = null; + socket.broadcast.emit(data.socketId, data); }; }); }); -app.configure(function() { - [ 'css', 'js', 'plugin', 'lib' ].forEach(function(dir) { - app.use('/' + dir, staticDir(opts.baseDir + dir)); - }); +[ 'css', 'js', 'plugin', 'lib' ].forEach(function(dir) { + app.use('/' + dir, staticDir(opts.baseDir + dir)); }); app.get("/", function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); - fs.createReadStream(opts.baseDir + '/index.html').pipe(res); + + var stream = fs.createReadStream(opts.baseDir + '/index.html'); + stream.on('error', function( error ) { + res.write('
-
+ +
import numpy as np
+from sklearn.svm import SVR
+import matplotlib.pyplot as plt
-diff --git a/doc/pub/svm/html/svm.html b/doc/pub/svm/html/svm.html index 149c64d48..497df0d1e 100644 --- a/doc/pub/svm/html/svm.html +++ b/doc/pub/svm/html/svm.html @@ -30,32 +30,6 @@ p { text-indent: 0px; } hr { border: 0; width: 80%; border-bottom: 1px solid #aaa} p.caption { width: 80%; font-style: normal; text-align: left; } hr.figure { border: 0; width: 80%; border-bottom: 1px solid #aaa} -.alert-text-small { font-size: 80%; } -.alert-text-large { font-size: 130%; } -.alert-text-normal { font-size: 90%; } -.alert { - padding:8px 35px 8px 14px; margin-bottom:18px; - text-shadow:0 1px 0 rgba(255,255,255,0.5); - border:1px solid #bababa; - border-radius: 4px; - -webkit-border-radius: 4px; - -moz-border-radius: 4px; - color: #555; - background-color: #f8f8f8; - background-position: 10px 5px; - background-repeat: no-repeat; - background-size: 38px; - padding-left: 55px; - width: 75%; - } -.alert-block {padding-top:14px; padding-bottom:14px} -.alert-block > p, .alert-block > ul {margin-bottom:1em} -.alert li {margin-top: 1em} -.alert-block p+p {margin-top:5px} -.alert-notice { background-image: url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_notice.png); } -.alert-summary { background-image:url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_summary.png); } -.alert-warning { background-image: url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_warning.png); } -.alert-question {background-image:url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_question.png); } div { text-align: justify; text-justify: inter-word; } @@ -94,19 +68,51 @@ end of tocinfo -->
-
+ +
import numpy as np
+from sklearn.svm import SVR
+import matplotlib.pyplot as plt
-
diff --git a/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz b/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz
index f50314532..0d17f826b 100644
Binary files a/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz and b/doc/pub/svm/ipynb/ipynb-svm-src.tar.gz differ
diff --git a/doc/pub/svm/ipynb/svm.ipynb b/doc/pub/svm/ipynb/svm.ipynb
index 549670130..697c1a740 100644
--- a/doc/pub/svm/ipynb/svm.ipynb
+++ b/doc/pub/svm/ipynb/svm.ipynb
@@ -10,7 +10,7 @@
" \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: **May 22, 2018**\n",
+ "Date: **May 30, 2018**\n",
"\n",
"Copyright 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
@@ -19,6 +19,51 @@
"\n",
"## Support Vector Machines, overarching aims"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "%matplotlib inline\n",
+ "\n",
+ "import numpy as np\n",
+ "from sklearn.svm import SVR\n",
+ "import matplotlib.pyplot as plt\n",
+ "\n",
+ "# Generate sample data\n",
+ "X = np.sort(5*np.random.rand(40,1), axis=0)\n",
+ "y = X**3\n",
+ "y=y.ravel()\n",
+ "\n",
+ "# Add noise to targets\n",
+ "X[::4] +=3*(0.5 - np.random.rand(1))\n",
+ "y[::5] += 50 * (0.5 - np.random.rand(8))\n",
+ "\n",
+ "plt.plot(X,y, 'g^')\n",
+ "\n",
+ "#SVR Fit\n",
+ "svr_poly = SVR(kernel='poly', C=1e3, degree=3)\n",
+ "y_poly = svr_poly.fit(X, y).predict(X)\n",
+ "\n",
+ "# Plots\n",
+ "z = np.arange(0, 5, 0.1)\n",
+ "t = z**3\n",
+ "fig = plt.figure()\n",
+ "ax = fig.add_subplot(111)\n",
+ "plt.plot(z,z**3, 'r--', label='Cubic Function with No Noise')\n",
+ "lw = 2\n",
+ "plt.scatter(X, y, color='darkorange', label='Gaussian Cubic Noise')\n",
+ "plt.plot(X, y_poly, color='green', lw=lw, label='Polynomial model')\n",
+ "plt.xlabel('data')\n",
+ "plt.ylabel('target')\n",
+ "plt.title('Cubic Gaussian Distribution')\n",
+ "plt.legend()\n",
+ "plt.show()"
+ ]
}
],
"metadata": {},
diff --git a/doc/pub/svm/pdf/svm-beamer-handouts2x3.pdf b/doc/pub/svm/pdf/svm-beamer-handouts2x3.pdf
index f0e15a565..3991ef9c0 100644
Binary files a/doc/pub/svm/pdf/svm-beamer-handouts2x3.pdf and b/doc/pub/svm/pdf/svm-beamer-handouts2x3.pdf differ
diff --git a/doc/pub/svm/pdf/svm-beamer.pdf b/doc/pub/svm/pdf/svm-beamer.pdf
index 728b1dc4a..77324339a 100644
Binary files a/doc/pub/svm/pdf/svm-beamer.pdf and b/doc/pub/svm/pdf/svm-beamer.pdf differ
diff --git a/doc/pub/svm/pdf/svm-minted.pdf b/doc/pub/svm/pdf/svm-minted.pdf
index 8ec3299c5..64e86e7f4 100644
Binary files a/doc/pub/svm/pdf/svm-minted.pdf and b/doc/pub/svm/pdf/svm-minted.pdf differ
diff --git a/doc/src/DecisionTrees/DecisionTrees.do.txt b/doc/src/DecisionTrees/DecisionTrees.do.txt
index a92078bad..24fd3865a 100644
--- a/doc/src/DecisionTrees/DecisionTrees.do.txt
+++ b/doc/src/DecisionTrees/DecisionTrees.do.txt
@@ -1,4 +1,4 @@
-TITLE: Data Analysis and Machine Learning: Decision Trees, from simple to randon ones
+TITLE: Data Analysis and Machine Learning: Nearest Neighbors and Decision Trees
AUTHOR: Morten Hjorth-Jensen {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
DATE: today
@@ -9,3 +9,157 @@ DATE: today
!eblock
+!split
+===== Nearest Neighbors =====
+!bc pycod
+import mglearn
+import numpy as np
+from sklearn import linear_model
+from sklearn.linear_model import LinearRegression
+import matplotlib.pyplot as plt
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.pipeline import Pipeline
+from sklearn.neighbors import KNeighborsClassifier
+
+# Generate sample data
+X = np.sort(5*np.random.rand(40,1), axis=0)
+y = X**3
+y=y.ravel()
+
+# Add noise to targets
+X[::4] +=(0.5 - np.random.rand(1))
+y[::5] +=(0.5 - np.random.rand(8))
+
+a=np.array(X)
+b=np.array(y)
+
+X_train=a[:19]
+X_test=a[19:]
+y_train=b[:19]
+y_test=b[19:]
+
+model=Pipeline([('poly', PolynomialFeatures(degree=3)),('linear', LinearRegression(fit_intercept=False))])
+model=model.fit(X_train, y_train)
+pred=model.predict(X_test)
+
+
+poly=PolynomialFeatures(degree=3)
+poly.fit_transform(X_train, y_train)
+plt.scatter(X_test, y_test)
+plt.plot(X_test, pred, color='green')
+plt.show()
+
+print (model.score(X_test,y_test))
+
+print ("---------K-Nearest Neighbors-------")
+"""neighbors_settings=range(1,11)
+for n_neighbors in neighbors_settings:
+ clf=KNeighborsClassifier(n_neighbors=n_neighbors)
+ clf.fit(X_train, y_train)
+ training_accuracy.append(clf.score(X_train, y_train))
+ test_accuracy.append(clf.score(X_test, y_test))
+
+
+print (mglearn.plots.plot_knn_regression(n_neighbors=3))"""
+
+from sklearn.neighbors import KNeighborsRegressor
+
+X, y=mglearn.datasets.make_wave(n_samples=40)
+reg = KNeighborsRegressor(n_neighbors=3)
+reg.fit(X_train, y_train)
+!ec
+
+!split
+===== Decision trees and Regression =====
+!bc pycod
+import numpy as np
+import matplotlib.pyplot as plt
+from sklearn.preprocessing import PolynomialFeatures
+from sklearn.linear_model import LinearRegression
+
+steps=250
+
+distance=0
+x=0
+distance_list=[]
+steps_list=[]
+while x