Implementation using nnet() library

######################################################################## 
##Chapter 1 - Introduction to Neural Networks - using R ################
###Simple R program to build, train and test neural networks ###########
### Classification based on 3 inputs and 1 categorical output ##########
########################################################################
###Choose the libraries to use
library(NeuralNetTools)
library(nnet)
###Set working directory for the training data
setwd("C:/R")
getwd()
###Read the input file
mydata=read.csv('RestaurantTips.csv',sep=",",header=TRUE)
mydata
attach(mydata)
names(mydata)
##Train the model based on output from input
model=nnet(CustomerWillTip~Service+Ambience+Food,
data=mydata,
size =5,
rang=0.1,
decay=5e-2,
maxit=5000)
print(model)
plotnet(model)
garson(model)
########################################################################

Let us go through the code line-by-line

library(NeuralNetTools)
library(nnet)
###Set working directory for the training data
setwd("C:/R")
getwd()
###Read the input file
mydata=read.csv('RestaurantTips.csv',sep=",",header=TRUE)
mydata
attach(mydata)
names(mydata)
##Train the model based on output from input
model=nnet(CustomerWillTip~Service+Ambience+Food,
data=mydata,
size =5,
rang=0.1,
decay=5e-2,
maxit=5000)
print(model)
> model=nnet(CustomerWillTip~Service+Ambience+Food,data=mydata, size =5, rang=0.1, decay=5e-2, maxit=5000)
# weights: 26
initial value 7.571002
iter 10 value 5.927044
iter 20 value 5.267425
iter 30 value 5.238099
iter 40 value 5.217199
iter 50 value 5.216688
final value 5.216665
converged
print(model)
> print(model)
a 3-5-1 network with 26 weights
inputs: Service Ambience Food
output(s): CustomerWillTip
options were - decay=0.05
plotnet(model)
garson(model)

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Understanding Machine Learning Algorithms — Naive Bayes

Computer Vision Abbreviation Glossary (growing)

DISCRIMINANT ANALYSIS — A CONCEPTUAL UNDERSTANDING

Machine learning revelations

How to use Deep Learning to identify dog breeds

The Last Machine & Deep-Learning Compendium You’ll Ever Need.

Image Similarity Using UNET AutoEncoder And KNN

3. INTRODUCTION TO ML WITH PYTHON USING kNN

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Reza Hartono

Reza Hartono

More from Medium

Sparkify: Customer Churn Prediction

Predicting Churn with Spark

“Everything is Cancelled” Photo by Jeffrey Czum source: https://www.pexels.com/photo/concrete-building-under-blue-sky-4004291/

Dynamic Performance Analytics

Analysis of Simpson’s paradox example dataset

png