Deep Neural Network (DNN) or deep learning for both regression and classification: R code — All you have to do is just preparing data set (very simple, easy and practical)
I release R code of Deep Neural Network (DNN) or deep learning. They are very easy to use. You prepare data set, and just run the code! Then, DNN and prediction results for new samples can be obtained. Very simple and easy!
You can buy each code from the URL below.
Please download the supplemental zip file (this is free) from the URL below to run the DNN code.
Procedure of DNN in the R code
To perform appropriate DNN, the R code follow the procedure below, after data set is loaded.
1. Autoscale explanatory variable (X)
Autoscaling means centering and scaling. Mean of each variable becomes zero by subtracting mean of each variable from the variable in centering. Standard deviation of each variable becomes one by dividing standard deviation of each variable from the variable in scaling.
2. Divide data set into samples for training network and samples for validating the trained network
When the number of components in PLS or C and gamma in SVM is decided, cross-validation is used in a general way. But, it is not used in DNN since it is assumed that the number of samples is enormous in deep learning and it takes amazingly-much time in learning process.
3. Decide candidates of network structure such as the number of layers and the number of units in each layer, (initial) learning rate, factor in updating learning rate, activating function, drop-out rate
4. Train DNNs with different candidate combinations
5. Calculate Root-Mean-Squared Error (RMSE) in regression or misclassification rate in classification rbetween actual Y and estimated Y for validation samples for each candidate combination
6. Decide the optimal candidate combination with the minimum RMSE value
7. Train final DNN using both training samples and validation samples with the optimal candidate combination
8. Calculate determinant coefficient (r2C) and RMSE (RMSEC) in regression or confusion matrix in classification between actual Y and calculated Y, for the optimal candidate combination
r2C means the ratio of Y information that the SVR model can explain.
RMSEC means the average of Y errors in the SVR model.
9. Check plots between actual Y and calculated Y in regression
Outliers of calculated and estimated values can be checked.
10. In prediction, subtract the mean in the autoscalling of X in 1. from X-variables, and then, divide X-variables by the standard deviation in the autoscalling of X in 1., for new samples
11. Estimate Y based on the DNN in 7.
12. Multiply the standard deviation in the autoscalling of Y in 1. by estimated Y, and then, add the mean in the autoscalling of Y in 1. in regression
How to perform DNN
1. Buy the code and unzip the file
2. Download and unzip the supplemental zip file (this is free)
3. Place the supplemental files at the same directory or folder as that of the DNN code.
4. Prepare data set. For data format, see the article below.
5. Run the code!
Estimated values of Y for “data_prediction2.csv” are saved in ”PredictedY2.csv”.
Please see the article below.