Una Red Neuronal Artificial modela la relación entre un conjunto de entradas y una salidad, resolviendo un problema de aprendizaje.
library(neuralnet)
library(caret)
boston <- read.csv("BostonHousing.csv")
set.seed(123)
renglones_entrenamiento_boston <- createDataPartition(boston$medv,p=0.7,list=FALSE)
entrenamiento_boston <- boston[renglones_entrenamiento_boston, ]
prueba_boston <- boston[-renglones_entrenamiento_boston, ]
modelo_boston <-neuralnet(medv~.,data=entrenamiento_boston)
summary(modelo_boston)
## Length Class Mode
## call 3 -none- call
## response 356 -none- numeric
## covariate 4628 -none- numeric
## model.list 2 -none- list
## err.fct 1 -none- function
## act.fct 1 -none- function
## linear.output 1 -none- logical
## data 14 data.frame list
## exclude 0 -none- NULL
## net.result 1 -none- list
## weights 1 -none- list
## generalized.weights 1 -none- list
## startweights 1 -none- list
## result.matrix 19 -none- numeric
prediccion <- compute(modelo_boston, prueba_boston[, -which(names(prueba_boston) == "medv")])$net.result
real <- prueba_boston$medv
boston_resultados <- data.frame(Real = real, Predicción = prediccion)
ggplot(boston_resultados, aes(x=Real, y= Predicción)) +
geom_point(color="blue") +
geom_abline(slope=1, intercept=0, color="red") +
theme_minimal() +
ggtitle("Predicción vs. Valores Reales")
```