SlideShare a Scribd company logo
1 of 10
Machine Learning with
Python
Logistic Regression
 Extension of linear regression where the dependent variable is categorical and not continuous.
 It is a prediction done with categorical variable. It predicts the probability of the outcome
variable being true.
In other words, the interest is in predicting which of two possible events are going to happen given
certain other information
• Is he a prospective customer ie., likelihood of purchase vs non-purchase ?
• Is he a defaulter for bill payment ie., credit worthiness
• Low claim or high risk for an insurance
• Medicine: is it going to work or does not work
Logistic Function
Logistic regression is named for the function used at the core of the method - the logistic
function(or sigmoid function). It converts any number into a number between 0 and 1.
Logistic regression models the probability of the
default class.
Logistic regression is a linear method, but the
predictions are transformed using the logistic function.
Logistic Regression - Example
You have data for some customers. You need to predict the probability whether a customer will buy
(y) a particular product or not. Let us assume we are given the “Age” of each customer.
g(y) = βo + β(Age)
In logistic regression, we are only concerned about the probability of outcome
dependent variable ( success or failure)
p = exp(βo + β(Age)) / exp(βo + β(Age)) + 1
Performance Metrics
Some of the metrics to evaluate a ML Model performance are:
Classification
 Accuracy
 Precision
 Recall
 F1 score
Regression
 Mean Absolute Error
 Mean Squared Error
 R2 Score
Classification Metrics
It’s a 2 by 2 matrix which compares the actual outcomes to the predicted outcomes. The rows are labeled with
actual outcomes while the columns are labeled with predicted outcomes.
True Positives (TP) - These are the correctly predicted positive values which means that the value of actual
class is yes and the value of predicted class is also yes. E.g. if actual class value indicates that this passenger
survived and predicted class tells you the same thing.
True Negatives (TN) - These are the correctly predicted negative values which means that the value of actual
class is no and value of predicted class is also no. E.g. if actual class says this passenger did not survive and
predicted class tells you the same thing.
False Positives (FP) – When actual class is no and predicted class is yes. E.g. if actual class says this passenger
did not survive but predicted class tells you that this passenger will survive.
False Negatives (FN) – When actual class is yes but predicted class in no. E.g. if actual class value indicates
that this passenger survived and predicted class tells you that passenger will die.
Classification Metrics
Accuracy : it is simply a ratio of correctly predicted observation to the total observations
Accuracy = TP+TN/TP+FP+FN+TN
Sensitivity or Recall = True Positives/(True Positives + False Negatives)
Out of all the items that are truly positive, how many were correctly classified as positive. Or simply,
how many positive items were 'recalled' from the dataset. The question recall answers is: Of all the
passengers that truly survived, how many did we label as Survived?
Specificity or Precision = True Positives/(True Positives + False Positives) aka Precision
Out of all the items labeled as positive, how many truly belong to the positive class. It measures
how precise you are at predicting a positive label. The question that this metric answer is of all
passengers that labeled as survived, how many actually survived?
F1-Score: F1 score combines precision and recall relative to a specific positive class. The F1 score can
be interpreted as a weighted average of the precision and recall, where an F1 score reaches its best
value at 1 and worst at 0:
F1 = 2 * (precision * recall) / (precision + recall)
False Positives and False Negatives
Precision: Out of the patients, diagnosed with illness, how many were classified correctly. Out
of emails sent to spam folder, how many of them were actually Spam.
Recall: Out of the sick patients, how many did we correctly diagnosed as sick? Out of all the
spam emails, how many of them were correctly sent to spam?
Accuracy Paradox
Accuracy can often be misleading, especially in cases where classes are heavily distributed
unevenly through the dataset. Consider the case where you have a dataset of 950 positive items
and 50 negative items. Without even using a model, predicting everything to be positive will
net a 95% accuracy score. This is known as the Accuracy Paradox. This information doesn't
really tell us anything at all. Our precision value would also yield the same percentage of 95%,
but this value is more telling. We know that out of all the items classified as positive, 95% truly
belong to that positive class. Our recall on the positive class would be 100%. Great! But recall
on the negative class is 0%. Accuracy couldn't tell us any of that information.
ROC Curve
Receiver Operating Characteristic(ROC) summarizes the model’s
performance by evaluating the trade offs between true positive rate
(sensitivity) and false positive rate(1- specificity).
The area under curve (AUC), referred to as index of accuracy(A) or
concordance index, is a perfect performance metric for ROC curve.
Higher the area under curve, better the prediction power of the
model. Below is a sample ROC curve. The ROC of a perfect
predictive model has TP equals 1 and FP equals 0.

