### R script to run the pre-constructed, trained NN on the new data set testdata <- read.csv("test.csv", sep=",") # Converting factors to numbers in Sex and Cabin testdata$Sex<-as.numeric(testdata$Sex) testdata$Cabin<-as.numeric(testdata$Cabin) # Approximating the ages of the NA values (linear interpolation) testdata$Age<-na.spline(testdata$Age) testdata$Fare<-na.spline(testdata$Fare) # Subsetting the test data to be of the same dimensions as the train data set testdata <- testdata[,c(2,4:7,9,10)] # method of normalization used is the min-max scaling technique [0,1] maxs <- apply(testdata, 2, max) mins <- apply(testdata, 2, min) # scaling the data for each column and fitting the scaled values into the data frame scaled <- as.data.frame(scale(testdata, center = mins, scale = maxs - mins)) # applying the scaled transform on the training and testing indices testdata_ <- scaled[1:nrow(testdata),] # finding the normalized test results for classification Survived.nn <- compute(nn,testdata_[,1:ncol(testdata)]) # Using a strict threshold of 0.5 and greater for binary values of 0 & 1 Survived.nn.res <- ifelse(Survived.nn$net.result>=0.5, 1, 0) # # comparing the two values and printing out a success percentage # MSE.nn <- sum(abs(test_$Survived - nn.res))/nrow(test_) # # #print(paste(MSE.lm,MSE.nn)) # print(paste("MSE for neural network: ",MSE.nn))