-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhormigón_example.R
More file actions
85 lines (52 loc) · 2.01 KB
/
hormigón_example.R
File metadata and controls
85 lines (52 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#########################
# Implementando #
# Redes Neuronales en R #
#########################
# MLP - REGRESSION #
#####################
#install.packages("readxl")
require(caret)
require(neuralnet)
require(readxl)
con = read_xls("Concrete_Data.xls")
head(con)
colnames(con) = c("cement", "slag", "ash", "water", "superplastic", "coarseagg", "fineagg", "age", "strength")
typeof(con)
con = as.data.frame(con)
typeof(con)
head(con)
# normalizar todas las variables
# todos los valores están entre 0 y 1
# función de normalización estándar
normal = function(x){
return((x-min(x))/(max(x)-min(x)))}
# aplique la función normal a cada columna
con_norm = as.data.frame(lapply(con, normal))
head(con_norm)
# preproceso
#caret para preprocesamiento
trainIndex = createDataPartition(con$strength,p = .75, list = F)
train_set = con[trainIndex,]
test_set = con[-trainIndex,]
#RNA simple con una sola neurona oculta
concrete_model <- neuralnet(formula = strength ~ cement + slag + ash +
water + superplastic + coarseagg + fineagg + age,
data = train_set)
plot(concrete_model)
con_r = compute(concrete_model, test_set[1:8])
#implementar nn en el conjunto de pruebas
predicted_strength = con_r$net.result
srmse = sqrt(mean((predicted_strength - test_set$strength)^2))
## MEJORA EL MODELO
## agrega más neuronas, no más capas
# RNA simple con solo 5 neuronas ocultas
# más neuronas se ajustan mejor a datos complejos y no lineales,
#pero no a una gran cantidad de neuronas
concrete_model2 = neuralnet(formula = strength ~ cement + slag + ash +
water + superplastic + coarseagg + fineagg + age,
data = train_set, hidden = 5)
plot(concrete_model2)
con_r2 = compute(concrete_model2, test_set[1:8])
predicted_strength2 = con_r2$net.result
srmse2 = sqrt(mean((predicted_strength2 - test_set$strength)^2))
#no se produce mejoras.