SESSION - SUPERVISED LEARNING
Recap and Code
Presented by: Khadijah S. Mohammed
Understanding Regression and Classification
Regression - Predicting Continuous Values
Regression is a type of supervised learning where the goal is to
predict continuous values. Imagine predicting the price of a
house based on its features. It's like fitting a line to the data to
make future predictions.
Types of Regression Algorithms
Tools for Continuous Predictions
Overview of common regression algorithms:
● Linear Regression
● Polynomial Regression
● Ridge Regression
● Lasso Regression
Types of Classification Algorithms
Choosing the Right Category
Overview of common classification algorithms:
● Logistic Regression
● Decision Trees
● Support Vector Machines
● K-Nearest Neighbors
Linear Regression
Definition: Linear Regression is a supervised machine learning algorithm
used for predicting a continuous outcome variable (also called the
dependent variable) based on one or more predictor variables
(independent variables). It assumes a linear relationship between the
predictors and the target variable.
Use Case: Predicting house prices based on features like square
footage, number of bedrooms, etc.
Logistic Regression
Definition: Logistic Regression is a supervised machine learning algorithm
used for binary classification tasks, where the outcome variable is
categorical and has two classes. Despite its name, it's used for
classification, not regression. It models the probability that an instance
belongs to a particular class using a logistic function.
Use Case: Predicting whether an email is spam or not spam, or predicting
whether a patient has a particular medical condition.
Decision Trees
Definition: Decision Trees are a versatile supervised machine
learning algorithm used for both classification and regression tasks.
They make decisions based on a tree-like graph structure, where
each internal node represents a decision based on a feature, each
branch represents an outcome of that decision, and each leaf node
represents the final prediction or outcome.
Use Case: In a classification task, a Decision Tree might be used to
determine the species of a flower based on features like petal length
and width.
Evaluating Models
Measuring Success
Discussion on metrics:
● Accuracy
● Precision
● Recall
● F1 Score
LET’S CODE
Setting the Stage
Alright, let's dive into the code together!
Quick heads up about what we're getting into.
Introduction to the dataset: Hours Studied vs. Exam Scores.
We're going to work on predicting exam scores based on hours studied.
Think of it as unraveling the magic behind predicting outcomes using
machine learning.
Importing Libraries
Let's bring in the cool coding tools!
Simple explanation and code snippet for importing libraries:
Explanation: We're grabbing some tools to make our coding journey smooth. numpy for numerical
operations, matplotlib for plotting, and LinearRegression from scikit-learn for our star prediction
model.
Preparing the Data
Time to set the stage for our data drama!
Code snippet for defining hours_studied and exam_scores arrays:
Explanation: This is where we introduce our actors - the hours students
studied and their corresponding exam scores. This data will be the heart
of our prediction model.
Visualizing the Data
Let’s see what our data looks like - graph time!
Code snippet for creating a scatter plot:
Explanation: "We're painting a picture of our data. The x-axis shows
hours studied, the y-axis shows exam scores. A scatter plot gives us a
visual story of how they relate.
Visualization
B
Creating the Model
Introducing the star of our show - Linear Regression!
Explanation: Our main character - Linear Regression! We're reshaping
the data and teaching the model using the fit method. It's like training our
ML superhero to understand the relationship between hours studied and
exam scores.
Making Predictions
We're predicting the future!
Explanation: Time to put our model to the test! We're giving it new hours
to study, and it's predicting the corresponding exam scores. It's like
asking our ML fortune teller for predictions.
Visualizing the Regression Line
Caption: Time to draw the line between reality and our predictions!"
Code snippet for plotting the regression line:
Explanation: Let's visualize how well our predictions align with reality.
The scatter plot shows our actual data, and the red line represents our
model's predictions - it's like drawing the best-fit line through our data
points.
Visualizing the regression line
LOGISTIC REGRESSION CODING
Import and clean
Split
Split dataset into training and testing.
Model, predict and Evaluation
Discussion
That's a wrap! Feel free to ask anything or experiment with the code.
Understanding these steps is like having the backstage pass to machine
learning tricks.
Presented by: Khadijah S. Mohammed
Khadijah@culminatech.com