1. “Regression Model and Artificial
Neural Network for Predictive
Analytics using R”
By
Vaibhav Kumar
Assistant Professor
Dept. of CSE
DIT University, Dehradun
Vaibhav Kumar@DIT University, Dehradun
2. Outline
Introduction
Predictive Analytics
Predictive Analytics Techniques
Regression Models in Prediction
Machine Learning Models in Prediction
Stock Market Prediction
Prediction using Regression Model
Prediction using Artificial Neural Network
Comparison
Conclusion
Vaibhav Kumar@DIT University, Dehradun
3. Introduction
On the basis of several input attributes, the value of an output attribute can be
determined through a model which formulates the relationship between these input and
output attributes.
There are many real life examples such as weather condition, dearness etc. where we see
that many independent variables which affects the future value of a dependent variable.
To model this dependency of a variable on other variables, there are a variety of methods
available.
Statistics, one of the premier field of mathematics, has given many methods to formulate
the relationship between variables.
The developments in the field of Computer Science have given many intelligent
algorithms, which are known as machine learning. It simulates the human learning
process.
Vaibhav Kumar@DIT University, Dehradun
4. Introduction
There are a variety of machine learning models which use the concept of statistics and
process the data intelligently with the speed of computer in order to generate a fast and
accurate result.
Research and development in the field of machine learning of is going on a full swing and
continuously proposing a much faster and accurate result.
A new field in the area of computer science is on boom – Data Science. It leverages the
capabilities of statistical and machine learning tools and works on data.
Industries are using data science to grow their businesses.
Vaibhav Kumar@DIT University, Dehradun
5. Predictive Analytics
Predictive analytics, a branch in the domain of advanced analytics, is used in predicting
the future events.
It analyze the current and historical data in order to make predictions about the future by
employing the techniques from statistics, data mining, machine learning, and artificial
intelligence.
It brings together the information technology, business modeling process and
management to make prediction about the future.
Businesses can appropriately use big data for their profit by successfully applying the
predictive analytics.
It can help organizations in becoming proactive, forward looking and anticipating trends
or behavior based on the data.
Vaibhav Kumar@DIT University, Dehradun
6. Predictive Analytics
Predictive analytics has a wide range of application in many domains.
It is widely used in e-commerce business to find the customer behaviors and offer them a
customized solution.
Insurance companies collect the data of working professional from a third party and
identifies which type of working professional would be interested in which type of
insurance plan and they approach them to attract towards its products.
Banking companies apply predictive analytics models to identify credit card risks and
fraudulent customer and become alert from those type of customers.
Organizations involved in financial investments identify the stocks which may give a good
return on their investment and they even predict the future performance of stocks based
on the past and current performance.
There are many other applications.
Vaibhav Kumar@DIT University, Dehradun
7. Predictive Analytics Techniques
All predictive analytics techniques are grouped into two categories:-
1. Classification Techniques: The class of a new observation is assigned based on the class
assignment of past observations. All the techniques used in this category give the discrete
output. For Example: Class A or Class B if there are two classes to classify the
observations.
2. Regression Techniques: Models used in the techniques give a continuous output. It
predicts a number. For example Temperature today at 08:00 PM.
Vaibhav Kumar@DIT University, Dehradun
8. Regression Models in Prediction
Regression is one of the most popular statistical technique which estimates the
relationship among variables.
It models the relationship between a dependent variable and one or more independent
variables.
It analyzes how the value of a dependent variable changes on changing the values of
independent variables in the modeled relation.
There are two types of regression models used in predictive analytics:-
1. Linear Regression Model (as a regression model)
2. Logistic Regression Model (as a classification model)
Vaibhav Kumar@DIT University, Dehradun
9. Machine Learning Models in Prediction
Machine learning is an application of artificial intelligence (AI) that provides systems the ability
to automatically learn and improve from experience without being explicitly programmed.
Machine learning focuses on the development of computer programs that can access data and
use it learn for themselves.
There are variety of machine learning model used in predictive analytics:-
Artificial Neural Network
Decision Tree
Support Vector Machine
Gradient Boosting
Random Forest
Many other
Vaibhav Kumar@DIT University, Dehradun
10. Stock Market Prediction
Machine learning models have a dominating role in financial applications.
In predicting the prices and trends in stock, machine learning techniques have always
been dominating among all the predictive analytics techniques.
This is only because of fast computing algorithms and working on large datasets.
Many of the stock market-based organization use machine learning models for predicting
the stock prices.
An accurate prediction of future prices may lead to higher yield of profit to investors
through stock investments.
As per the prediction, the investor shall be able to pick the stocks which may give a higher
return.
Vaibhav Kumar@DIT University, Dehradun
11. Prediction using Regression Model
Lets consider an example of stock market prediction. Please refer to the following data
set.
Vaibhav Kumar@DIT University, Dehradun
12. First take the historical data of all the attributes for same duration.
Normalize the data.
Fetch the data in Rstudio
> data=read.csv(“filename.csv”)
Split the data set into two sets– training set and test set.
> tr.data=data[1:380,]
> ts.data=data[381:495,]
Set the independent and dependent variables.
> y=tr.data$DAY_CLOSE
>x=tr.data$SENSEX+tr.data$NIFTY.50+tr.data$ST_52_High+tr.data$ST_52_Low+tr.data$PREV_
CLOSE+tr.data$DOLLAR+tr.data$CRUDE+tr.data$HANG_SENG+tr.data$DAX+tr.data$SENT_SCR
> reg.model=lm(y~x)
> print(summary(reg.model))
Vaibhav Kumar@DIT University, Dehradun
13. Prepare the test data.
>x=ts.data$SENSEX+ts.data$NIFTY.50+ts.data$ST_52_High+ts.data$ST_52_Low+ts.data$PREV
_CLOSE+ts.data$DOLLAR+ts.data$CRUDE+ts.data$HANG_SENG+ts.data$DAX+ts.data$SENT_S
CR
> result=predict(reg.model,data.frame(x))
> res=as.data.frame(result)
> test.y=ts.data$DAY_CLOSE
> test.x=result
Find the correlation between original values and the predicted values
> cor(test.x,test.y)
It can also be visualized through a graph.
> plot(test.x,test.y, abline(lm(test.y~test.x))
Vaibhav Kumar@DIT University, Dehradun
14. Artificial Neural Network
Artificial Neural Network (ANN) is a machine learning tool.
It is inspired by biological neural network of brain.
Billion of neurons are connected together in the brain. They receive electrochemical
signals from neighboring neurons, they process it and forward it to the next neighboring
neurons in the network.
Similar to the biological neurons, artificial neurons are connected together to form the
artificial neural network.
The network process the data in patterns rather than executing sequential information.
As information is stored in brain as strengths of synaptic gaps between neurons, similarly
the knowledge is stored in ANN as weights associated with the interconnection between
artificial neurons.
Vaibhav Kumar@DIT University, Dehradun
15. Introduction (Cont….)
Vaibhav Kumar@DIT University, Dehradun
Structure of an artificial neuron is shown in the above figure. The net input yin to the
neuron can be given as:
yin = b+x1w1+x2w2+…..+xnwn
Or, yin = 𝑖=1
𝑛
xiwi
where b is the bias term. The output of the neuron can be given as:
yout = f(yin)
Where f(.) is called the activation or transfer function of the neuron. This function is
used as per the required output.
16. Learning
The main goal of neural network is to solve the problems through learning which are
complex to solve by human.
In all the neural net learning methods, weights of the network are adjusted.
There are a variety if learning algorithms used by neural networks to solve problems.
Some popular neural network learning algorithms are:
Backpropagation Learning
Hebbian learning Supervised Learning
Perceptron Learning
Delta/Least Mean Square learning
Winner-Takes-All Unsupervised Learning
Vaibhav Kumar@DIT University, Dehradun
17. Application in Stock Market Prediction
The input attributes of the dataset will be applied at the input layer of the neural network
and the day’s closing price of stock will be obtained at the output layer.
> library("neuralnet")
>f=tr.data$DAY_CLOSE~tr.data$SENSEX+tr.data$NIFTY.50+tr.data$ST_52_High+tr.data$ST_52_
Low+tr.data$PREV_CLOSE+tr.data$DOLLAR+tr.data$CRUDE+tr.data$HANG_SENG+tr.data$DAX
+tr.data$SENT_SCR
> net=neuralnet(f,tr.data,hidden = 12, algorithm = "rprop+", act.fct = "logistic", linear.output =
TRUE, lifesign.step = 1000)
> summary(net)
> plot(net)
> tt.x=ts.data[,1:10]
> result=compute(net,tt.x)
> cor(ts.data$DAY_CLOSE,result$net.result)
Vaibhav Kumar@DIT University, Dehradun