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

Deep Reinforcement Learning for Ping Pong

How to use AI and Computer vision to make the virtual watchdog

Playing with OpenAI CLIP on multiple datasets

Linear Regression on Boston Dataset

Road defect detection using deep active learning

An illustrative introduction to Fisher’s Linear Discriminant

Active Learning in Machine Learning

Lecture Notes in Deep Learning: Feedforward Networks — Part 4

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

Creating a Feature Store with Feast

How AI and ML Can Accelerate Business Intelligence

Explaining AI — Auditing Machine Learning

A Deep Dive into Machine Learning Pipeline with ML Ops architecture, Model registry, and Feature…