Question
Goal: predict the purchase decision in the OJ data by fitting a dense neural network. (The data contains 1070 purchases where the customer either purchased
Goal: predict the purchase decision in the OJ data by fitting a dense neural network.
(The data contains 1070 purchases where the customer either purchased Citrus Hill or Minute Maid Orange Juice. A number of characteristics of the customer and product are recorded.)
First we load the data and divide it into the train and test sets. ```{r} library(ISLR2) library(keras)
set.seed(117)
n = nrow(OJ) sam = sample(n, 800) train = OJ[sam,] test = OJ[-sam,]
(a) For both the train and test data, create the matrix of scaled predictors, and the vector of responses encoded as one-hot vector.
(b) Construct the model. Use the architecture similar to what was used in the lab for NIST classification. More precisely, use two hidden layer with 10 units in each, one output layer with a single unit, and two dropout regularization layers in between, with dropout rates 0.4 and 0.3. Use "relu" activation for hidden layers and "sigmoid" activation for the output unit.
(c) Compile the model using the "binary_crossentropy" loss and the "accuracy" as a metric. (Use the same optimizer as in the code example.)
(d) Fit the model using 50 epochs, with the batch_size = 64, and validation_split = 0.2. Plot the history.
(e) Predict the decision on the test data and calculate the test misclassification
(f) Compare the result with the misclassification test errors which were achieved by other methods in the previous homework.
Use R please
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started