To measure the performance of building materials in the field of engeneering, accurate estimates of those materials can be done using neural network models. Put aside the interaction effects between the components of a process, artificial neural network approach can reliably predict the solidity of a material, given the input ingredients we have in hand. The data used to apply the ANN algorithm can be downloaded from http://http://archive.ics.uci.edu/ml. Details of this approach can be found in the book “Machine Learning with R”, by Brett Lantz.
setwd("C:/bassel/MACHINE LEARNING")
getwd()
## [1] "C:/bassel/MACHINE LEARNING"
concrete<-read.csv("concrete.csv", sep = ",", header = T)
str(concrete)
## 'data.frame': 1030 obs. of 9 variables:
## $ cement : num 141 169 250 266 155 ...
## $ slag : num 212 42.2 0 114 183.4 ...
## $ ash : num 0 124.3 95.7 0 0 ...
## $ water : num 204 158 187 228 193 ...
## $ superplastic: num 0 10.8 5.5 0 9.1 0 0 6.4 0 9 ...
## $ coarseagg : num 972 1081 957 932 1047 ...
## $ fineagg : num 748 796 861 670 697 ...
## $ age : int 28 14 28 28 28 90 7 56 28 28 ...
## $ strength : num 29.9 23.5 29.2 45.9 18.3 ...
normalize <-function(x){
return((x-min(x))/(max(x)-min(x)))
}
concrete_norm <- as.data.frame(lapply(concrete, normalize))
hist(concrete_norm$strength, col = "blue")
summary(concrete_norm$strength)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.2664 0.4001 0.4172 0.5457 1.0000
summary(concrete$strength)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.33 23.71 34.44 35.82 46.14 82.60
library(psych)
pairs.panels(concrete_norm)
concrete_train<-concrete_norm[1:773,]
concrete_test<-concrete_norm[774:1030,]
library(NeuralNetTools)
par(mar = numeric(4), family = 'serif')
plotnet(concrete_model, alpha=0.6)
# Make predictions using the model trained by neuralnet function
model_results<-compute(concrete_model, concrete_test[1:8])
# display the predicted scores of the target variable
predicted_strength<-model_results$net.result
# Correlations between predicted and actual values of target variable
cor(predicted_strength, concrete_test$strength)
## [,1]
## [1,] 0.8064655576
model_results_2<-compute(concrete_model_2, concrete_test[1:8])
predicted_strength_2<-model_results_2$net.result
cor(predicted_strength_2, concrete_test$strength)
## [,1]
## [1,] 0.9342537338