<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/r-code-to-accompany-real-world-machine-learning-chapter-4/"></div></div><div><a data-url="https://www.r-bloggers.com/r-code-to-accompany-real-world-machine-learning-chapter-4/" data-counturl="https://www.r-bloggers.com/r-code-to-accompany-real-world-machine-learning-chapter-4/" data-count="horizontal" data-text="R code to accompany Real-World Machine Learning (Chapter 4)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://feedproxy.google.com/~r/DataProne-R/~3/f8bwC6Avhlg/real-world-machine-learning-with-R-chapter-4.html"> data prone - R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Abstract</h2>
<p>In the latest update to the rwml-R Github repo, I provide R code to accompany Chapter 4 of the book “Real-World Machine Learning” by Henrik Brink, Joseph W. Richards, and Mark Fetherolf. Topics covered include optimization of model parameters via grid search with <code>caret</code>, plotting a confusion matrix with <code>ggplot2</code>, and generating ROC curves with <code>ROCR</code>. This blog post provides a summary and some examples of the code contained in the update.</p>
<h2>rwml-R project pages posted</h2>
<p>For convenience, I’ve created a <a target="_blank" rel="nofollow" href="https://padamson.github.io/rwml-R/">project page for rwml-R</a> to post<br>
the generated HTML files<br>
from <code>knitr</code>. This (and <a target="_blank" rel="nofollow" href="http://padamson.github.io/r/machine%20learning/ggplot2/dplyr/tidyr/2016/10/01/real-world-machine-learning-with-R-intro.html">Chapter 2</a> and <a target="_blank" rel="nofollow" href="http://padamson.github.io/r/ggplot2/dplyr/caret/2016/10/15/real-world-machine-learning-with-R-chapter-3.html">Chapter 3</a>) blog posts<br>
are short<br>
summaries of the R code provided in the <a target="_blank" rel="nofollow" href="https://padamson.github.io/rwml-R/">rwml-R</a> project.<br>
Also, feel free to <a target="_blank" rel="nofollow" href="https://github.com/padamson/rwml-R/fork">fork the rwml-R repo</a><br>
and submit a pull request if you wish to contribute.</p>
<h2>Plotting a confusion matrix</h2>
<p>The MNIST dataset of handwritten digits makes another appearance.<br>
The <code>kknn</code> package is again used, and the confusion matrix is plotted<br>
using <code>ggplot2</code>. The color scale for the plot is generated using<br>
the <code>RColorBrewer</code> package.</p>
<p></p>
<p><img alt="Figure generated by above code" src="https://i2.wp.com/padamson.github.io/assets/figure4_19.png?w=456" data-recalc-dims="1"></p>
<h2>Plotting a series of ROC curves</h2>
<p>The <code>ROCR</code> package is introduced and used to generate ROC curves.<br>
Also, AUC values are calculated for each curve and displayed along with<br>
each of the curves.</p>
<p></p>
<p><img alt="Figure generated by above code" src="https://i0.wp.com/padamson.github.io/assets/figure4_20.png?w=456" data-recalc-dims="1"></p>
<h2>Tuning model parameters</h2>
<p>The <a target="_blank" rel="nofollow" href="http://topepo.github.io/caret/"><code>caret</code></a> package is used to tune parameters via grid search<br>
for the Support Vector Machines model with a Radial Basis Function Kernel.<br>
By setting <code>summaryFunction = twoClassSummary</code><br>
in <code>trainControl</code>, the <code>ROC</code> curve is used to select the optimal<br>
model. The <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/doMC/index.html"><code>doMC</code></a> package is also introduced for parallel computation.</p>
<h2>Feedback welcome</h2>
<p>If you have any feedback on the <a target="_blank" rel="nofollow" href="https://padamson.github.io/rwml-R/">rwml-R</a> project, please<br>
leave a comment below or use the Tweet button.<br>
Again, feel free to <a target="_blank" rel="nofollow" href="https://github.com/padamson/rwml-R/fork">fork the rwml-R repo</a><br>
and submit a pull request if you wish to contribute.</p>
<p><a data-style="mega" target="_blank" rel="nofollow" href="https://github.com/padamson/rwml-R/archive/master.zip" data-icon="octicon-cloud-download">Download</a><br>
<a data-style="mega" data-count-href="http://feedproxy.google.com/padamson/rwml-R/network" data-count-aria-label="# forks on GitHub" target="_blank" data-count-api="/repos/padamson/rwml-R#forks_count" rel="nofollow" href="https://github.com/padamson/rwml-R/fork" data-icon="octicon-repo-forked">Fork</a></p>
<p><img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/DataProne-R/~4/f8bwC6Avhlg"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/r-code-to-accompany-real-world-machine-learning-chapter-4/"></div></div><div><a data-url="https://www.r-bloggers.com/r-code-to-accompany-real-world-machine-learning-chapter-4/" data-counturl="https://www.r-bloggers.com/r-code-to-accompany-real-world-machine-learning-chapter-4/" data-count="vertical" data-text="R code to accompany Real-World Machine Learning (Chapter 4)" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://feedproxy.google.com/~r/DataProne-R/~3/f8bwC6Avhlg/real-world-machine-learning-with-R-chapter-4.html"> data prone - R</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/YNnT3-kk-CM"></a></div>