concrete <- read.csv("/cloud/project/Data/concrete.txt")
#View(sms_raw)
#install.packages("tm") quan trọng cần tìm hiểu
#install.packages("wordcloud")
#install.packages("e1071")
#install.packages("neuralnet") # use in this project
#library("tm")
#library(wordcloud)
#library("dplyr")
#library("e1071")
#library("gmodels")
library("neuralnet")
str(concrete)
## 'data.frame': 1030 obs. of 9 variables:
## $ cement : num 540 540 332 332 199 ...
## $ slag : num 0 0 142 142 132 ...
## $ ash : num 0 0 0 0 0 0 0 0 0 0 ...
## $ water : num 162 162 228 228 192 228 228 228 228 228 ...
## $ superplastic: num 2.5 2.5 0 0 0 0 0 0 0 0 ...
## $ coarseagg : num 1040 1055 932 932 978 ...
## $ fineagg : num 676 676 594 594 826 ...
## $ age : int 28 28 270 365 360 90 365 28 28 28 ...
## $ strength : num 80 61.9 40.3 41 44.3 ...
#View(concrete_norm)
normalize <- function(x) {
return((x - min(x)) / (max(x) - min(x)))
}
concrete_norm <- as.data.frame(lapply(concrete, normalize))
summary(concrete_norm$strength)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.2664 0.4001 0.4172 0.5457 1.0000
plot(concrete_norm$strength)

concrete_train <- concrete_norm[1:773,]
concrete_test <- concrete_norm[778:1030,]
concrete_model <- neuralnet(concrete_train$strength ~. , data = concrete_train)
plot(concrete_model)
knitr::include_graphics("/cloud/project/Data/picture/000004.png")

model_result <- compute(concrete_model, concrete_test[,1:8])
# 2 component in list of model_result lấy cái kết quả thôi
#View(model_result)
typeof(model_result)
## [1] "list"
predict_strengh <- model_result$net.result
str(predict_strengh)
## num [1:253, 1] 0.331 0.182 0.274 0.203 0.169 ...
## - attr(*, "dimnames")=List of 2
## ..$ : chr [1:253] "778" "779" "780" "781" ...
## ..$ : NULL
cor(predict_strengh, concrete_test$strength )
## [,1]
## [1,] 0.7180458
concrete_model2 <- neuralnet(concrete_train$strength ~. , data = concrete_train, hidden = 5 )
plot(concrete_model2)
knitr::include_graphics("/cloud/project/Data/picture/000003.png")

model_result2 <- compute(concrete_model2, concrete_test[,1:8])
# 2 component in list of model_result lấy cái kết quả thôi
#View(model_result)
typeof(model_result2)
## [1] "list"
predict_strengh2 <- model_result2$net.result
str(predict_strengh2)
## num [1:253, 1] 0.336 0.137 0.269 0.198 0.131 ...
## - attr(*, "dimnames")=List of 2
## ..$ : chr [1:253] "778" "779" "780" "781" ...
## ..$ : NULL
cor(predict_strengh2, concrete_test$strength )
## [,1]
## [1,] 0.8085592