More Related Content

What's hot

Data Communication And Networking - DATA RATE LIMITS
Data Communication And Networking - DATA RATE LIMITSData Communication And Networking - DATA RATE LIMITS
Data Communication And Networking - DATA RATE LIMITS
Avijeet Negel
 

What's hot (20)

Linear regression theory
Linear regression theoryLinear regression theory
Linear regression theory
 
Data Communication And Networking - DATA RATE LIMITS
Data Communication And Networking - DATA RATE LIMITSData Communication And Networking - DATA RATE LIMITS
Data Communication And Networking - DATA RATE LIMITS
 
Complements of numbers
Complements of numbersComplements of numbers
Complements of numbers
 
Linear regression
Linear regressionLinear regression
Linear regression
 
Error control
Error controlError control
Error control
 
Machine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion MatrixMachine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion Matrix
 
Theory of Computation Unit 1
Theory of Computation Unit 1Theory of Computation Unit 1
Theory of Computation Unit 1
 
Data Communications,Data Networks
Data Communications,Data NetworksData Communications,Data Networks
Data Communications,Data Networks
 
UNIT-4.pptx
UNIT-4.pptxUNIT-4.pptx
UNIT-4.pptx
 
Error detection correction (CRC)
Error detection correction  (CRC)Error detection correction  (CRC)
Error detection correction (CRC)
 
Data and computer communication exam i
Data and computer communication exam iData and computer communication exam i
Data and computer communication exam i
 
Huffman Algorithm By Shuhin
Huffman Algorithm By ShuhinHuffman Algorithm By Shuhin
Huffman Algorithm By Shuhin
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correction
 
Primality
PrimalityPrimality
Primality
 
Ml3 logistic regression-and_classification_error_metrics
Ml3 logistic regression-and_classification_error_metricsMl3 logistic regression-and_classification_error_metrics
Ml3 logistic regression-and_classification_error_metrics
 
Event classification & prediction using support vector machine
Event classification & prediction using support vector machineEvent classification & prediction using support vector machine
Event classification & prediction using support vector machine
 
C programs Set 3
C programs Set 3C programs Set 3
C programs Set 3
 
16 dynamic-memory-allocation
16 dynamic-memory-allocation16 dynamic-memory-allocation
16 dynamic-memory-allocation
 
Go Back N ARQ
Go  Back N ARQGo  Back N ARQ
Go Back N ARQ
 
Booth's Algorithm Fully Explained With Flow Chart PDF
Booth's Algorithm Fully Explained With Flow Chart PDFBooth's Algorithm Fully Explained With Flow Chart PDF
Booth's Algorithm Fully Explained With Flow Chart PDF
 

Similar to Machine learning session5(logistic regression)

Lecture-12Evaluation Measures-ML.pptx
Lecture-12Evaluation Measures-ML.pptxLecture-12Evaluation Measures-ML.pptx
Lecture-12Evaluation Measures-ML.pptx
GauravSonawane51
 
MACHINE LEARNING PPT K MEANS CLUSTERING.
MACHINE LEARNING PPT K MEANS CLUSTERING.MACHINE LEARNING PPT K MEANS CLUSTERING.
MACHINE LEARNING PPT K MEANS CLUSTERING.
AmnaArooj13
 

Similar to Machine learning session5(logistic regression) (20)

Logistic regression
Logistic regressionLogistic regression
Logistic regression
 
Important Classification and Regression Metrics.pptx
Important Classification and Regression Metrics.pptxImportant Classification and Regression Metrics.pptx
Important Classification and Regression Metrics.pptx
 
Assessing Model Performance - Beginner's Guide
Assessing Model Performance - Beginner's GuideAssessing Model Performance - Beginner's Guide
Assessing Model Performance - Beginner's Guide
 
Lecture-12Evaluation Measures-ML.pptx
Lecture-12Evaluation Measures-ML.pptxLecture-12Evaluation Measures-ML.pptx
Lecture-12Evaluation Measures-ML.pptx
 
Performance of the classification algorithm
Performance of the classification algorithmPerformance of the classification algorithm
Performance of the classification algorithm
 
Confusion matrix and classification evaluation metrics
Confusion matrix and classification evaluation metricsConfusion matrix and classification evaluation metrics
Confusion matrix and classification evaluation metrics
 
