Professional Documents
Culture Documents
Codigo
Codigo
library(ggthemes)
library(ggpubr)
#modelado
#===============================================
#
#sudo apt install default-jre
library(h2o)
# Datos simulados
# ==============================================================================
datos = read_csv('https://raw.githubusercontent.com/JoaquinAmatRodrigo/Estadistica-
machine-learning-python/master/data/blobs.csv')
# Modelos
# ==============================================================================
modelo_1 <- h2o.deeplearning(
x = c("x_1", "x_2"),
y = "y",
distribution = "multinomial",
training_frame = datos_train,
standardize = TRUE,
activation = "Rectifier",
adaptive_rate = FALSE,
hidden = 1,
stopping_rounds = 0,
epochs = 1000,
seed = 123,
model_id = "modelo_1"
)
# Gráfico de predicciones
# ==============================================================================
p1 <- ggplot(data = grid_predicciones, aes(x = x_1, y = x_2, color = modelo_1)) +
geom_point(size = 0.5) +
theme_fivethirtyeight() +
labs(title = "Arquitectura: (5)") +
theme(legend.position = "none",
plot.title = element_text(size=11),
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank())
# Número de neuronas
# ==============================================================================
hiperparametros <- list(hidden = c(1, 5, 10, 15, 25, 50, 100, 300, 500))
data.frame(resultados_grid@summary_table) %>%
mutate(
accuracy = as.numeric(accuracy),
hidden = str_remove_all(hidden, pattern = "\\[|\\]"),
hidden = as.numeric(hidden),
) %>%
ggplot(aes(x=hidden, y=accuracy, group=1)) +
geom_line() +
geom_point() +
labs(title="Accuracy del modelo vs número de neuronas") +
theme_bw()
# Learning rate
# ==============================================================================
hiperparametros <- list(rate = c(0.00001, 0.0001, 0.0001, 0.001, 0.01, 0.1, 1, 10))