Professional Documents
Culture Documents
Lesson 3
Lesson 3
AI AND MACHINE
LEARNING
UNDERSTANDING • what is regression
• Linear Regression
REGRESSION • implementation issues
WHAT IS REGRESSION
▪ Logistic Regression
▪ The model created is usually sigmoidal (i.e. S-shape) between input(s) variables and
output variable
▪ Output variable is usually categorical
▪ Binary Logistic Regression – Only 2 possible outcome in the output (i.e. Success. / Failure)
▪ Multinomial Logistic Regression - > 2 possible outcomes in the output + no ordering
▪ Ordinal Logistic Regression - >2 possible outcomes in the output + order associated with output
INTRO TO AI & ML | DIP IN BORDER SECURITY | SINGAPORE POLYTECHNIC
WHAT IS REGRESSION
REGRESSION VS CLASSIFICATION
▪ Regression (method) is to study the relationship input vs output
BUT using the same method could also be used to classifier (i.e.
logistic regression)
▪ The objective (or problem) will require a suitable regression
method to be used.
▪ For example:
▪ X (independent variable)
▪ Y (dependent variable)
▪ To get the “best fit” for the training samples, the line should
minimize error between the observed y and predicted ŷ value
in the training data.
▪ RMSE ▪ R2
Range is dependent on the Range 0 - 1
response (output) variable General formula (there is
another formula for entire
population)
R2 = 0.98
Knowing X will help in predicting Y
X Y
1 2
2 3
3 6
4 7
5 9
Source: https://towardsdatascience.com/linear-regression-made-easy-how-does-it-work-and-
INTRO TO AI & ML | DIP IN BORDER SECURITY | SINGAPORE POLYTECHNIC how-to-use-it-in-python-be0799d2f159
HOW LINEAR REGRESSION WORKS
MULTI DIMENSION LINEAR REGRESSION
▪ Steps
▪ pick random set of weights
▪ iteratively adjust weights in the direction of the gradient of the error
▪ when gradient approaches 0 🡪 minimum error , convergence
▪ Generalization
▪ Over-fitting
▪ Regularization
▪ Assumption
▪ Limited dataset
▪ System could ”remember” all the data
points
▪ Over-fitting (green line)
▪ Perfect prediction for known training data
▪ Likely not as good for unseen data
▪ Generalization (black line)
▪ More suitable for new unseen data
Source : https://en.wikipedia.org/wiki/Overfitting
INTRO TO AI & ML | DIP IN BORDER SECURITY | SINGAPORE POLYTECHNIC
IMPLEMENTING LINEAR REGRESSION
OVERFITTING AND GENERALIZATION
▪ Add an additional term in the cost function that has the effect
of penalizing large weights and thereby minimizing this skew.
▪ Examples
▪ Male = x1
▪ Female = x2
▪ Other features = x3 …
INTRO TO AI & ML | DIP IN BORDER SECURITY | SINGAPORE POLYTECHNIC
REGRESSION APPLICATIONS