AAI Lecture 10 Sp 25
AAI Lecture 10 Sp 25
Supervised Learning
1
Supervised Learning
• A type of machine learning method in which:
• labeled data is provided to the machine learning system in order to train it,
• The system creates a model using labeled data to understand the datasets and
learn about each data,
• On the basis of learning, Model predicts the output for an unlabeled data
• Basically discovers patterns in the data that relate data attributes with a
target (class) attribute.
2
Supervised Learning
• The two most common types of supervised learning are
• Classification
• Prediction/Classification of the discrete values
• outputs are discrete labels
• Male or Female, True or False, Spam or Not Spam, etc.
• Regression
• algorithms are used to predict the continuous values
• outputs are real-valued.
• price, salary, age, stock exchange market prediction
3
What is Linear Regression ?
Linear Regression is a type of regression analysis that Linear Regression is based on the concept of a linear Linear Regression is used to draw a line of best
is used to establish relationships between function, y =b0 +b1x, where y is the dependent fit through a series of data points on a scatter
independent variables and dependent variables.It variable, x is the independent variable, b1 is the plot. The line is drawn in such a way that it
assumes a linear relationship between the variables. slope of the line and b0 is the y- intercept. predicts the value of the dependent variable
4
based on the value of the independent variable.
Linear regression
• Linear regression at its simplest expresses the mathematical
relationship between two variables or attributes.
• a linear relationship between an outcome variable and a predictor
(or set of predictors) is the simplest form of a relationship
5
Whyis LinearRegressionImportant?
Predictive Modeling Data Analysis Business Decision Making
6
TypesofLinearRegressionModels
Logistic Regression
Multiple Linear Regression
Logistic Regression is used when the
Multiple Linear Regression involves two dependent variable is categorical in
or more independent variables and one nature and cannot be measured
dependent variable. numerically.
1 2 3 4
Linear Regression is used to Linear Regression models are Linear Regression is used in educational
Linear Regression is used in
predict the outcome of a used in weather forecasting to institutions to predict a student's
trend analysis to predict the
particular treatment based on predict temperatures, performance based on various factors such
future value of stocks based
various factors such as age, precipitation, and other as demographics, socio-economic status,
on their historical
gender, and medical history. meteorological parameters. and previous academic performance.
performance.
8
Challenges in Linear Regression
9
Evaluation Methods in Linear Regression
10
What is Linear
• Remember this?
11
What is linear
• A slope of 2 means that
every 1-unit change in X
yields a 2-unit change in Y.
12
A simplistic example
• Suppose you run a social networking site that charges a monthly
subscription fee of $25. Each month you collect data and count
your number of users and total revenue
13
Equations for finding slope and intercept
14
Equations for finding slope and intercept
15
Linear regression equation
16
Trend and variation
• FINDING THE MODEL
• As we consider it to be a linear
relationship, the functional form will
be:
• Y = mx + c y = w0 + w1x
17
Example
• Dataset giving the living areas and prices of 50
houses
18
Example
• We can plot this data
19
Predictions
• Predicting in this manner is equivalent to “drawing line through
data”
3.2
Observed days
3.0 Prediction
2.8
2.6
2.4
2.2
2.0
1.8
1.6
1.4
55 60 65 70 75 80 85 90 95 100
20
Notations
23
Types of Loss/Error
24
Error/Loss Calculation
25
Practice
• Given c= 32, m = 10, find the value of error for the given data:
26
Chosing the regression line
Which of these
lines to chose?
Y Y
X X 27
y hw( x ) w0 w1 x
Chosing the regression line
The predicted value is:
yˆ i hw( x i ) w0 w1 xi
yˆ i
Error or residual yˆ i y i
yi
X
29
Chosing the regression line
Sum the error over
m training
To simplify examples We dont want
calculations negative values
m
1
J (w) min (hw( x ( i ) ) y (i ) )2
2 w i 1
31
min J (w)
w
Gradient Descent
• Choose initial values of w0 and w1 and continue moving the
direction of steepest descente
J(w)
32
W0
W1
Gradient Descent
• Choose initial values of w0 and w1 and continue moving the
direction of steepest descente
• The step size is controlled by a parameter called learning rate
Starting point is
important
33
Gradient Descent - Steps
34
Gradient descent
J(W1) ; W1 is a real number
d
W1 W1 J (W1 )
dW1
w1
36
Logistic regression (Logit Model)
• Example: One can determine the likelihood of choosing an offer
on your website (dependent variable).
• For analysis purposes, you can look at various visitor
characteristics such as the sites they came from, count of visits to
your site, and activity on your site (independent variables).
• This can help determine the probability of certain visitors who are
more likely to accept the offer.
• As a result, it allows you to make better decisions on whether to
promote the offer on your site or not.
37