Una Red Neuronal Artificial (ANN) modela la relación entre un conjunto de entradas y una salida, resolviendo un problema de aprendizaje.
Ejemplos prácticos de aplicación de Redes Neuronales son:
La recomendación de contenido de Netflix El feed de Instagram o Tik Tok *Determinar el número o letra escrito a mano
#install.packages("neuralnet")
#install.packages("caret")
library(neuralnet)
library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(readr)
library(ggplot2)
examen<-c(20,10,30,20,80,30)
proyecto<-c(90,20,40,50,50,80)
estatus<-c(1,0,0,0,0,1)
df<-data.frame(examen,proyecto,estatus)
red_neuronal<-neuralnet(estatus~., data = df)
plot(red_neuronal, rep="best")
# Predecir con la Red Neuronal
prueba_examen<-c(20,40,85)
prueba_proyecto<-c(85,40,50)
prueba<-data.frame(prueba_examen,prueba_proyecto)
prediccion<-compute(red_neuronal,prueba)
prediccion$net.result
## [,1]
## [1,] 0.3339816
## [2,] 0.3339816
## [3,] 0.3339816
probabilidad<- prediccion$net.result
resultado<-ifelse(probabilidad>0.5,1,0)
resultado
## [,1]
## [1,] 0
## [2,] 0
## [3,] 0
df1 <- read_csv("cancer_de_mama.csv")
## Rows: 569 Columns: 31
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): diagnosis
## dbl (30): radius_mean, texture_mean, perimeter_mean, area_mean, smoothness_m...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
set.seed(123)
renglones_entrenamiento <- createDataPartition(df1$diagnosis,p=0.8, list=FALSE)
entrenamiento <- df1[renglones_entrenamiento,]
prueba <- df1[-renglones_entrenamiento,]
df1$diagnosis <- ifelse(df1$diagnosis=="M",1,0)
red_neuronal <- neuralnet(diagnosis~., data=df1)
plot(red_neuronal, rep = "best")
prediccion <- compute(red_neuronal, prueba)
prediccion$net.result
## [,1]
## [1,] 0.3725861
## [2,] 0.3725861
## [3,] 0.3725861
## [4,] 0.3725861
## [5,] 0.3725861
## [6,] 0.3725861
## [7,] 0.3725861
## [8,] 0.3725861
## [9,] 0.3725861
## [10,] 0.3725861
## [11,] 0.3725861
## [12,] 0.3725861
## [13,] 0.3725861
## [14,] 0.3725861
## [15,] 0.3725861
## [16,] 0.3725861
## [17,] 0.3725861
## [18,] 0.3725861
## [19,] 0.3725861
## [20,] 0.3725861
## [21,] 0.3725861
## [22,] 0.3725861
## [23,] 0.3725861
## [24,] 0.3725861
## [25,] 0.3725861
## [26,] 0.3725861
## [27,] 0.3725861
## [28,] 0.3725861
## [29,] 0.3725861
## [30,] 0.3725861
## [31,] 0.3725861
## [32,] 0.3725861
## [33,] 0.3725861
## [34,] 0.3725861
## [35,] 0.3725861
## [36,] 0.3725861
## [37,] 0.3725861
## [38,] 0.3725861
## [39,] 0.3725861
## [40,] 0.3725861
## [41,] 0.3725861
## [42,] 0.3725861
## [43,] 0.3725861
## [44,] 0.3725861
## [45,] 0.3725861
## [46,] 0.3725861
## [47,] 0.3725861
## [48,] 0.3725861
## [49,] 0.3725861
## [50,] 0.3725861
## [51,] 0.3725861
## [52,] 0.3725861
## [53,] 0.3725861
## [54,] 0.3725861
## [55,] 0.3725861
## [56,] 0.3725861
## [57,] 0.3725861
## [58,] 0.3725861
## [59,] 0.3725861
## [60,] 0.3725861
## [61,] 0.3725861
## [62,] 0.3725861
## [63,] 0.3725861
## [64,] 0.3725861
## [65,] 0.3725861
## [66,] 0.3725861
## [67,] 0.3725861
## [68,] 0.3725861
## [69,] 0.3725861
## [70,] 0.3725861
## [71,] 0.3725861
## [72,] 0.3725861
## [73,] 0.3725861
## [74,] 0.3725861
## [75,] 0.3725861
## [76,] 0.3725861
## [77,] 0.3725861
## [78,] 0.3725861
## [79,] 0.3725861
## [80,] 0.3725861
## [81,] 0.3725861
## [82,] 0.3725861
## [83,] 0.3725861
## [84,] 0.3725861
## [85,] 0.3725861
## [86,] 0.3725861
## [87,] 0.3725861
## [88,] 0.3725861
## [89,] 0.3725861
## [90,] 0.3725861
## [91,] 0.3725861
## [92,] 0.3725861
## [93,] 0.3725861
## [94,] 0.3725861
## [95,] 0.3725861
## [96,] 0.3725861
## [97,] 0.3725861
## [98,] 0.3725861
## [99,] 0.3725861
## [100,] 0.3725861
## [101,] 0.3725861
## [102,] 0.3725861
## [103,] 0.3725861
## [104,] 0.3725861
## [105,] 0.3725861
## [106,] 0.3725861
## [107,] 0.3725861
## [108,] 0.3725861
## [109,] 0.3725861
## [110,] 0.3725861
## [111,] 0.3725861
## [112,] 0.3725861
## [113,] 0.3725861
probabilidad <- prediccion$net.result
resultado <- ifelse(probabilidad>0.5,1,0)
resultado
## [,1]
## [1,] 0
## [2,] 0
## [3,] 0
## [4,] 0
## [5,] 0
## [6,] 0
## [7,] 0
## [8,] 0
## [9,] 0
## [10,] 0
## [11,] 0
## [12,] 0
## [13,] 0
## [14,] 0
## [15,] 0
## [16,] 0
## [17,] 0
## [18,] 0
## [19,] 0
## [20,] 0
## [21,] 0
## [22,] 0
## [23,] 0
## [24,] 0
## [25,] 0
## [26,] 0
## [27,] 0
## [28,] 0
## [29,] 0
## [30,] 0
## [31,] 0
## [32,] 0
## [33,] 0
## [34,] 0
## [35,] 0
## [36,] 0
## [37,] 0
## [38,] 0
## [39,] 0
## [40,] 0
## [41,] 0
## [42,] 0
## [43,] 0
## [44,] 0
## [45,] 0
## [46,] 0
## [47,] 0
## [48,] 0
## [49,] 0
## [50,] 0
## [51,] 0
## [52,] 0
## [53,] 0
## [54,] 0
## [55,] 0
## [56,] 0
## [57,] 0
## [58,] 0
## [59,] 0
## [60,] 0
## [61,] 0
## [62,] 0
## [63,] 0
## [64,] 0
## [65,] 0
## [66,] 0
## [67,] 0
## [68,] 0
## [69,] 0
## [70,] 0
## [71,] 0
## [72,] 0
## [73,] 0
## [74,] 0
## [75,] 0
## [76,] 0
## [77,] 0
## [78,] 0
## [79,] 0
## [80,] 0
## [81,] 0
## [82,] 0
## [83,] 0
## [84,] 0
## [85,] 0
## [86,] 0
## [87,] 0
## [88,] 0
## [89,] 0
## [90,] 0
## [91,] 0
## [92,] 0
## [93,] 0
## [94,] 0
## [95,] 0
## [96,] 0
## [97,] 0
## [98,] 0
## [99,] 0
## [100,] 0
## [101,] 0
## [102,] 0
## [103,] 0
## [104,] 0
## [105,] 0
## [106,] 0
## [107,] 0
## [108,] 0
## [109,] 0
## [110,] 0
## [111,] 0
## [112,] 0
## [113,] 0