<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/machine-learning-artificial-neural-networks-strength-of-concrete/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://feedproxy.google.com/~r/DataRValue/~3/3qfIL6OB1_c/machine-learning-artificial-neural.html"> Data R Value</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><span><span lang="en">It is important to mention that the present posts series began as a personal way of practicing R programming and machine learning. <span>Subsequently feedback from the community, urged me to continue performing these exercises and sharing them.</span><span> </span></span><span lang="en"><span>The bibliography and corresponding authors are cited at all times and this posts series is a way of honoring and giving them the credit they deserve for their work.</span></span></span><span><br></span><span><span lang="en"><span> </span></span></span><br><span><span lang="en"><span>We will develop an artificial neural network</span></span><span lang="en"><span><span lang="en"><span><span lang="en"><span> example.</span></span></span></span> The example was originally published in </span></span><b><span lang="en"><span><i>“Machine Learning in R” </i>by Brett Lantz, PACKT publishing 2015 (open source community experience destilled).</span></span></b></span><br><span><br></span><br><span><span lang="en"><span><span lang="en"><span><span lang="en"><span>The example we will develop is about predicting the strength of concrete based in the ingredients used to made it.</span></span></span></span></span></span></span></p>
<p><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span>We will carry out the exercise verbatim as published in the aforementioned reference</span></span></span></span></span></span><span lang="en"><span>.</span></span></span></span></span></span>
<p><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span>For more details on the </span></span></span></span></span></span></span></span></span></span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span>model trees and regression trees</span></span> algorithms it is recommended to check the aforementioned reference or </span></span></span></span><span lang="en"><span><span lang="en"><span><span lang="en"><span>any other bibliography of your choice</span></span>.</span></span></span></span></span></span></span></span></span></span></p></span>
<p><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><b>### “Machine Learning in R” by Brett Lantz,<br>### PACKT publishing 2015<br>### (open source community experience destilled)<br>### based on: Yeh IC. “Modeling of Strength of<br>### High Performance Concrete Using Artificial<br>### Neural Networks.” Cement and Concrete Research<br>### 1998; 28:1797-1808.
<p>### Strength of concrete example<br>### relationship between the ingredients used in<br>### concrete and the strength of finished product</p>
<p>### Dataset<br>### Compressive strength of concrete<br>### UCI Machine Learning Data Repository<br>### http://archive.ics.uci.edu/ml</p>
<p>### install an load required packages<br>#install.packages(“neuralnet”)</p></b>
<p>library(neuralnet)</p>
<p><b>### read and explore the data</b><br>concrete &lt;-read.csv(“concrete.csv”)<br>str(concrete)</p>
<p><b>### neural networks work best when the input data<br>### are scaled to a narrow range around zero
<p>### normalize the dataset values<br>normalize &lt;-function(x){<br>  return((x – min(x)) / (max(x) – min(x)) )<br>}</p></b>
<p><b>### apply normalize() to the dataset columns</b><br>concrete_norm &lt;-as.data.frame(lapply(concrete, normalize))</p>
<p><b>### confirm and compare normalization</b><br>summary(concrete_norm$strength)<br>summary(concrete$strength)</p>
<p><b>### split the data into training and testing sets<br>### 75% – 25%</b><br>concrete_train &lt;-concrete_norm[1:773, ]<br>concrete_test &lt;-concrete_norm[774:1030, ]</p>
<p><b>### training model on the data</b><br>concrete_model &lt;-neuralnet(strength ~ cement + slag +<br>              ash + water + superplastic + coarseagg + <br>              fineagg + age, data = concrete_train)<br><b><br>### visualize the network topology</b><br>plot(concrete_model)</p></span>
<div><a target="_blank" rel="nofollow" href="https://i2.wp.com/4.bp.blogspot.com/-s5QUEVpe338/WR3PRHK9KiI/AAAAAAAADDk/VbQAm2MZtWQkMVewNML1bmc7fDlAHlq8QCLcB/s1600/ann_1.png?ssl=1"><img src="https://i2.wp.com/4.bp.blogspot.com/-s5QUEVpe338/WR3PRHK9KiI/AAAAAAAADDk/VbQAm2MZtWQkMVewNML1bmc7fDlAHlq8QCLcB/s400/ann_1.png?resize=400%2C181&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><b>### there is one input node for each of the eight<br>### features, followed by a single hidden node and<br>### a single output node that predicts the concrete<br>### strength<br>### at the bottom of the figure, R reports the number<br>### of training steps and an error measure called the<br>### the sum of squared errors (SSE)
<p>### evaluating model performance</p>
<p>### predictions<br>model_results &lt;-compute(concrete_model, concrete_test[1:8])<br>predicted_strength &lt;-model_results$net.result</p></b>
<p><b>### because this is a numeric prediction problem rather<br>### than a classification problem, we cannot use a confusion<br>### matrix to examine model accuracy<br>### obtain correlation between our predicted concrete strength<br>### and the true value</b><br>cor(predicted_strength, concrete_test$strength)</p>
<p><b>### correlation indicate a strong linear relationships between <br>### two variables
<p>### improving model performance<br>### increase the number of hidden nodes to five<br>concrete_model2 &lt;-neuralnet(strength ~ cement + slag +<br>                 ash + water + superplastic + coarseagg + <br>            fineagg + age, data = concrete_train, hidden = 5)</p></b>
<p>plot(concrete_model2)</p></span>
<p><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<div><a target="_blank" rel="nofollow" href="https://i1.wp.com/3.bp.blogspot.com/-UdEIe0zEtY0/WR3PdBPgdgI/AAAAAAAADDo/dN7NaJrBU-kqHWh2BRa7yUkLQVQbooPMgCLcB/s1600/ann_2.png?ssl=1"><img src="https://i0.wp.com/3.bp.blogspot.com/-UdEIe0zEtY0/WR3PdBPgdgI/AAAAAAAADDo/dN7NaJrBU-kqHWh2BRa7yUkLQVQbooPMgCLcB/s400/ann_2.png?resize=400%2C237&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><br><b>### SSE has been reduced significantly</b>
<p><b>### predictions</b><br>model_results2 &lt;-compute(concrete_model2, concrete_test[1:8])<br>predicted_strength2 &lt;-model_results2$net.result</p>
<p><b>### performance</b><br>cor(predicted_strength, concrete_test$strength)</p>
<p><b>### notice that results can differs because neuralnet<br>### begins with random weights<br>### if you’d like to match results exactly, use set.seed(12345)<br>### before building the neural network </b><br><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><b> </b></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span>You can get the example and the dataset in:</span></span></span></span></span></span><b> </b></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><a target="_blank" rel="nofollow" href="https://github.com/pakinja/Data-R-Value/tree/master/MachineLearning_ANN_ConcreteStrength">https://github.com/pakinja/Data-R-Value</a></p></span>
<p><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><span lang="en"><span><b> </b></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/DataRValue/~4/3qfIL6OB1_c"></p>
<p>
<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/DataRValue/~3/3qfIL6OB1_c/machine-learning-artificial-neural.html"> Data R Value</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/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/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/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/8AgwNe9cWos"></a></div></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>