Keras for R, MNIST 간단 예제
MNIST Code Show All Code Hide All Code Download Rmd MNIST 데이터 준비 library(keras) mnist<-dataset_mnist() c(x_train,y_train) %<-% mnist$train c(x_test,y_test) %<-% mnist$test NUM_CATEGORY=10 Reshape x_train<-x_train%>%array_reshape(c(nrow(x_train),784)) 원래 데이터는 (images,width,height)의 3차원 데이터이다. images 인덱스만 남기고 width와 height를 flattern시켰다. x_test<-x_test%>%array_reshape(c(nrow(x_test),784)) 마찬가지다. Categorical y_train<-y_train%>% to_categorical(NUM_CATEGORY) y_test<-y_test%>% to_categorical(NUM_CATEGORY) Model model<-keras_model_sequential() 레이어를 쌓자. model%>% layer_dense(256, activation='relu', input_shape=c(784))%>% layer_dropout(0.4)%>% layer_dense(128, activation='relu')%>% layer_dropout(0.3)%>% layer_dense(10,