Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in ANN using R programming for Hitters data set can you please help what I am doing wrong ### develop an ANN model

Need help in ANN using R programming for Hitters data set

can you please help what I am doing wrong

### develop an ANN model to predict log(salary) from other attributes. Use at least two hidden layers. Use tfruns to tune your model's hyper-parameters including, the number of nodes in each hidden layer, the activation function in each hidden layer, batch_size, learning_rate, and the number of epochs). Validate each model on the validation set. Answer the following questions:

###Print the returned value from tf_runs to see the metrics for each run. Which run ( which hyper-parameter combination) gave the best mean squared error on the validation data?

### Print the learning curve for your best model. Does your best model still overfit?

### Does your validation_loss stop decreasing after several epochs? If so, at roughly which epoch

###does your validation_loss stop decreasing?

```{r}

in_train <- createDataPartition(hitters$Salary, p=.9, list = FALSE)

hitters_train <- hitters[in_train,]

hitters_test <- hitters[-in_train,]

#based on the requirement again i divived training data set in 90% and 10 as training and validation respectively%

Train_In_Train <- createDataPartition(hitters_train$Salary, p=.9, list = FALSE)

training <- hitters_train[Train_In_Train,]

training_level <- hitters_train$Salary[Train_In_Train]

validation <- hitters_train[-Train_In_Train,]

validation_level <- hitters_train$Salary[-Train_In_Train]

# Define a flag for each hyper-parameter you want to Tune and a default value for That hyper-parameter

FLAGS <- flags(flag_numeric("nodes", 128),

flag_numeric("batch_size", 100),

flag_string("activation", "relu"),

flag_numeric("learning_rate", 0.01),

flag_numeric("epochs", 30)

)

model <- keras_model_sequential()

model %>%

layer_dense(units = 10, activation = FLAGS$activation, input_shape = c(20)) %>%

layer_dense(units = 5, activation = 'softmax') %>%

layer_dense(units = 16, activation = 'softmax')

model %>% compile(

optimizer = optimizer_adam(lr=FLAGS$learning_rate),

loss = 'sparse_categorical_crossentropy',

metrics = c('mean_squared_error'))

training = as.matrix(training)

training_level = as.matrix(training_level)

validation = as.matrix(validation)

validation_level = as.matrix(validation_level)

##Getting error from below codes: Please note I have optimize categorical variable

model %>% fit(training, training_level, epochs = FLAGS$epochs, batch_size= FLAGS$batch_size, validation_data=list(validation, validation_level))

runs <- tuning_run("~/Documents/UIS Fall/CSC 532 ML/Assignment/Reuters.R",

flags = list(

nodes = c(64, 128, 392),

learning_rate = c(0.01, 0.05, 0.001, 0.0001),

batch_size=c(100,200,500,1000),

epochs=c(30,50,100),

activation=c("relu","sigmoid","tanh")

),

sample = 0.02

)

view_run(runs$run_dir[1])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Quantitative Analysis For Management

Authors: Barry Render, Ralph M. Stair, Michael E. Hanna

11th Edition

9780132997621, 132149117, 132997622, 978-0132149112

Students also viewed these Mathematics questions

Question

=+Describe how business intelligence can aid in this process.

Answered: 1 week ago