14.3 Neural Networks
14.3 Neural Networks
Ans:
> library(neuralnet)
> library(NeuralNetTools)
> library(nnet)
> library(caret)
> library(corrplot)
> library(GGally)
> 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 ...
> summary(concrete)
cement slag ash water superplastic coarseagg
Min. :102.0 Min. : 0.0 Min. : 0.00 Min. :121.8 Min. : 0.000 Min. : 801.0
1st Qu.:192.4 1st Qu.: 0.0 1st Qu.: 0.00 1st Qu.:164.9 1st Qu.: 0.000 1st Qu.: 932.0
Median :272.9 Median : 22.0 Median : 0.00 Median :185.0 Median : 6.400 Median : 968.0
Mean :281.2 Mean : 73.9 Mean : 54.19 Mean :181.6 Mean : 6.205 Mean : 972.9
3rd Qu.:350.0 3rd Qu.:142.9 3rd Qu.:118.30 3rd Qu.:192.0 3rd Qu.:10.200 3rd Qu.:1029.4
Max. :540.0 Max. :359.4 Max. :200.10 Max. :247.0 Max. :32.200 Max. :1145.0
fineagg age strength
Min. :594.0 Min. : 1.00 Min. : 2.33
1st Qu.:731.0 1st Qu.: 7.00 1st Qu.:23.71
Median :779.5 Median : 28.00 Median :34.45
Mean :773.6 Mean : 45.66 Mean :35.82
3rd Qu.:824.0 3rd Qu.: 56.00 3rd Qu.:46.13
Max. :992.6 Max. :365.00 Max. :82.60
> attach(concrete)
Normalising function
Normalising df
> norm_concrete <- as.data.frame(lapply(concrete,normm))
> head(norm_concrete)
cement slag ash water superplastic coarseagg fineagg
1 0.08972603 0.5898720 0.0000000 0.6525559 0.0000000 0.4965116 0.3876066
2 0.15273973 0.1174179 0.6211894 0.2915335 0.3354037 0.8133721 0.5072755
3 0.33789954 0.0000000 0.4782609 0.5239617 0.1708075 0.4531977 0.6703462
4 0.37442922 0.3171953 0.0000000 0.8482428 0.0000000 0.3808140 0.1906673
5 0.12054795 0.5102949 0.0000000 0.5710863 0.2826087 0.7162791 0.2576518
6 0.34931507 0.0000000 0.0000000 0.5607029 0.0000000 0.2581395 0.8805820
age strength
1 0.07417582 0.3433412
2 0.03571429 0.2638595
3 0.07417582 0.3349944
4 0.07417582 0.5421702
5 0.07417582 0.1988290
6 0.24450549 0.2433038
Model building
> plot(model_con)
> pred_model_con <-compute(model_con,tst_c)
> predict_con <- pred_model_con$net.result
> cor(predict_con,tst_c$strength)
[,1]
[1,] 0.8219754
SSE is more with less acc
> plotnet(model_con,cex=0.8)
> plot(model2_con)
> predict_model2 <- compute(model2_con,tst_c)
> predict_con2 <- predict_model2$net.result
> cor(predict_con2,tst_c$strength)
[,1]
[1,] 0.9383941
SSE has decreased
> plotnet(model2_con,cex=0.8)