Professional Documents
Culture Documents
M4 - FDS
M4 - FDS
M4 - FDS
Supervised learning
• Supervised learning attempts to find a
relationship between the predictors and the
response in order to make a prediction
• Biggest drawback of supervised machine
learning need labelled data
• Some possible applications for supervised
learning include:
o Stock price predictions
o Weather predictions
o Crime prediction using is that we need
this labelled data
• Types
o Classification - predict a categorical response
o Regression - predicts a continuous response
• List of Common Algorithms
• Nearest Neighbour • Linear Regression
• Naive Bayes • Support Vector Machines (SVM)
• Decision Trees • Neural Networks
• Here the human experts act as the teacher where we feed the computer with
training data containing the input/predictors and we show it the correct answers
(output) and from the data the computer should be able to learn the patterns.
• Supervised learning algorithms try to model relationships and dependencies
between the target prediction output and the input features such that we can
predict the output values for new data based on those relationships which it
learned from the previous data sets.
Unsupervised learning
• Input is a set of predictors and utilizes relationships between the predictors
o Reducing the dimension - dimensionality reduction
o Similar groups – clustering
• The advantage over Supervised Learning is that, here, no labels are required.
• Drawback is that it merely suggests
differences and similarities, which then
requires a human’s interpretation.
• List of Common Algorithms
o k-means clustering
o Association Rules
• Mainly used in pattern
detection and descriptive modeling.
However, there are no output categories
nor labels here based on which the
algorithm can try to model relationships.
These algorithms try to use techniques on
the input data to mine for rules, detect
patterns, and summarize and group the
data points which help in deriving meaningful insights and describe the data
better to the users.
Reinforcement learning
• It uses observations gathered from the interaction with the environment to take
actions that would maximize the reward or minimize the risk.
• It allows machines and software agents to automatically determine the ideal
behavior within a specific context, in order to maximize its performance.
• Simple reward feedback is required for the agent to learn its behavior; this is
known as the reinforcement signal.
• Using this algorithm, the machine is trained to make specific decisions.
• It works this way: the machine is exposed to an environment where it trains itself
continually using trial and error.
• This machine learns from past experience and tries to capture the best possible
knowledge to make accurate decisions
Components of TSM
1. Trend
o The trend shows the general tendency of the data to increase or decrease
during a long period of time.
o A trend could be:
▪ Uptrend: If the TSM shows a general pattern that is upward, then it is
an uptrend.
▪ Downtrend: If the TSM shows a pattern that is downward then, it is a
downtrend.
▪ Horizontal or Stationary trend: If no pattern is observed, then it is
called a Horizontal or stationary trend.
o Ex: Suppose there is a hardware shop near a construction site. Until the
construction is completed, the hardware shop would see an uptrend in sales
and once the construction is completed, there would be a downtrend in sales
o Hence, we can say that trend is something which happens for some time and
then it disappears.
2. Seasonality
o Seasonality is a repeating pattern within a fixed period.
o It is a predictable pattern that recurs or repeats over regular intervals.
o Seasonality is often observed within a year or less.
o Ex: Every year during the holidays or Christmas season, sales revenue
increases. And during the off-season, the sales go down.
o Ex: During the monsoon seasons, the sale of umbrellas and raincoats increase
and it decreases, once the season is over.
3. Irregularity:
o It is also known as noise, so these are erratic, or you can say unsystematic.
o This happens only for a short duration, and it is non-repeating.
o It is a random part of the data.
o There is no specific pattern, which makes it difficult to be factored into an
analysis.
o It does not repeat often and is caused due to unforeseen or highly random
events like natural disasters.
4. Cyclicity:
o It is somewhat like seasonality, but in cyclicity, the duration is unfixed, and
the gap length of time between two cycles can be much longer.
o Ex: Suppose a recession happened in 2002, then one in 2008 and then
another one is 2012.
o So, it is not every year but for a much longer time over the years.
o The duration of the event varies, and the gap between the durations too.
Time Series Models
1. Autoregression (AR)
o The autoregression (AR) method models the next step in the sequence as a
linear function of the observations at prior time steps.
o Number of AR (Auto-Regressive) terms (p):
▪ p is the parameter associated with the auto-regressive aspect of the
model, which incorporates past values i.e., lags of dependent variable.
▪ For instance, if 𝑝 is 5, the predictors for 𝑥(𝑡) will be
𝑥(𝑡 − 1) …. 𝑥(𝑡 − 5).
2. Moving Average (MA)
o The Moving Average (MA) method models the next step in the sequence as
the average of a window of observations at prior time steps.
o Number of MA (Moving Average) terms (q):
▪ 𝑞 is size of the moving average part window of the model i.e., lagged
forecast errors in prediction equation.
▪ For instance, if 𝑞 is 5, the predictors for 𝑥(𝑡) will be
𝑒(𝑡 − 1) …. 𝑒(𝑡 − 5) where 𝑒(𝑖) is the difference between the
moving average at 𝑖 𝑡ℎ instant and actual value.
3. Autoregressive Moving Average (ARMA)
o In ARMA model, there are 2 paramters:
o Number of AR (Auto-Regressive) terms (p):
▪ p is the parameter associated with the auto-regressive aspect of the
model, which incorporates past values i.e., lags of dependent variable.
▪ For instance, if 𝑝 is 5, the predictors for 𝑥(𝑡) will be
𝑥(𝑡 − 1) …. 𝑥(𝑡 − 5).
o Number of MA (Moving Average) terms (q):
▪ 𝑞 is size of the moving average part window of the model i.e., lagged
forecast errors in prediction equation.
▪ For instance, if 𝑞 is 5, the predictors for 𝑥(𝑡) will be
𝑒(𝑡 − 1) …. 𝑒(𝑡 − 5) where 𝑒(𝑖) is the difference between the moving
average at 𝑖 𝑡ℎ instant and actual value.
4. Autoregressive integrated moving average (ARIMA)
o In an ARIMA model there are 3 parameters that are used to help model the
major aspects of a times series: seasonality, trend, and noise.
o These parameters are labelled p, d and q.
o Number of AR (Auto-Regressive) terms (p): p is the parameter associated
with the auto-regressive aspect of the model, which incorporates past values
i.e., lags of dependent variable.
o Number of Differences (d): d is the parameter associated with the integrated
part of the model, which effects the amount of differencing to apply to a time
series.
o Number of MA (Moving Average) terms (q): q is size of the moving average
part window of the model
When not to use TSM
1. When the values are constant - This means they are not dependent on time so first
of all, the data is not a time series data and secondly, it is pointless as the values
never change.
2. When the values are in the form of a function - For example sin(𝑥 ), cos(𝑥 ) etc. It
is, again, pointless to use time series analysis as you can calculate the values using
a function.
x = data ["Average_Pulse"]
y = data ["Calorie_Burnage"]
plt.scatter(x, y)
# draw a scatter plot of x vs actual y
plt.ylim(ymin=0, ymax=2000)
plt.xlim(xmin=0, xmax=200)
plt.xlabel("Average_Pulse")
plt.ylabel("Calorie_Burnage")
plt.show()
Output:
1. Data Preprocessing
import numpy as nm
import pandas as pd
# Feature Scaling will normalize the columns so that each column will have μ = 0
# and σ = 1
from sklearn.preprocessing import StandardScaler
ss = StandardScaler()
x_train = ss.fit_transform(x_train) # fit_transform for train
x_test = ss.transform(x_test) # transform for test