![R Deep Learning Cookbook](https://img.perlego.com/book-covers/526940/9781787127111_300_450.webp)
R Deep Learning Cookbook
Dr. PKS Prakash, Achyutuni Sri Krishna Rao
- 288 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
R Deep Learning Cookbook
Dr. PKS Prakash, Achyutuni Sri Krishna Rao
About This Book
Powerful, independent recipes to build deep learning models in different application areas using R librariesAbout This Book• Master intricacies of R deep learning packages such as mxnet & tensorflow• Learn application on deep learning in different domains using practical examples from text, image and speech• Guide to set-up deep learning models using CPU and GPUWho This Book Is ForData science professionals or analysts who have performed machine learning tasks and now want to explore deep learning and want a quick reference that could address the pain points while implementing deep learning. Those who wish to have an edge over other deep learning professionals will find this book quite useful.What You Will Learn• Build deep learning models in different application areas using TensorFlow, H2O, and MXnet.• Analyzing a Deep boltzmann machine• Setting up and Analysing Deep belief networks• Building supervised model using various machine learning algorithms• Set up variants of basic convolution function• Represent data using Autoencoders.• Explore generative models available in Deep Learning.• Discover sequence modeling using Recurrent nets• Learn fundamentals of Reinforcement Leaning• Learn the steps involved in applying Deep Learning in text mining• Explore application of deep learning in signal processing• Utilize Transfer learning for utilizing pre-trained model• Train a deep learning model on a GPUIn DetailDeep Learning is the next big thing. It is a part of machine learning. It's favorable results in applications with huge and complex data is remarkable. Simultaneously, R programming language is very popular amongst the data miners and statisticians.This book will help you to get through the problems that you face during the execution of different tasks and Understand hacks in deep learning, neural networks, and advanced machine learning techniques. It will also take you through complex deep learning algorithms and various deep learning packages and libraries in R. It will be starting with different packages in Deep Learning to neural networks and structures. You will also encounter the applications in text mining and processing along with a comparison between CPU and GPU performance.By the end of the book, you will have a logical understanding of Deep learning and different deep learning packages to have the most appropriate solutions for your problems.Style and approachCollection of hands-on recipes that would act as your all-time reference for your deep learning needs
Frequently asked questions
Information
Generative Models in Deep Learning
- Comparing principal component analysis with the Restricted Boltzmann machine
- Setting up a Restricted Boltzmann machine for Bernoulli distribution input
- Training a Restricted Boltzmann machine
- Backward or reconstruction phase of RBM
- Understanding the contrastive divergence of the reconstruction
- Initializing and starting a new TensorFlow session
- Evaluating the output from an RBM
- Setting up a Restricted Boltzmann machine for Collaborative Filtering
- Performing a full run of training an RBM
- Setting up a Deep Belief Network
- Implementing a feed-forward backpropagation Neural Network
- Setting up a Deep Restricted Boltzmann Machine
Comparing principal component analysis with the Restricted Boltzmann machine
![](https://book-extracts.perlego.com/526940/images/2e997643-a4eb-46ba-8c23-74cba5f8fbcf-plgo-compressed.webp)
![](https://book-extracts.perlego.com/526940/images/816336b5-03d0-4c8b-82b7-b63d74ec9939-plgo-compressed.webp)
Getting ready
library(tensorflow)
datasets <- tf$contrib$learn$datasets
mnist <- datasets$mnist$read_data_sets("MNIST-data", one_hot = TRUE)
How to do it...
- Extract the train dataset (trainX with all 784 independent variables and trainY with the respective 10 binary outputs):
trainX <- mnist$train$images
trainY <- mnist$train$labels
- Run a PCA on the trainX data:
PCA_model <- prcomp(trainX, retx=TRUE)
- Run an RBM on the trainX data:
RBM_model <- rbm(trainX, retx=TRUE, max_epoch=500,num_hidden =900)
- Predict on the train data using the generated models. In the case of the RBM model, generate probabilities:
PCA_pred_train <- predict(PCA_model)
RBM_pred_train <- predict(RBM_model,type='probs')
- Convert the outcomes into data frames:
PCA_pred_train <- as.data.frame(PCA_pred_train)
class="MsoSubtleEmphasis">RBM_pred_train <- as.data.frame(as.matrix(RBM_pred_train))
- Convert the 10-class binary trainY data frame into a numeric vector:
trainY_num<- as.numeric(stringi::stri_sub(colnames(as.data.frame(trainY))[max.col(as.data.frame(trainY),ties.method="first")],2))
- Plot the components generated using PCA. Here, the x-axis represents component 1 and the y-axis represents component 2. The following image shows the outcome of the PCA model:
ggplot(PCA_pred_train, aes(PC1, PC2))+
geom_point(aes(colour = trainY))+
theme_bw()+labs()+
theme(plot.title = element_text(hjust = 0.5))
![](assets/0b286c98-d0f9-4078-a908-25ff12a22c2a-plgo-compressed.webp)
- Plot the hidden layers generated using PCA. Here, the x-axis represents hidden 1 and y-axis represents hidden 2. The following image shows the outcome of the RBM model:
ggplot(RBM_pred_train, aes(Hidden_2, Hidden_3))+
geom_point(aes(colour = trainY))+
theme_bw()+labs()+
theme(plot.title = element_text(hjust = 0.5))
![](assets/e9ce16e0-7c49-457f-858b-cc4d0781c326-plgo-compressed.webp)
var_explain <- as.data.frame(PCA_model$sdev^2/sum(PCA_model$sdev^2))
var_explain <- cbind(c(1:784),var_explain,cumsum(var_explain[,1]))
colnames(var_explain) <- c("PcompNo.","Ind_Variance","Cum_Variance")
plot(var_explain$PcompNo.,var_explain$Cum_Variance, xlim = c(0,100),type='b',pch=16,xlab = "# of Principal Components",ylab = "Cumulative Variance",main = 'PCA - Explained variance')
![](assets/ec3a2a56-1334-4080-873d-855f8059e949-plgo-compressed.webp)
plot(RBM_model,xlab = "# of epoch iterations",ylab = "Reconstruction error",main = 'RBM - Reconstruction Error')
![](assets/b2bd391e-606d-44c1-84b4-d129dd4de946-plgo-compressed.webp)