04 performance metrics v2
04 performance metrics v204 performance metrics v2
04 performance metrics v2
 
MACHINE LEARNING PPT K MEANS CLUSTERING.
MACHINE LEARNING PPT K MEANS CLUSTERING.MACHINE LEARNING PPT K MEANS CLUSTERING.
MACHINE LEARNING PPT K MEANS CLUSTERING.
 
Machine learning algorithms and business use cases
Machine learning algorithms and business use casesMachine learning algorithms and business use cases
Machine learning algorithms and business use cases
 
PERFORMANCE_PREDICTION__PARAMETERS[1].pptx
PERFORMANCE_PREDICTION__PARAMETERS[1].pptxPERFORMANCE_PREDICTION__PARAMETERS[1].pptx
PERFORMANCE_PREDICTION__PARAMETERS[1].pptx
 
All PERFORMANCE PREDICTION PARAMETERS.pptx
All PERFORMANCE PREDICTION  PARAMETERS.pptxAll PERFORMANCE PREDICTION  PARAMETERS.pptx
All PERFORMANCE PREDICTION PARAMETERS.pptx
 
working with python
working with pythonworking with python
working with python
 
Performance Metrics, Baseline Model, and Hyper Parameter
Performance Metrics, Baseline Model, and Hyper ParameterPerformance Metrics, Baseline Model, and Hyper Parameter
Performance Metrics, Baseline Model, and Hyper Parameter
 
Supervised learning
Supervised learningSupervised learning
Supervised learning
 
Performance Metrics for Machine Learning Algorithms
Performance Metrics for Machine Learning AlgorithmsPerformance Metrics for Machine Learning Algorithms
Performance Metrics for Machine Learning Algorithms
 
ML-ChapterFour-ModelEvaluation.pptx
ML-ChapterFour-ModelEvaluation.pptxML-ChapterFour-ModelEvaluation.pptx
ML-ChapterFour-ModelEvaluation.pptx
 
WEKA:Credibility Evaluating Whats Been Learned
WEKA:Credibility Evaluating Whats Been LearnedWEKA:Credibility Evaluating Whats Been Learned
WEKA:Credibility Evaluating Whats Been Learned
 
WEKA: Credibility Evaluating Whats Been Learned
WEKA: Credibility Evaluating Whats Been LearnedWEKA: Credibility Evaluating Whats Been Learned
WEKA: Credibility Evaluating Whats Been Learned
 
Supervised learning - Linear and Logistic Regression( AI, ML)
Supervised learning - Linear and Logistic Regression( AI, ML)Supervised learning - Linear and Logistic Regression( AI, ML)
Supervised learning - Linear and Logistic Regression( AI, ML)
 
The Lachman Test
The Lachman TestThe Lachman Test
The Lachman Test
 

More from Abhimanyu Dwivedi

More from Abhimanyu Dwivedi (11)

Deepfakes videos
Deepfakes videosDeepfakes videos
Deepfakes videos
 
John mc carthy contribution to AI
John mc carthy contribution to AIJohn mc carthy contribution to AI
John mc carthy contribution to AI
 
Machine learning session9(clustering)
Machine learning   session9(clustering)Machine learning   session9(clustering)
Machine learning session9(clustering)
 
Machine learning session8(svm nlp)
Machine learning   session8(svm nlp)Machine learning   session8(svm nlp)
Machine learning session8(svm nlp)
 
Machine learning session7(nb classifier k-nn)
Machine learning   session7(nb classifier k-nn)Machine learning   session7(nb classifier k-nn)
Machine learning session7(nb classifier k-nn)
 
Machine learning session6(decision trees random forrest)
Machine learning   session6(decision trees random forrest)Machine learning   session6(decision trees random forrest)
Machine learning session6(decision trees random forrest)
 
Machine learning session3(intro to python)
Machine learning   session3(intro to python)Machine learning   session3(intro to python)
Machine learning session3(intro to python)
 
Machine learning session2
Machine learning   session2Machine learning   session2
Machine learning session2
 
Machine learning session1
Machine learning   session1Machine learning   session1
Machine learning session1
 
Data analytics with python introductory
Data analytics with python introductoryData analytics with python introductory
Data analytics with python introductory
 
Housing price prediction
Housing price predictionHousing price prediction
Housing price prediction
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

