Part One

Load the requisite libraries

pack <- function(lib){
  new.lib <- lib[!(lib %in% 
                     installed.packages()[, 'Package'])]
  if (length(new.lib)) 
    install.packages(new.lib, dependencies = TRUE)
  sapply(lib, require, character.only = TRUE)
}

packages <- c('neuralnet', 'corrplot', 'caret', 'caTools', 'ggplot2', 'ggpubr',
              'cowplot', 'h2o', 'lime', 'pander', 'DT')
pack(packages)
## neuralnet  corrplot     caret   caTools   ggplot2    ggpubr   cowplot       h2o 
##      TRUE      TRUE      TRUE      TRUE      TRUE      TRUE      TRUE      TRUE 
##      lime    pander        DT 
##      TRUE      TRUE      TRUE
getwd() # establish current working directory

[1] “C:/Users/lshpaner/OneDrive/Cornell University/Coursework/Data Science Certificate Program/CEEM586 - Neural Networks and Machine Learning”

# set new working directory
working_dir = paste('C:/Users/lshpaner/OneDrive/Cornell University/Coursework/',
                    'Data Science Certificate Program/',
                    'CEEM586 - Neural Networks and Machine Learning/', sep = '')
setwd(working_dir)
# Read in the data
election <- read.csv(paste('https://raw.githubusercontent.com/lshpaner/',
                           'CEEM586_Neural_Networks_and_ML/main/data/',
                           'ElectionData.csv', sep = ''), row.names = 1, 
                     header = TRUE,
                     stringsAsFactors = FALSE)

Preprocessing

# remove index column to better adapt to machine learning format
rownames(election) <- NULL
datatable(election, options = list(scrollX = TRUE))  # inspect the df