Question: Machine Learning, R-Studio- We will use Artificial Neural Network with a hidden layer to predict baseball players log-salary judging by all other variables of the

Machine Learning, R-Studio-

We will use Artificial Neural Network with a hidden layer to predict baseball players log-salary judging by all other variables of the Hitters data set.

(a) Start off by running the following code, which will perform all the necessary initial transformation of Hitters data, alongside subdividing it into training (80%) and test (20%) subsets.

library(keras)

library(ISLR)

Hitters <- na.omit(Hitters)

Hitters$LogSalary <- log(Hitters$Salary)

Hitters$Salary <- NULL

n <- nrow(Hitters)

p <- ncol(Hitters)-1

set.seed(1)

train <- sample(n, 0.8*n)

(b) In a manner identical to what we did for Boston data in the lecture, proceed to save training inputs/labels and testing inputs/labels into respective R objects.

(c) List the names of all the variables that are in need of one-hot encoding, if there are any. Perform one-hot encoding on them, provide the code.

(d) Proceed to normalize the training data, and use the results to also scale the testing data appropriately.

(e) In a manner identical to what we did in the lecture and the Lab #6, build up an ANN layout with a fully-connected hidden layer of 64 ReLU units, a single linear neuron in the output layer.

(f) Compile this model in a manner identical to the lecture and the Lab #6.

(g) Proceed to train it for 300 epochs, with batch size 20, and validation split of 0.2. Plot the history of training.

(h) Evaluate the performance on test data. What is the overall mean absolute error?

(i) Looking back at the plot in part (g) - does there appear to be a lack of improvement in validation error past certain # of epochs? Proceed to re-run parts (e),(f),(g),(h), now using an early stopping callback function during (g), as we did in Lab #6. Does the training stop earlier? What is the overall test mean absolute error?

Please help with the HW on R-studio

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!