<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><span lang="en"><span><i>&quot;Machine Learning in R&quot; </i>by Brett Lantz, PACKT publishing 2015 (open source community experience destilled).</span></span></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><br><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>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><br><br><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></span></span></span></span></span></span></span><br><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>### &quot;Machine Learning in R&quot; by Brett Lantz,<br>### PACKT publishing 2015<br>### (open source community experience destilled)<br>### based on: Yeh IC. &quot;Modeling of Strength of<br>### High Performance Concrete Using Artificial<br>### Neural Networks.&quot; Cement and Concrete Research<br>### 1998; 28:1797-1808.<br><br>### Strength of concrete example<br>### relationship between the ingredients used in<br>### concrete and the strength of finished product<br><br>### Dataset<br>### Compressive strength of concrete<br>### UCI Machine Learning Data Repository<br>### http://archive.ics.uci.edu/ml<br><br><br>### install an load required packages<br>#install.packages(&quot;neuralnet&quot;)<br><br>library(neuralnet)<br><br>### read and explore the data<br>concrete &lt;- read.csv(&quot;concrete.csv&quot;)<br>str(concrete)<br><br>### neural networks work best when the input data<br>### are scaled to a narrow range around zero<br><br>### normalize the dataset values<br>normalize &lt;- function(x){<br>  return((x - min(x)) / (max(x) - min(x)) )<br>}<br><br>### apply normalize() to the dataset columns<br>concrete_norm &lt;- as.data.frame(lapply(concrete, normalize))<br><br>### confirm and compare normalization<br>summary(concrete_norm$strength)<br>summary(concrete$strength)<br><br>### split the data into training and testing sets<br>### 75% - 25%<br>concrete_train &lt;- concrete_norm[1:773, ]<br>concrete_test &lt;- concrete_norm[774:1030, ]<br><br>### training model on the data<br>concrete_model &lt;- neuralnet(strength ~ cement + slag +<br>              ash + water + superplastic + coarseagg + <br>              fineagg + age, data = concrete_train)<br><br>### visualize the network topology<br>plot(concrete_model)</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><br><div><a href="https://4.bp.blogspot.com/-s5QUEVpe338/WR3PRHK9KiI/AAAAAAAADDk/VbQAm2MZtWQkMVewNML1bmc7fDlAHlq8QCLcB/s1600/ann_1.png"></a></div><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>### 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)<br><br>### evaluating model performance<br><br>### predictions<br>model_results &lt;- compute(concrete_model, concrete_test[1:8])<br>predicted_strength &lt;- model_results$net.result<br><br>### 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<br>cor(predicted_strength, concrete_test$strength)<br><br>### correlation indicate a strong linear relationships between <br>### two variables<br><br>### 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)<br><br><br>plot(concrete_model2)</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><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></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><div><a href="https://3.bp.blogspot.com/-UdEIe0zEtY0/WR3PdBPgdgI/AAAAAAAADDo/dN7NaJrBU-kqHWh2BRa7yUkLQVQbooPMgCLcB/s1600/ann_2.png"></a></div><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>### SSE has been reduced significantly<br><br>### predictions<br>model_results2 &lt;- compute(concrete_model2, concrete_test[1:8])<br>predicted_strength2 &lt;- model_results2$net.result<br><br>### performance<br>cor(predicted_strength, concrete_test$strength)<br><br>### 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 </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></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> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><a target="_blank" href="https://github.com/pakinja/Data-R-Value/tree/master/MachineLearning_ANN_ConcreteStrength">https://github.com/pakinja/Data-R-Value</a><br><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></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>