Make a simple neural network in R

Make a simple neural network in R

Recipe Objective - Make a simple neural network in R?

Neural network is a circuit of neurons or in broader sense, an Artificial Neural Network which composes of nodes that are basis of deep learning inspired by human brain in the same way biologically created neurons signal each other, used in solving artificial intelligence problems. Neural networks comprises of node layers, with an input layer, one or more hidden layers, and finally an output layer. Node assigns a number to its incoming connection known as 'weight'. It also contain an associated threshold value. If the output of individual node is above the specified threshold value then that node is activated thereby sending data to the next layer of the network. No data is passed to the next layer of the network if the output of individual node is below the specified threshold value.

A Deep Dive into the Types of Neural Networks

This recipe explains how to make a neural network in R.

Making a simple neural network.

Step 1: Sample_data.csv is used in building the neural network model. neuralnet package is installed and loaded to create neural network model.

# Installing Package
install.packages("neuralnet")
# Loading package
library(neuralnet)

Step 2: Sample_data.csv is loaded into the R environment to create neural network model.

# Loading the data data <- read.csv(file.choose())
str(data)

Step 3: Dataset features is scaled and normalized using min-max normalization technique for achieving good results afterwards and prevent overfitting in neural network model.

# Normalizing data data$overall_gre <- (data$overall_gre - min(data$overall_gre)) / (max(data$overall_gre) - min(data$overall_gre))
data$overall_gpa <- (data$overall_gpa - min(data$overall_gpa)) / (max(data$overall_gpa) - min(data$overall_gpa))
data$overall_rank <- (data$overall_rank - min(data$overall_rank)) / (max(data$overall_rank) - min(data$overall_rank))

Step 4: Datset is sampled into training and test dataset to build neural network model. Model is trained on training dataset and predictions are made on test dataset.

# Data Sampling set.seed(123)
input <- sample(2, nrow(data), replace = TRUE, prob = c(0.8, 0.2))
train_data <- data[input == 1, ]
test_data <- data[input == 2, ]

Step 5: Model is build using neuralnet() package specifying all the parameters of the neuralnet function.

# Model Building set.seed(123) # Setting the seed
network <- neuralnet(admit_univ ~ overall_gre + overall_gpa + overall_rank,
data = train_data,
hidden = 4,
err.fct = "ce",
linear.output = FALSE,
lifesign = 'full',
rep = 2,
algorithm = rprop+",
stepmax = 10000
)

Step 6: Neural network is plotted which was trained and build in previous steps.

# plotting the neural network
plot(network, rep = 1)
<c/ode>

Step 7: Predictions are made on test dataset and further analyzed.

# Prediction on test data
prediction <- compute(network, rep = 1, train_data[, -1])
head(prediction$net.result)
head(train_data[1, ])

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

Build a Logistic Regression Model in Python from Scratch
Regression project to implement logistic regression in python from scratch on streaming app data.

Deploy Transformer BART Model for Text summarization on GCP
Learn to Deploy a Machine Learning Model for the Abstractive Text Summarization on Google Cloud Platform (GCP)

NLP Project for Beginners on Text Processing and Classification
This Project Explains the Basic Text Preprocessing and How to Build a Classification Model in Python

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.