#install.packages("neuralnet")
#install.packages("caret")
library(neuralnet)
library(caret)
## Cargando paquete requerido: ggplot2
## Cargando paquete requerido: lattice
#Crear el Df directo del csv
df <- read.csv("C:\\Carpeta de R\\DBs\\cancer_de_mama.csv")
df$diagnosis <- ifelse(df$diagnosis == "M",1,0)
# Ver las primeras 10 filas del df
head(df, 10)
## diagnosis radius_mean texture_mean perimeter_mean area_mean smoothness_mean
## 1 1 17.99 10.38 122.80 1001.0 0.11840
## 2 1 20.57 17.77 132.90 1326.0 0.08474
## 3 1 19.69 21.25 130.00 1203.0 0.10960
## 4 1 11.42 20.38 77.58 386.1 0.14250
## 5 1 20.29 14.34 135.10 1297.0 0.10030
## 6 1 12.45 15.70 82.57 477.1 0.12780
## 7 1 18.25 19.98 119.60 1040.0 0.09463
## 8 1 13.71 20.83 90.20 577.9 0.11890
## 9 1 13.00 21.82 87.50 519.8 0.12730
## 10 1 12.46 24.04 83.97 475.9 0.11860
## compactness_mean concavity_mean concave_points_mean symmetry_mean
## 1 0.27760 0.30010 0.14710 0.2419
## 2 0.07864 0.08690 0.07017 0.1812
## 3 0.15990 0.19740 0.12790 0.2069
## 4 0.28390 0.24140 0.10520 0.2597
## 5 0.13280 0.19800 0.10430 0.1809
## 6 0.17000 0.15780 0.08089 0.2087
## 7 0.10900 0.11270 0.07400 0.1794
## 8 0.16450 0.09366 0.05985 0.2196
## 9 0.19320 0.18590 0.09353 0.2350
## 10 0.23960 0.22730 0.08543 0.2030
## fractal_dimension_mean radius_se texture_se perimeter_se area_se
## 1 0.07871 1.0950 0.9053 8.589 153.40
## 2 0.05667 0.5435 0.7339 3.398 74.08
## 3 0.05999 0.7456 0.7869 4.585 94.03
## 4 0.09744 0.4956 1.1560 3.445 27.23
## 5 0.05883 0.7572 0.7813 5.438 94.44
## 6 0.07613 0.3345 0.8902 2.217 27.19
## 7 0.05742 0.4467 0.7732 3.180 53.91
## 8 0.07451 0.5835 1.3770 3.856 50.96
## 9 0.07389 0.3063 1.0020 2.406 24.32
## 10 0.08243 0.2976 1.5990 2.039 23.94
## smoothness_se compactness_se concavity_se concave_points_se symmetry_se
## 1 0.006399 0.04904 0.05373 0.01587 0.03003
## 2 0.005225 0.01308 0.01860 0.01340 0.01389
## 3 0.006150 0.04006 0.03832 0.02058 0.02250
## 4 0.009110 0.07458 0.05661 0.01867 0.05963
## 5 0.011490 0.02461 0.05688 0.01885 0.01756
## 6 0.007510 0.03345 0.03672 0.01137 0.02165
## 7 0.004314 0.01382 0.02254 0.01039 0.01369
## 8 0.008805 0.03029 0.02488 0.01448 0.01486
## 9 0.005731 0.03502 0.03553 0.01226 0.02143
## 10 0.007149 0.07217 0.07743 0.01432 0.01789
## fractal_dimension_se radius_worst texture_worst perimeter_worst area_worst
## 1 0.006193 25.38 17.33 184.60 2019.0
## 2 0.003532 24.99 23.41 158.80 1956.0
## 3 0.004571 23.57 25.53 152.50 1709.0
## 4 0.009208 14.91 26.50 98.87 567.7
## 5 0.005115 22.54 16.67 152.20 1575.0
## 6 0.005082 15.47 23.75 103.40 741.6
## 7 0.002179 22.88 27.66 153.20 1606.0
## 8 0.005412 17.06 28.14 110.60 897.0
## 9 0.003749 15.49 30.73 106.20 739.3
## 10 0.010080 15.09 40.68 97.65 711.4
## smoothness_worst compactness_worst concavity_worst concave_points_worst
## 1 0.1622 0.6656 0.7119 0.2654
## 2 0.1238 0.1866 0.2416 0.1860
## 3 0.1444 0.4245 0.4504 0.2430
## 4 0.2098 0.8663 0.6869 0.2575
## 5 0.1374 0.2050 0.4000 0.1625
## 6 0.1791 0.5249 0.5355 0.1741
## 7 0.1442 0.2576 0.3784 0.1932
## 8 0.1654 0.3682 0.2678 0.1556
## 9 0.1703 0.5401 0.5390 0.2060
## 10 0.1853 1.0580 1.1050 0.2210
## symmetry_worst fractal_dimension_worst
## 1 0.4601 0.11890
## 2 0.2750 0.08902
## 3 0.3613 0.08758
## 4 0.6638 0.17300
## 5 0.2364 0.07678
## 6 0.3985 0.12440
## 7 0.3063 0.08368
## 8 0.3196 0.11510
## 9 0.4378 0.10720
## 10 0.4366 0.20750
set.seed(123)
renglones_entrenamiento <- createDataPartition(df$diagnosis,p=0.8, list = FALSE)
entrenamiento <- df[renglones_entrenamiento,]
prueba <- df[-renglones_entrenamiento,]
red_neuronal <- neuralnet(diagnosis~., data=entrenamiento)
plot(red_neuronal, rep = "best")
CÓDIGO
prediccion <- compute(red_neuronal, prueba)
prediccion\(net.result<br>
probabilidad <- prediccion\)net.result
resultado <-
ifelse(probabilidad>0.5,1,0)
df_resultado <- data.frame(PROBABILIDAD_TUMOR = probabilidad, RESULTADO_TUMOR = resultado)
print(df_resultado)
## PROBABILIDAD_TUMOR RESULTADO_TUMOR
## 1 0.3486923 0
## 9 0.3486923 0
## 15 0.3486923 0
## 17 0.3486923 0
## 18 0.3486923 0
## 28 0.3486923 0
## 35 0.3486923 0
## 44 0.3486923 0
## 46 0.3486923 0
## 56 0.3486923 0
## 58 0.3486923 0
## 60 0.3486923 0
## 65 0.3486923 0
## 68 0.3486923 0
## 71 0.3486923 0
## 79 0.3486923 0
## 82 0.3486923 0
## 86 0.3486923 0
## 95 0.3486923 0
## 99 0.3486923 0
## 101 0.3486923 0
## 109 0.3486923 0
## 124 0.3486923 0
## 133 0.3486923 0
## 138 0.3486923 0
## 140 0.3486923 0
## 142 0.3486923 0
## 157 0.3486923 0
## 162 0.3486923 0
## 171 0.3486923 0
## 173 0.3486923 0
## 183 0.3486923 0
## 188 0.3486923 0
## 189 0.3486923 0
## 193 0.3486923 0
## 201 0.3486923 0
## 203 0.3486923 0
## 206 0.3486923 0
## 207 0.3486923 0
## 216 0.3486923 0
## 220 0.3486923 0
## 227 0.3486923 0
## 233 0.3486923 0
## 240 0.3486923 0
## 242 0.3486923 0
## 247 0.3486923 0
## 251 0.3486923 0
## 256 0.3486923 0
## 259 0.3486923 0
## 261 0.3486923 0
## 262 0.3486923 0
## 275 0.3486923 0
## 284 0.3486923 0
## 293 0.3486923 0
## 296 0.3486923 0
## 303 0.3486923 0
## 305 0.3486923 0
## 317 0.3486923 0
## 318 0.3486923 0
## 320 0.3486923 0
## 323 0.3486923 0
## 329 0.3486923 0
## 332 0.3486923 0
## 340 0.3486923 0
## 341 0.3486923 0
## 352 0.3486923 0
## 354 0.3486923 0
## 358 0.3486923 0
## 359 0.3486923 0
## 369 0.3486923 0
## 370 0.3486923 0
## 371 0.3486923 0
## 375 0.3486923 0
## 386 0.3486923 0
## 387 0.3486923 0
## 394 0.3486923 0
## 400 0.3486923 0
## 405 0.3486923 0
## 407 0.3486923 0
## 412 0.3486923 0
## 417 0.3486923 0
## 418 0.3486923 0
## 429 0.3486923 0
## 432 0.3486923 0
## 434 0.3486923 0
## 437 0.3486923 0
## 453 0.3486923 0
## 454 0.3486923 0
## 466 0.3486923 0
## 481 0.3486923 0
## 484 0.3486923 0
## 487 0.3486923 0
## 492 0.3486923 0
## 510 0.3486923 0
## 515 0.3486923 0
## 518 0.3486923 0
## 520 0.3486923 0
## 522 0.3486923 0
## 529 0.3486923 0
## 531 0.3486923 0
## 532 0.3486923 0
## 541 0.3486923 0
## 545 0.3486923 0
## 547 0.3486923 0
## 551 0.3486923 0
## 554 0.3486923 0
## 556 0.3486923 0
## 557 0.3486923 0
## 558 0.3486923 0
## 560 0.3486923 0
## 561 0.3486923 0
## 562 0.3486923 0
## 564 0.3486923 0
Las redes neuronales permiten que los programas reconozcan patrones y resuelvan problemas comunes en IA y aprendizaje automático.