Machine learning session5(logistic regression)

  • 2. Logistic Regression  Extension of linear regression where the dependent variable is categorical and not continuous.  It is a prediction done with categorical variable. It predicts the probability of the outcome variable being true. In other words, the interest is in predicting which of two possible events are going to happen given certain other information • Is he a prospective customer ie., likelihood of purchase vs non-purchase ? • Is he a defaulter for bill payment ie., credit worthiness • Low claim or high risk for an insurance • Medicine: is it going to work or does not work
  • 3. Logistic Function Logistic regression is named for the function used at the core of the method - the logistic function(or sigmoid function). It converts any number into a number between 0 and 1. Logistic regression models the probability of the default class. Logistic regression is a linear method, but the predictions are transformed using the logistic function.
  • 4. Logistic Regression - Example You have data for some customers. You need to predict the probability whether a customer will buy (y) a particular product or not. Let us assume we are given the “Age” of each customer. g(y) = βo + β(Age) In logistic regression, we are only concerned about the probability of outcome dependent variable ( success or failure) p = exp(βo + β(Age)) / exp(βo + β(Age)) + 1
  • 5. Performance Metrics Some of the metrics to evaluate a ML Model performance are: Classification  Accuracy  Precision  Recall  F1 score Regression  Mean Absolute Error  Mean Squared Error  R2 Score
  • 6. Classification Metrics It’s a 2 by 2 matrix which compares the actual outcomes to the predicted outcomes. The rows are labeled with actual outcomes while the columns are labeled with predicted outcomes. True Positives (TP) - These are the correctly predicted positive values which means that the value of actual class is yes and the value of predicted class is also yes. E.g. if actual class value indicates that this passenger survived and predicted class tells you the same thing. True Negatives (TN) - These are the correctly predicted negative values which means that the value of actual class is no and value of predicted class is also no. E.g. if actual class says this passenger did not survive and predicted class tells you the same thing. False Positives (FP) – When actual class is no and predicted class is yes. E.g. if actual class says this passenger did not survive but predicted class tells you that this passenger will survive. False Negatives (FN) – When actual class is yes but predicted class in no. E.g. if actual class value indicates that this passenger survived and predicted class tells you that passenger will die.
  • 7. Classification Metrics Accuracy : it is simply a ratio of correctly predicted observation to the total observations Accuracy = TP+TN/TP+FP+FN+TN Sensitivity or Recall = True Positives/(True Positives + False Negatives) Out of all the items that are truly positive, how many were correctly classified as positive. Or simply, how many positive items were 'recalled' from the dataset. The question recall answers is: Of all the passengers that truly survived, how many did we label as Survived? Specificity or Precision = True Positives/(True Positives + False Positives) aka Precision Out of all the items labeled as positive, how many truly belong to the positive class. It measures how precise you are at predicting a positive label. The question that this metric answer is of all passengers that labeled as survived, how many actually survived? F1-Score: F1 score combines precision and recall relative to a specific positive class. The F1 score can be interpreted as a weighted average of the precision and recall, where an F1 score reaches its best value at 1 and worst at 0: F1 = 2 * (precision * recall) / (precision + recall)
  • 8. False Positives and False Negatives Precision: Out of the patients, diagnosed with illness, how many were classified correctly. Out of emails sent to spam folder, how many of them were actually Spam. Recall: Out of the sick patients, how many did we correctly diagnosed as sick? Out of all the spam emails, how many of them were correctly sent to spam?
  • 9. Accuracy Paradox Accuracy can often be misleading, especially in cases where classes are heavily distributed unevenly through the dataset. Consider the case where you have a dataset of 950 positive items and 50 negative items. Without even using a model, predicting everything to be positive will net a 95% accuracy score. This is known as the Accuracy Paradox. This information doesn't really tell us anything at all. Our precision value would also yield the same percentage of 95%, but this value is more telling. We know that out of all the items classified as positive, 95% truly belong to that positive class. Our recall on the positive class would be 100%. Great! But recall on the negative class is 0%. Accuracy couldn't tell us any of that information.
  • 10. ROC Curve Receiver Operating Characteristic(ROC) summarizes the model’s performance by evaluating the trade offs between true positive rate (sensitivity) and false positive rate(1- specificity). The area under curve (AUC), referred to as index of accuracy(A) or concordance index, is a perfect performance metric for ROC curve. Higher the area under curve, better the prediction power of the model. Below is a sample ROC curve. The ROC of a perfect predictive model has TP equals 1 and FP equals 0.