-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaperucita_example.R
More file actions
54 lines (35 loc) · 1.66 KB
/
caperucita_example.R
File metadata and controls
54 lines (35 loc) · 1.66 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
# Red Neuranal R ----------------------------------------------------------
#########################
# Implementando #
# Redes Neuronales en R #
#########################
install.packages("NeuralNetTools")
install.packages("neuralnet")
library(neuralnet)
library(NeuralNetTools)
# cualidades y acciones del código
qualities <- matrix (c(1, 1, 1, 0, 0, 0,
0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1), byrow = TRUE, nrow = 3)
colnames(qualities) <- c("big_ears", "big_eyes", "big_teeth", "kindly", "wrinkled", "handsome")
rownames(qualities) <- c("wolf", "grannie", "woodcutter")
qualities
actions <- matrix (c(1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 0,
0, 0, 0, 1, 0, 1, 1), byrow = TRUE, nrow = 3)
colnames(actions) <- c("run_away", "scream", "look_for_woodcutter", "kiss_on_cheek", "approach", "offer_food", "flirt_with")
rownames(actions) <- rownames(qualities)
actions
data <- cbind(qualities, actions)
# Entrenar la neural network (NN)
set.seed(123) # para reproductabilidad
neuralnetwork <- neuralnet(run_away + scream + look_for_woodcutter + kiss_on_cheek + approach +
offer_food + flirt_with ~
big_ears + big_eyes + big_teeth + kindly + wrinkled + handsome,
data = data, hidden = 3, linear.output = FALSE)
# Graficar la NN
par_bkp <- par(mar = c(0, 0, 0, 0)) # establecer un margen diferente para minimizar el texto de cutoff
plotnet(neuralnetwork, bias = FALSE)
par(par_bkp)
# ¿Qué acciones aprendió la red?
round(neuralnetwork$net.result[[1]])