Logistic Regression Implementation
Logistic Regression:
When the outcome variable is categorical in nature, logistic regression can be used
to predict the likelihood of an outcome based on the input variables.
Although logistic regression can be applied to an outcome variable that represents
multiple values, but we will examine the case in which the outcome variable
represents two values such as true/false, pass/fail, or yes/no.
Logistic Regression Model:
A logistic regression model can be built to determine if a person will or will not
purchase a new automobile in the next 12 months.
The training set could include input variables for a person's age, income, and
gender as well as the age of an existing automobile.
The training set would also include the outcome variable on whether the person
purchased a new automobile over a 12-month period.
The logistic regression model provides the likelihood or probability of a person
making a purchase in the next 12 months..
Linear Regression Implementation:
The steps to implement linear regression includes:
Step 1: Import the required modules.
Step 2: Generate Dataset.
Step 3: Visualize the Data.
Step 4:Split the dataset.
Step 5: Perform logistic regression.
Step 6: Make prediction using the model
Step 7: Display the confusion matrix
Rutuja Kadam Sathaye College
Code:
Rutuja Kadam Sathaye College
Output:
Figure 1: Displays the logistic regression coefficient and intercept, the predicted y value and
the confusion matrix.
The confusion matrix is displayed as:
[[ 9 1
1 14]]
Where,
9 represents the number of positive true values we predicted correctly.
14 represents number of negative true values we predicted correctly.
1 represents number of positive values we predicted incorrectly.
1 represents number of negative values we predicted incorrectly.
Figure 2: Plotting a scatter plot of Logistic Regression.
Rutuja Kadam Sathaye College