0% found this document useful (0 votes)
10 views88 pages

CSC 413 Machine Learning With Python

CSC 413 is a course on Machine Learning using Python, covering essential topics such as data preprocessing, supervised and unsupervised learning, model evaluation, and real-world applications. Students will learn to use key Python libraries like NumPy, Pandas, Matplotlib, and Scikit-learn to build and evaluate machine learning models. The course also addresses ethical considerations in machine learning, emphasizing the importance of bias, fairness, and data privacy.

Uploaded by

j70410145
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views88 pages

CSC 413 Machine Learning With Python

CSC 413 is a course on Machine Learning using Python, covering essential topics such as data preprocessing, supervised and unsupervised learning, model evaluation, and real-world applications. Students will learn to use key Python libraries like NumPy, Pandas, Matplotlib, and Scikit-learn to build and evaluate machine learning models. The course also addresses ethical considerations in machine learning, emphasizing the importance of bias, fairness, and data privacy.

Uploaded by

j70410145
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CSC 413: MACHINE LEARNING WITH PYTHON

Course Description
This course introduces students to the principles and practical implementation of Machine Learning
(ML) using Python. It covers data preprocessing, supervised and unsupervised learning, model
evaluation, and real-world applications using popular libraries.

Course Objectives
By the end of this course, students should be able to:

✓ Understand core concepts in Machine Learning

✓ Use Python libraries to build ML models

✓ Analyze and preprocess datasets

✓ Implement supervised and unsupervised algorithms

✓ Evaluate and improve model performance

✓ Apply ML to real-world problems

Course Modules

Module 1: Introduction to Machine Learning

➢ Definition and importance of ML

➢ Types of ML:

✓ Supervised Learning

✓ Unsupervised Learning

✓ Reinforcement Learning

➢ Applications of ML (healthcare, finance, education)

Module 2: Python for Machine Learning

➢ Overview of Python for ML

➢ Key libraries:
CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

1
✓ NumPy (numerical computing)

✓ Pandas (data manipulation)

✓ Matplotlib (visualization)

✓ Scikit-learn (ML models)

Module 3: Data Preprocessing

➢ Data collection and cleaning

➢ Handling missing values

➢ Feature scaling (normalization, standardization)

➢ Encoding categorical variables

➢ Train-test split

Module 4: Exploratory Data Analysis (EDA)

➢ Data visualization techniques

➢ Correlation analysis

➢ Identifying patterns and trends

Module 5: Supervised Learning – Regression

➢ Linear Regression

➢ Multiple Regression

➢ Model training and prediction

➢ Evaluation metrics:

✓ Mean Squared Error (MSE)

✓ R² Score

Module 6: Supervised Learning – Classification

➢ Logistic Regression
CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

2
➢ K-Nearest Neighbors (KNN)

➢ Decision Trees

➢ Support Vector Machines (SVM)

Module 7: Model Evaluation and Validation

➢ Confusion Matrix

➢ Accuracy, Precision, Recall, F1-score

➢ Cross-validation

➢ Overfitting vs Underfitting

Module 8: Unsupervised Learning

➢ Clustering:

✓ K-Means

✓ Hierarchical Clustering

➢ Dimensionality Reduction:

✓ Principal Component Analysis (PCA)

Module 9: Ensemble Learning

➢ Bagging

➢ Boosting

➢ Random Forest

Module 10: Introduction to Neural Networks

➢ Basics of Artificial Neural Networks (ANN)

➢ Perceptron model

➢ Activation functions

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

3
Module 11: Deep Learning Basics

➢ Introduction to Deep Learning

➢ Using frameworks:

✓ TensorFlow

✓ Keras

Module 12: Model Deployment

➢ Saving models (Pickle, Joblib)

➢ Building simple ML APIs

➢ Introduction to cloud deployment

Module 13: Ethics in Machine Learning

➢ Bias and fairness

➢ Data privacy

➢ Responsible AI

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

4
Introduction to Machine Learning
What is Machine Learning?

Machine Learning (ML) is a part of Machine Learning where we teach computers how to learn from
experience, just like humans do.

Simple Definition:

Machine Learning is when a computer learns from data instead of being told every single step.

Example:

Think of teaching a child to recognize a dog

✓ You show many pictures of dogs

✓ The child learns what a dog looks like

✓ Next time, they can say: “That’s a dog!”

Machine Learning works the same way:

✓ Show the computer many examples

✓ It learns patterns

✓ Then it makes decisions on its own

Why is Machine Learning Important?


Machine Learning is important because it helps computers:

✓ Make smart decisions

✓ Solve problems faster

✓ Work without human help all the time

Real-life Example:

✓ Your phone unlocking with your face

✓ YouTube recommending videos you like

✓ Banks detecting fraud

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

5
Types of Machine Learning
There are 3 main types. Let’s make them very easy:

Supervised Learning (Learning with a Teacher )

The computer learns using questions and correct answers

Example:

You give a student:

✓ Questions + correct answers

So the student learns how to solve similar questions.

Real-life Example:

• Predicting student scores

• Email spam detection

Simple Illustration:

Input: Picture of a cat → Output: “Cat”


Input: Picture of a dog → Output: “Dog”

The computer is “supervised” because it is guided.

Unsupervised Learning (Learning Alone )

The computer learns without answers

It tries to find patterns by itself

Example:

Imagine giving a child:

✓ A box of mixed fruits


Without telling them anything

The child groups them like:

✓ Apples together

✓ Bananas together
CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

6
That’s unsupervised learning!

Real-life Example:

✓ Grouping customers by buying behavior

✓ Organizing photos by faces

Reinforcement Learning (Learning by Trial and Error )

The computer learns by:

✓ Trying something

✓ Getting reward or punishment

Example:

Like playing a video game

✓ Good move → you get points

✓ Bad move → you lose

Over time, you learn the best way to win.

Real-life Example:

✓ Self-driving cars

✓ Robots learning to walk

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

7
Applications of Machine Learning
Machine Learning is used everywhere!

1. Healthcare

✓ Detecting diseases from scans

✓ Predicting illness early

Example: Computer checks X-ray and says “Possible infection”

2. Finance (Money & Banking)

✓ Detecting fraud

✓ Predicting stock trends

Example: Bank notices unusual transaction and blocks it

3. Education

✓ Smart learning apps

✓ Automatic grading

Example: App suggests topics you need to improve

Everyday Life

✓ Voice assistants (like Siri, Google Assistant)

✓ Netflix/YouTube recommendations

✓ Face recognition

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

8
Summary (Very Simple)

Type Meaning Example

Supervised Learn with answers Teacher marking your work

Unsupervised Learn without answers Grouping fruits

Reinforcement Learn by trial & error Playing games

Final Idea
Machine Learning is like teaching computers to think and learn like humans, but using data instead
of a brain.

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

9
Python for Machine Learning
What is Python for Machine Learning?
Python is a programming language (a way we talk to computers).

When we use Python for Machine Learning, we use it to:

✓ Teach computers to learn

✓ Analyze data

✓ Make predictions

Simple Example:

Imagine you want to predict:

“Will it rain today?”

You can use Python to:

1. Collect weather data

2. Study it

3. Make a smart guess

That’s Python + Machine Learning working together!

Why Python is Used for Machine Learning

Python is popular because:

✓ It is easy to learn

✓ It has many helpful tools (called libraries)

✓ It saves time (you don’t need to write everything from scratch)

Key Python Libraries (Tools)

Think of libraries as toolboxes


Each toolbox has special tools for different jobs.

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

10
NumPy (Number Expert )

NumPy helps us work with numbers and calculations

Simple Example:

Let’s say you have scores:

import numpy as np

scores = [Link]([50, 60, 70, 80])


average = [Link](scores)

print(average)

Output:

65

What happened?

✓ NumPy helped us quickly calculate the average

Real-life Idea:

✓ Used in science, engineering, and ML calculations

Pandas (Data Organizer )

Pandas helps us organize and clean data

Simple Example:

import pandas as pd

data = {
"Name": ["John", "Mary", "Paul"],
"Score": [80, 90, 70]
}

df = [Link](data)
print(df)

Output:

Name Score
0 John 80
CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

11
1 Mary 90
2 Paul 70

What happened?

✓ Pandas turned messy data into a table

Real-life Idea:

✓ Like an Excel sheet inside Python

Matplotlib (Drawing Tool )

Matplotlib helps us draw charts and graphs

Simple Example:

import [Link] as plt

scores = [50, 60, 70, 80]

[Link](scores)
[Link]()

This draws a line graph

What happened?

✓ We turned numbers into a picture (graph)

Real-life Idea:

✓ Teachers use charts to explain results

✓ Businesses use graphs to see trends

Scikit-learn (The Smart Brain)

What is Scikit-learn?

Scikit-learn is a special Python tool that helps computers:

learn from data and make smart decisions

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

12
Simple Definition:

Scikit-learn is like giving your computer a brain so it can:

✓ Learn from examples

✓ Recognize patterns

✓ Make predictions

Imagine This...

Think of Scikit-learn like a smart student in class:

✓ You teach the student with examples

✓ The student understands the pattern

✓ Then answers new questions correctly

That “student” is Scikit-learn!

How Scikit-learn Works (Step-by-Step)

Let’s make it SUPER simple:

Give It Data (Teach It )

Example:

Hours Studied Score

1 20

2 40

3 60

4 80

You are teaching:

“More study = higher score”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

13
It Learns the Pattern

Scikit-learn looks at the data and says:

“Oh! The score increases when hours increase!”

Ask It a Question

Now you ask:

“What happens if a student studies 5 hours?”

It Gives an Answer

It predicts:

“The score will be around 100”

Simple Python Example

from sklearn.linear_model import LinearRegression

# Step 1: Data (input and output)


X = [[1], [2], [3], [4]] # Hours studied
y = [20, 40, 60, 80] # Scores

# Step 2: Create the brain


model = LinearRegression()

# Step 3: Train the brain


[Link](X, y)

# Step 4: Ask a question


prediction = [Link]([[5]])

print(prediction)

What’s happening?

✓ [Link]() → Teaching the computer

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

14
✓ [Link]() → Asking the computer

Types of Things Scikit-learn Can Do

Predict Numbers (Regression )

Example:

✓ Predict house price

✓ Predict student score

Classify Things (Classification )

Example:

✓ Email → Spam or Not Spam

✓ Fruit → Apple or Orange

Group Things (Clustering )

Example:

✓ Group students by performance

✓ Group customers by behavior

Real-Life Examples

Email Spam Detection

✓ Input: Email message

✓ Output: Spam or Not Spam

Student Performance

✓ Input: Study hours

✓ Output: Expected score

Healthcare

✓ Input: Patient data

✓ Output: Possible illness

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

15
Simple Analogy

Scikit-learn is like:

Real Life Scikit-learn

Teacher Training data

Student Model

Learning fit()

Answering questions predict()

Why Scikit-learn is Powerful

✓ Easy to use

✓ Saves time

✓ Already has many smart algorithms

✓ Used by professionals all over the world

Final Summary (Very Easy)

Scikit-learn is a smart brain that:

1. Learns from examples

2. Understands patterns

3. Answers new questions

How Everything Works Together

Think of it like a team:

Tool Job

NumPy Works with numbers

Pandas Organizes data

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

16
Tool Job

Matplotlib Draws graphs

Scikit-learn Learns patterns

Full Simple Flow:

1. Collect data

2. Use Pandas to organize it

3. Use NumPy for calculations

4. Use Matplotlib to visualize

5. Use Scikit-learn to make predictions

Final Summary (Very Easy)

Python is like a boss


Libraries are like helpers

✓ NumPy → numbers

✓ Pandas → tables

✓ Matplotlib → graphs

✓ Scikit-learn → learning

Final Example (Real Life)

Imagine a school wants to:

✓ Predict which students may fail

They can:

✓ Use Pandas → store student data

✓ Use NumPy → calculate averages

✓ Use Matplotlib → show performance

✓ Use Scikit-learn → predict outcomes

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

17
Data Preprocessing
What is Data Preprocessing?

Before a computer can learn, we must prepare the data properly.

This is called Data Preprocessing

Simple Idea:

Data preprocessing is like washing and cutting food before cooking

✓ Dirty data → bad results

✓ Clean data → good results

1. Data Collection and Cleaning

Data Collection (Getting Data)

This means gathering information

Example:

You want to predict student performance:

You collect:

✓ Name

✓ Age

✓ Hours studied

✓ Score

Data Cleaning (Fixing Data)

This means removing:

✓ Errors

✓ Wrong values

✓ Duplicates

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

18
Example:

Bad data:

John - 5 hours - 80
Mary - ??? - 90
John - 5 hours - 80

Problems:

✓ Missing value (???)

✓ Duplicate (John appears twice)

Python Example (Cleaning)

import pandas as pd

data = {
"Name": ["John", "Mary", "John"],
"Hours": [5, None, 5],
"Score": [80, 90, 80]
}

df = [Link](data)

# Remove duplicates
df = df.drop_duplicates()

print(df)

2. Handling Missing Values

Sometimes data is incomplete

Example:

Name Hours Score


Mary ? 90

Ways to Fix It:

Option 1: Remove it

(Delete the row)


CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

19
Option 2: Fill it

(Use average or guess)

Python Example:

df["Hours"].fillna(df["Hours"].mean(), inplace=True)

This fills missing values with the average

3. Feature Scaling

Big words, simple idea

Different numbers may be too big or too small

We make them balanced

Example:

Feature Value

Age 15

Income 500,000

Problem:

✓ 500,000 is too big compared to 15

Two Methods:

Normalization (0 to 1 range)

Makes values between 0 and 1

Standardization (centered values)

Makes values around 0

Python Example:

from [Link] import StandardScaler

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

20
scaler = StandardScaler()
scaled_data = scaler.fit_transform([[15], [20], [25]])

print(scaled_data)

Simple Idea:

“Make all numbers speak the same language”

4. Encoding Categorical Variables

Some data are words, not numbers

Computers only understand numbers

Example:

Name Gender

John Male

Mary Female

Computer cannot understand "Male" or "Female"

Solution: Convert to numbers

Python Example:

from [Link] import LabelEncoder

le = LabelEncoder()

gender = ["Male", "Female", "Male"]


encoded = le.fit_transform(gender)

print(encoded)

Output:

[1 0 1]

Simple Idea:

“Change words into numbers so the computer understands”


CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

21
5. Train-Test Split

This is VERY IMPORTANT

Idea:

We divide data into two parts:

Part Purpose

Training Data To teach the computer

Testing Data To test if it learned well

Example:

You have 100 students:

✓ 80 → for training

✓ 20 → for testing

Real-life Example:

Like studying for exams:

✓ Study (training)

✓ Write exam (testing)

Python Example:

from sklearn.model_selection import train_test_split

X = [[1], [2], [3], [4], [5]]


y = [2, 4, 6, 8, 10]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

print(X_train, X_test)

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

22
Full Process (Very Simple)

1. Collect data

2. Clean data

3. Fix missing values

4. Scale numbers

5. Convert words to numbers

6. Split data (train & test)

Final Summary (Super Easy)

Data preprocessing is like preparing ingredients before cooking

If you skip it:


Bad results

If you do it well:
Smart predictions

One-Line Idea

“Clean and prepare your data before teaching the computer.”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

23
Exploratory Data Analysis (EDA)
What is EDA?

EDA means looking at your data carefully to understand it before using it.

Simple Definition:

EDA is like being a data detective

You:

✓ Look at the data

✓ Ask questions

✓ Find clues

Example:

Imagine you are a teacher with student scores.

Before predicting anything, you ask:

✓ Who scored highest?

✓ Who scored lowest?

✓ Do students who study more score better?

That is EDA!

1. Data Visualization Techniques

What is Data Visualization?

It means turning numbers into pictures (graphs)

Why?

Because:

✓ Pictures are easier to understand

✓ You can quickly see what is happening

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

24
Types of Simple Graphs

Line Chart (Shows change over time)

Example: Student scores over weeks

import [Link] as plt

scores = [50, 60, 70, 80]

[Link](scores)
[Link]("Student Scores")
[Link]()

Bar Chart (Compare things)

Example: Scores of students

names = ["John", "Mary", "Paul"]


scores = [80, 90, 70]

[Link](names, scores)
[Link]()

Pie Chart (Show parts of a whole)

Example: Pass vs Fail

labels = ["Pass", "Fail"]


values = [80, 20]

[Link](values, labels=labels)
[Link]()

Simple Idea:

“Graphs help you SEE your data clearly”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

25
2. Correlation Analysis

What is Correlation?

Correlation means:
How two things are related

Example:

Hours Studied Score

1 20

2 40

3 60

As study time increases, score increases

This is a positive correlation

Types of Correlation

Positive Correlation

✓ One goes up → the other goes up

Example: Study more → score higher

Negative Correlation

✓ One goes up → the other goes down

Example: Play more games → score lower

No Correlation

✓ No clear relationship

Example: Shoe size vs exam score

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

26
Python Example:

import pandas as pd

data = {
"Hours": [1, 2, 3, 4],
"Score": [20, 40, 60, 80]
}

df = [Link](data)

print([Link]())

Simple Idea:

“Correlation shows if two things are connected”

3. Identifying Patterns and Trends

What are Patterns?

Patterns are things that repeat

Example:

✓ Every time students study more → scores improve


That’s a pattern

What are Trends?

Trends show direction over time

Example:

• Scores keep increasing every week


That’s an upward trend

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

27
Real-Life Example:

Week Score

1 50

2 60

3 70

Trend = Going up

Python Example:

weeks = [1, 2, 3]
scores = [50, 60, 70]

[Link](weeks, scores)
[Link]()

What you see:

✓ A line going up → improvement

Putting It All Together

EDA helps you:

1. Draw graphs (visualization)

2. Check relationships (correlation)

3. Find patterns and trends

Final Summary (Super Easy)

EDA is like investigating your data before using it

• Visualization → See the data

• Correlation → Check connections

• Patterns/Trends → Find meaning

One-Line Idea

“EDA helps you understand your data before teaching the computer.”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

28
Supervised Learning – Regression
What is Regression?

Regression is a type of Machine Learning used to:

predict numbers

Simple Examples:

✓ Predict a student’s score

✓ Predict house price

✓ Predict temperature

Easy Idea:

“Regression helps computers guess numbers based on patterns”

1. Linear Regression

What is Linear Regression?

It finds a straight-line relationship between two things

Example:

Hours Studied Score

1 20

2 40

3 60

4 80

We can see:

✓ As hours increase → score increases

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

29
Don’t worry about the big letters

• x = input (hours studied)

• y = output (score)

• The line helps us predict new values

Python Example:

from sklearn.linear_model import LinearRegression

X = [[1], [2], [3], [4]]


y = [20, 40, 60, 80]

model = LinearRegression()
[Link](X, y)

prediction = [Link]([[5]])
print(prediction)

Output:
100

Meaning:

If a student studies 5 hours → score ≈ 100

2. Multiple Regression

What is Multiple Regression?

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

30
It uses more than one factor to predict

Example:

Hours Studied Sleep Hours Score

2 8 50

3 7 60

4 6 70

Now score depends on:

✓ Study time

✓ Sleep

Python Example:

from sklearn.linear_model import LinearRegression

X=[
[2, 8],
[3, 7],
[4, 6]
]

y = [50, 60, 70]

model = LinearRegression()
[Link](X, y)

prediction = [Link]([[5, 7]])


print(prediction)

Simple Idea:

“More information = better prediction”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

31
3. Model Training and Prediction

Training

Training means:
teaching the computer using data

Example:

[Link](X, y)

You are saying:


“Learn from this data”

Prediction

Prediction means:
asking the computer a question

Example:

[Link]([[5]])

You are asking:


“What happens when x = 5?”

Simple Idea:

✓ Training = learning

✓ Prediction = answering

4. Evaluation Metrics (How Good is the Model?)

After teaching the computer, we must ask:

“Did it learn well?”

1. Mean Squared Error (MSE)

What is MSE?

It measures how wrong the predictions are

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

32
Formula:

1
𝑀𝑆𝐸 = ∑(𝑦𝑡𝑟𝑢𝑒 − 𝑦𝑝𝑟𝑒𝑑 )2
𝑛

Simple Example:

Real Score Predicted

80 78

90 85

Errors:

✓ 80 - 78 = 2

✓ 90 - 85 = 5

MSE looks at these errors

Meaning:

✓ Small MSE = Good model

✓ Big MSE = Bad model

2. R² Score (How Good the Fit is)

What is R²?

It shows how well the model explains the data

Simple Idea:

• R² = 1 → Perfect prediction

• R² = 0 → Very bad

Python Example:

from [Link] import mean_squared_error, r2_score

y_true = [20, 40, 60]


y_pred = [22, 38, 65]

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

33
print(mean_squared_error(y_true, y_pred))
print(r2_score(y_true, y_pred))

Putting It All Together

1. Collect data

2. Train model

3. Make predictions

4. Check accuracy

Final Summary (Very Easy)

Regression = predicting numbers

✓ Linear → one input

✓ Multiple → many inputs

✓ Training → teaching

✓ Prediction → answering

✓ MSE → how wrong

✓ R² → how good

One-Line Idea

“Regression teaches computers to predict numbers using patterns.”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

34
Supervised Learning – Classification
What is Classification?

Classification is a type of Machine Learning where the computer:

puts things into groups (categories)

Simple Examples:

✓ Email → Spam or Not Spam

✓ Fruit → Apple or Orange

✓ Student → Pass or Fail

Easy Idea:

“Classification is about choosing the correct label”

1. Logistic Regression

What is Logistic Regression?

It helps us answer YES or NO questions

Example:

Will a student pass?

Hours Studied Result

1 Fail

5 Pass

Logistic Regression learns:

✓ Small hours → Fail

✓ Big hours → Pass

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

35
Python Example:

from sklearn.linear_model import LogisticRegression

X = [[1], [2], [3], [4]]


y = [0, 0, 1, 1] # 0 = Fail, 1 = Pass

model = LogisticRegression()
[Link](X, y)

print([Link]([[3]]))

Output: 1 (Pass)

Simple Idea:

“It answers YES or NO (0 or 1)”

2. K-Nearest Neighbors (KNN)

What is KNN?

It looks at nearby examples and decides

Example:

You want to classify a fruit

Nearby fruits are:

✓ Apple

✓ Apple

✓ Orange

Majority = Apple
So it predicts: Apple

Python Example:

from [Link] import KNeighborsClassifier

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

36
X = [[1], [2], [3], [4]]
y = [0, 0, 1, 1]

model = KNeighborsClassifier(n_neighbors=3)
[Link](X, y)

print([Link]([[2.5]]))

Simple Idea:

“Look at your neighbors and follow the majority”

3. Decision Trees

What is a Decision Tree?

It works like a flowchart of questions

Example:

“Will student pass?”

Did student study more than 3 hours?



YES → Pass
NO → Fail

Python Example:

from [Link] import DecisionTreeClassifier

X = [[1], [2], [3], [4]]


y = [0, 0, 1, 1]

model = DecisionTreeClassifier()
[Link](X, y)

print([Link]([[2]]))

Simple Idea:

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

37
“Ask questions step by step to decide”

4. Support Vector Machines (SVM)

What is SVM?

It draws a line to separate groups

Example:

Imagine this:

✓ Apples on one side

✓ Oranges on the other

SVM draws a line between them

Separation Line:

𝑎𝑥 + 𝑏𝑦 + 𝑐 = 0

This line separates the groups

Python Example:

from [Link] import SVC

X = [[1], [2], [3], [4]]


y = [0, 0, 1, 1]

model = SVC()
[Link](X, y)

print([Link]([[3]]))

Simple Idea:

“Draw a line to separate different groups”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

38
Putting It All Together

Method How it Works

Logistic Regression Yes/No decision

KNN Follow neighbors

Decision Tree Ask questions

SVM Draw a separating line

Real-Life Examples

Spam Detection

✓ Logistic Regression → Spam or Not

Shopping Recommendation

✓ KNN → Suggest similar items

Student Result

✓ Decision Tree → Pass or Fail

Image Recognition

✓ SVM → Separate objects

Final Summary (Super Easy)

Classification = grouping things

✓ Logistic → Yes/No

✓ KNN → Follow neighbors

✓ Tree → Ask questions

✓ SVM → Draw line

One-Line Idea

“Classification helps computers decide which group something belongs to.”


CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

39
Model Evaluation and Validation
What is Model Evaluation?

After teaching a computer (model), we must ask:

“Did it learn well or not?”

Simple Idea:

Model evaluation is like:

✓ Writing an exam

✓ Checking your score

1. Confusion Matrix (But it’s actually simple!)

What is a Confusion Matrix?

It is a table that shows:

✓ What the computer predicted

✓ What the real answer was

Example: Spam Detection

Predicted Spam Predicted Not Spam

Actual Spam Correct Wrong

Actual Not Spam Wrong Correct

The 4 Important Parts:

Name Meaning

True Positive (TP) Correctly said “Yes”

True Negative (TN) Correctly said “No”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

40
Name Meaning

False Positive (FP) Said “Yes” but wrong

False Negative (FN) Said “No” but wrong

Simple Idea:

“It shows where the model is right and wrong”

2. Accuracy, Precision, Recall, F1-score

These are scores that tell us how good the model is.

Accuracy (Overall Score)

“How many did we get correct?”

Formula:

𝑇𝑃 + 𝑇𝑁
𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦 =
𝑇𝑃 + 𝑇𝑁 + 𝐹𝑃 + 𝐹𝑁

What is this formula?

𝑇𝑃 + 𝑇𝑁
𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦 =
𝑇𝑃 + 𝑇𝑁 + 𝐹𝑃 + 𝐹𝑁

This is called the Accuracy formula in Machine Learning.

It tells us:

“How often did the computer get the answer right?”

Step 1: What is Accuracy?

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

41
Accuracy means:
“How many predictions were correct out of all predictions?”

Step 2: Understand the letters (TP, TN, FP, FN)

Let’s make it super simple

TP = True Positive

The computer said YES and it was correct

Example:

✓ Email is Spam

✓ Computer says “Spam”

TN = True Negative

The computer said NO and it was correct

Example:

✓ Email is NOT Spam

✓ Computer says “Not Spam”

FP = False Positive

The computer said YES but it was wrong

Example:

✓ Email is NOT Spam

✓ Computer says “Spam”

FN = False Negative

The computer said NO but it was wrong

Example:

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

42
✓ Email is Spam

✓ Computer says “Not Spam”

Step 3: What the formula is doing

Formula meaning:

✓ Top (numerator) = correct answers


TP + TN

✓ Bottom (denominator) = all answers


TP + TN + FP + FN

Step 4: Simple Meaning

Accuracy =

“Number of correct answers ÷ Total answers”

Step 5: Easy Example

Imagine a computer checked 10 emails

Type Count

TP (correct Spam) 4

TN (correct Not Spam) 3

FP (wrong Spam) 2

FN (wrong Not Spam) 1

Now calculate:

Correct = 4 + 3 = 7
Total = 4 + 3 + 2 + 1 = 10

Accuracy:
CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

43
7
𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦 =
10

Accuracy = 0.7 = 70%

Final Simple Idea

Accuracy tells us:

“Out of everything the computer tried, how many did it get right?”

Easy Real-Life Example

Imagine a game:

✓ You answer 10 questions

✓ You get 7 correct

Your accuracy = 70%

One-Line Memory Trick

“Accuracy = Correct answers ÷ All answers”

Precision (Quality of YES answers)

Formula:

𝑇𝑃
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 =
𝑇𝑃 + 𝐹𝑃

What is this formula?

𝑇𝑃
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 =
𝑇𝑃 + 𝐹𝑃

This is called Precision in Machine Learning.

Simple Meaning
CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

44
Precision means:

“When the computer says YES, how often is it actually correct?”

Step 1: Understand the parts

TP = True Positive

Computer says YES and it is correct

Example:

✓ Email is Spam

✓ Computer says “Spam”

FP = False Positive

Computer says YES but it is wrong

Example:

✓ Email is NOT Spam

✓ Computer says “Spam”

Step 2: What the formula is doing

✓ Top (TP) = correct YES answers

✓ Bottom (TP + FP) = all YES answers the computer gave

Step 3: Simple Explanation

Precision is:

“Out of everything the computer called YES, how many were actually correct?”

Step 4: Easy Example

Imagine a spam detector :

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

45
Case Result

TP 5 correct spam detections

FP 2 wrong spam detections

Now calculate:

5
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 =
5+2

Precision = 5 / 7 ≈ 0.71 (71%)

Step 5: What does this mean?

Out of all emails the computer said were “Spam”:

✓ 71% were actually spam

✓ 29% were mistakes

Real-Life Example

Imagine a friend says:

“All these are apples ”

But:

✓ Some are apples

✓ Some are oranges

Precision tells us:

“How many times was your friend correct when they said ‘apple’?”

Easy Comparison

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

46
Term Meaning

Accuracy Overall correctness

Precision Correctness of YES predictions

One-Line Memory Trick

“Precision = When I say YES, how often am I right?”

Example:

If model says “Spam” 5 times:

• 4 correct

• 1 wrong

Precision = 4/5 = 80%

Simple Idea:

“When I say YES, am I sure?”

Recall (Catching all YES cases)

“Did I find all the real YES cases?”

Formula:

𝑇𝑃
𝑅𝑒𝑐𝑎𝑙𝑙 =
𝑇𝑃 + 𝐹𝑁

Example:

If there are 10 spam emails:

• You detect 7

Recall = 70%

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

47
Simple Idea:

“Did I miss anything important?”

F1-Score (Balance Score)

Combines Precision and Recall

Formula:

𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 ⋅ 𝑅𝑒𝑐𝑎𝑙𝑙
𝐹1 = 2 ⋅
𝑃𝑟𝑒𝑐𝑖𝑠𝑖𝑜𝑛 + 𝑅𝑒𝑐𝑎𝑙𝑙

Simple Idea:

“Balance between being correct and not missing things”

3. Cross-Validation

What is Cross-Validation?

Instead of testing once, we test many times

Example:

You have 100 data points:

✓ Split into 5 parts

✓ Train on 4 parts

✓ Test on 1 part

✓ Repeat 5 times

Real-Life Example:

Like practicing for exams:

✓ You don’t test yourself once

✓ You test many times


CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

48
Simple Idea:

“Test again and again to be sure”

4. Overfitting vs Underfitting

Overfitting (Too Much Learning )

The model memorizes everything

Example:

A student:

✓ Memorizes answers

✓ Fails new questions

Problem:

✓ Works well on training data

✓ Fails in real life

Underfitting (Not Learning Enough )

The model doesn’t learn properly

Example:

A student:

✓ Didn’t study enough

✓ Fails exam

Problem:

✓ Bad on training and testing

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

49
Good Model (Balanced )

Learns just enough:

✓ Works on new data

✓ Makes good predictions

Simple Table:

Type Problem

Overfitting Too much learning

Underfitting Too little learning

Good Fit Balanced learning

Putting It All Together

1. Use Confusion Matrix → See errors

2. Use Accuracy, Precision, Recall → Measure performance

3. Use Cross-validation → Test many times

4. Avoid Overfitting/Underfitting → Stay balanced

Final Summary (Super Easy)

Model evaluation is like checking how smart your model is

✓ Confusion Matrix → Right vs wrong

✓ Accuracy → Overall score

✓ Precision → Correct YES

✓ Recall → Find all YES

✓ F1 → Balance

✓ Cross-validation → Test many times


CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

50
✓ Overfitting/Underfitting → Avoid extremes

One-Line Idea

“Model evaluation helps us know if our computer is truly smart or just guessing.”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

51
Unsupervised Learning
What is Unsupervised Learning?

Unsupervised learning is a part of Machine Learning where:

The computer learns WITHOUT answers

Simple Idea:

✓ No teacher

✓ No correct answers

✓ The computer finds patterns by itself

Example:

Imagine giving a child a box of mixed items:

✓ Apples

✓ Oranges

✓ Bananas

You don’t tell them anything


They group similar fruits together

That is unsupervised learning!

1. Clustering (Grouping Similar Things)

What is Clustering?

Clustering means:

“Grouping similar things together”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

52
Example:

Imagine a school wants to group students:

✓ Group 1: High scorers

✓ Group 2: Average students

✓ Group 3: Low scorers

But the computer is NOT told the groups


It discovers them itself

1.1 K-Means Clustering

What is K-Means?

It groups data into K number of clusters

Simple Example:

You choose K = 3:

✓ 3 groups of students

✓ Computer sorts them automatically

How it works (simple steps):

1. Pick K groups

2. Put random centers (centroids)

3. Assign each point to nearest center

4. Move centers

5. Repeat until stable

Python Example:

from [Link] import KMeans

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

53
data = [[1], [2], [3], [10], [11], [12]]

model = KMeans(n_clusters=2)
[Link](data)

print(model.labels_)

Simple Idea:

“Put similar things near each other”

1.2 Hierarchical Clustering

What is it?

It builds a tree of groups

Example:

Start with all students separate:

Then:

✓ Combine closest students

✓ Then combine groups

✓ Until everything becomes one big tree

Picture Idea:

All Students
/ \
Group A Group B
/ \ / \
A1 A2 B1 B2

Simple Idea:

“Build groups step-by-step like a family tree”


CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

54
2. Dimensionality Reduction

What is it?

It means:

“Making big data smaller but still useful”

Example:

Imagine a student profile:

✓ Age

✓ Height

✓ Weight

✓ Study hours

✓ Sleep hours

✓ Attendance

Too many features!

We reduce them into fewer important ones.

2.1 Principal Component Analysis (PCA)

What is PCA?

PCA finds the most important information in data

Simple Example:

Instead of 6 features:

✓ It keeps only 2 or 3 important ones

Real-Life Example:

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

55
Imagine compressing a big photo:

✓ Original: 10 MB

✓ After PCA: 2 MB

✓ Still looks almost the same

Python Example:

from [Link] import PCA

data = [[1,2], [2,3], [3,4], [4,5]]

pca = PCA(n_components=1)
new_data = pca.fit_transform(data)

print(new_data)

Simple Idea:

“Keep only the most important information”

Summary of Module 8

Topic Simple Meaning

Clustering Group similar things

K-Means Make K groups

Hierarchical Tree-like grouping

PCA Reduce data size

Final Easy Explanation

Unsupervised learning is like:

✓ A child exploring a room

✓ Without instructions

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

56
✓ But still finding patterns

One-Line Memory Trick

“Unsupervised learning = computer finds patterns without being told”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

57
Ensemble Learning
What is Ensemble Learning?

Ensemble learning is a part of Machine Learning where:

“We combine MANY small models to make ONE strong model.”

Simple Idea:

Instead of asking one person for advice, you ask:

✓ 10 people

✓ Then you choose the most common answer

That is ensemble learning!

Why do we use it?

Because:

✓ One model can make mistakes

✓ Many models together are more accurate

1. Bagging (Bootstrap Aggregating)

What is Bagging?

Bagging means:

“Train many models on different random parts of data, then combine results.”

Simple Example:

Imagine you want to know:


“Is this fruit an apple?”

You ask:

✓ Friend 1

✓ Friend 2

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

58
✓ Friend 3 (wrong)

✓ Friend 4

Most say “apple” → final answer = apple

How it works:

1. Split data into random samples

2. Train many models

3. Each model gives answer

4. Take majority vote

Python Example:

from [Link] import BaggingClassifier


from [Link] import DecisionTreeClassifier

model = BaggingClassifier(
estimator=DecisionTreeClassifier(),
n_estimators=10
)

Simple Idea:

“Many small brains vote together”

2. Boosting

What is Boosting?

Boosting means:

“Train models one after another, each one fixes mistakes of the previous one.”

Simple Example:

Imagine learning math:

✓ Student 1 makes mistakes

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

59
✓ Teacher focuses on those mistakes

✓ Student 2 improves

✓ Student 3 improves more

Final result = very strong understanding

How it works:

1. Model 1 learns

2. Model 2 focuses on mistakes

3. Model 3 fixes more mistakes

4. Continue improving

Python Example:

from [Link] import AdaBoostClassifier


from [Link] import DecisionTreeClassifier

model = AdaBoostClassifier(
estimator=DecisionTreeClassifier(max_depth=1),
n_estimators=50
)

Simple Idea:

“Each model learns from previous mistakes”

3. Random Forest

What is Random Forest?

Random Forest is:

“A collection of many decision trees working together.”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

60
Simple Example:

Imagine asking:
“Should I play football today?”

You ask many trees:

✓ Tree 1 → Yes

✓ Tree 2 → No

✓ Tree 3 → Yes

✓ Tree 4 → Yes

Final answer = YES

Why “Random”?

Because:

✓ Each tree sees different random data

✓ Each tree makes independent decisions

Python Example:

from [Link] import RandomForestClassifier

model = RandomForestClassifier(n_estimators=100)

Simple Idea:

“A forest of decision trees voting together”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

61
Summary Table

Method Simple Meaning

Bagging Many models vote together

Boosting Models improve step by step

Random Forest Many decision trees combined

Final Easy Explanation

Ensemble learning is like:

✓ Asking many friends

✓ Not trusting just one person

✓ Combining opinions for a better answer

One-Line Memory Trick

“Many weak models together = one strong model”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

62
Introduction to Neural Networks
What are Neural Networks?

Neural Networks are part of Machine Learning.

They are computer systems that try to think like the human brain.

Simple Idea:

Your brain has:

✓ Neurons (tiny brain cells)

✓ They send messages to each other

Neural networks do the same thing using numbers!

Real-Life Example:

Imagine teaching a child to recognize a cat :

You say:

✓ Has whiskers

✓ Has ears

✓ Says meow

The child learns patterns → “This is a cat”

Neural networks learn the same way!

1. Artificial Neural Networks (ANN)

What is ANN?

ANN = A system of connected “artificial neurons” that learn patterns.

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

63
Simple Structure:

Input → Hidden Layers → Output

Example:

You want to predict:


“Will it rain today?”

Inputs:

✓ Cloudy

✓ Humidity

✓ Wind

Output:

✓ Rain or No Rain

Simple Idea:

“ANN is a network that learns from examples”

2. Perceptron Model

What is a Perceptron?

A perceptron is the simplest brain cell of AI

It:

✓ Takes inputs

✓ Adds them

✓ Makes a decision (YES or NO)

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

64
Example:

Imagine a robot deciding:

“Should I go outside?”

Inputs:

✓ Is it raining?

✓ Do I have an umbrella?

Decision:

Condition Result

Rain + No umbrella Stay inside

Rain + Umbrella Go outside

Simple Idea:

“Perceptron = a yes/no decision maker”

Simple Formula Idea:

Inputs × Weights → Add → Decision

(Weights = importance of each input)

3. Activation Functions

What are Activation Functions?

They are like a decision switch

They decide:

“Should the neuron turn ON or OFF?”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

65
Simple Example:

Think of a light bulb :

✓ If switch is ON → light shines

✓ If OFF → no light

Activation function = switch

Common Types (Simple Explanation)

1. Step Function

Only two outputs:

✓ 0 (OFF)

✓ 1 (ON)

Example:

✓ If score > 50 → Pass

✓ Else → Fail

2. Sigmoid Function

Gives values between 0 and 1

Example:

✓ 0.9 → Very likely YES

✓ 0.2 → Very likely NO

Used in:
Yes/No predictions (like spam detection )

3. ReLU Function

If number is:

✓ Negative → becomes 0

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

66
✓ Positive → stays the same

Example:

✓ -5 → 0

✓ 10 → 10

Simple Idea:

“Activation function decides if neuron should react or not”

Summary Table

Topic Simple Meaning

ANN Brain-like system of computers

Perceptron Simple yes/no decision maker

Activation Function Switch that controls output

Final Easy Explanation

Neural networks are like:

✓ A brain made of tiny decision-makers

✓ Each one checks information

✓ Then they work together to make predictions

One-Line Memory Trick

“Neural network = many tiny decision brains working together”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

67
Deep Learning Basics
What is Deep Learning?

Deep Learning is part of Machine Learning.

It is a way of teaching computers to learn using very big neural networks.

Simple Idea:

Think of it like this:

Human Brain vs Deep Learning

✓ Human brain = learns by experience

✓ Deep learning computer = learns from lots of data (thousands or millions of examples)

Real-Life Example:

Teaching a computer to recognize cats :

✓ Show 100 pictures → it learns a little

✓ Show 10,000 pictures → it becomes smart

✓ Show 1,000,000 pictures → it becomes very accurate!

That is deep learning!

1. Introduction to Deep Learning

What makes it “Deep”?

“Deep” means:

Many layers of learning inside the neural network

Simple Structure:

Input → Layer 1 → Layer 2 → Layer 3 → Output

Each layer learns something:


CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

68
✓ Layer 1 → simple shapes (lines, edges)

✓ Layer 2 → parts (eyes, ears)

✓ Layer 3 → full object (cat )

Simple Idea:

“Deep learning = learning in many steps (layers)”

Example:

Self-driving car

It learns:

✓ Road lines

✓ Traffic signs

✓ Cars and people

✓ Speed and direction

2. TensorFlow

What is TensorFlow?

TensorFlow is a tool (library) used to build deep learning models.

It is like:

“A big toolbox for building AI brains”

Simple Example:

Imagine building a robot :

You need tools:

✓ Screws

✓ Wires

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

69
✓ Engine

TensorFlow gives you tools to build AI brains.

Simple Python Example:

import tensorflow as tf

model = [Link]([
[Link](10, activation='relu'),
[Link](1)
])

Simple Idea:

“TensorFlow helps build AI models step-by-step”

3. Keras

What is Keras?

Keras is a simple version of TensorFlow

It makes building AI:

✓ Easier

✓ Faster

✓ More beginner-friendly

Simple Example:

Think of:

✓ TensorFlow = big engine workshop

✓ Keras = easy remote control

Simple Python Example:

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

70
from tensorflow import keras

model = [Link]([
[Link](8, activation='relu'),
[Link](1, activation='sigmoid')
])

Simple Idea:

“Keras makes deep learning easy to write”

Summary Table

Topic Simple Meaning

Deep Learning AI that learns using many layers

TensorFlow Tool for building AI models

Keras Easy way to use TensorFlow

Final Easy Explanation

Deep learning is like:

✓ A very smart brain

✓ That learns from many examples

✓ And improves over time

One-Line Memory Trick

“Deep learning = many-layer brain that learns from lots of data”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

71
Model Deployment
What is Model Deployment?

Model deployment is part of Machine Learning.

It means:

“Putting your trained AI model into real life so people can use it.”

Simple Idea:

Think of it like this:

✓ You trained a smart robot brain (model)

✓ Now you want people to actually use it

Deployment = “making the robot available to everyone”

Real-Life Example:

You built a model that predicts:

“Will it rain today? ”

Now deployment means:

✓ Putting it in an app

✓ Or a website

✓ Or a system that others can use

1. Saving Models

Why save a model?

After training your model:


You don’t want to train it again every time

So you save it like a file.

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

72
Simple Example:

Think of it like:

✓ Writing your homework in a notebook

✓ So you can use it later without starting again

1.1 Pickle

Pickle is a tool that saves your model into a file.

Example:

import pickle

# save model
with open("[Link]", "wb") as file:
[Link](model, file)

Load it back:

with open("[Link]", "rb") as file:


model = [Link](file)

Simple Idea:

“Pickle stores your AI brain in a file”

1.2 Joblib

Joblib is similar to Pickle but better for big models.

Example:

import joblib

[Link](model, "[Link]")

Load it:

model = [Link]("[Link]")

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

73
Simple Idea:

“Joblib = stronger storage for big AI models”

2. Building Simple ML APIs

What is an API?

An API (Application Programming Interface) is like a messenger that helps two different systems talk
to each other.

“A way for apps to talk to your AI model”

It is part of Machine Learning and software development.

Think of an API like a waiter in a restaurant

How it works:

✓ You (customer) = user or app

✓ Waiter = API

✓ Kitchen = computer system or AI model

✓ Food = result (data or answer)

Example:

You go to a restaurant and say:

“I want a burger”

The waiter (API):

✓ Takes your order

✓ Gives it to the kitchen

✓ Brings back your burger

You don’t go into the kitchen yourself.

That is exactly how an API works.

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

74
In Technology

An API lets:

✓ Apps talk to servers

✓ Websites get data

✓ AI models give predictions

Simple Example:

Imagine a restaurant :

✓ You (customer) give order

✓ Waiter (API) takes order

✓ Chef (AI model) prepares food

✓ Waiter brings result back

In AI:

✓ User sends input

✓ API sends it to model

✓ Model gives prediction

✓ API returns result

Simple Flask API Example:

from flask import Flask, request


import joblib

app = Flask(__name__)
model = [Link]("[Link]")

@[Link]('/predict', methods=['POST'])
def predict():
data = [Link]

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

75
result = [Link]([data['value']])
return {"prediction": [Link]()}

Simple Idea:

“API = bridge between users and AI model”

3. Introduction to Cloud Deployment

What is Cloud Deployment?

Cloud deployment means:

“Putting your AI model on the internet so anyone can use it anytime”

Simple Example:

Think of:

✓ Your model is a shop

✓ Cloud is a big shopping mall

✓ Anyone from anywhere can visit

Real-Life Example:

Instead of running AI on your laptop :


You upload it to cloud services like:

✓ Google Cloud

✓ AWS

✓ Azure

Simple Idea Flow:

User → Internet → Cloud API → AI Model → Result

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

76
Simple Idea:

“Cloud deployment makes your AI available everywhere”

Summary Table

Topic Simple Meaning

Model Deployment Making AI usable in real life

Pickle Save model like a file

Joblib Better way to save big models

API Bridge between user and AI

Cloud Hosting AI online

Final Easy Explanation

Model deployment is like:

✓ Training a smart brain

✓ Packing it into a box

✓ Putting it online

✓ So everyone can use it anytime

One-Line Memory Trick

“Deployment = turning AI model into a real-world app”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

77
Ethics in Machine Learning
Ethics in Machine Learning is part of Machine Learning.

It means:

“Teaching computers to be fair, safe, and responsible when making decisions.”

Why is Ethics Important?

Because AI is now used in:

✓ Schools

✓ Hospitals

✓ Banks

✓ Social media

If AI is not fair, it can cause big problems.

1. Bias and Fairness

What is Bias?

Bias means:

“The AI is unfair because it learned wrong or incomplete information.”

Simple Example:

Imagine a teacher only teaches boys math


and ignores girls

Boys will perform better just because they got more attention
That is unfair learning

In AI:

If a model is trained mostly on:

• Men’s faces

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

78
• It may not recognize women’s faces well

That is bias

Another Example:

A job AI system says:

✓ “Only men are suitable for engineers”

That is unfair and wrong

Fairness means:

AI should treat everyone equally regardless of:

✓ Gender

✓ Race

✓ Age

✓ Background

2. Data Privacy

What is Data Privacy?

Data privacy means:

“Protecting people’s personal information.”

Simple Example:

Imagine your diary

✓ You don’t want everyone to read it

✓ It contains your secrets

That is your private data

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

79
In AI:

AI systems may collect:

✓ Your name

✓ Your location

✓ Your photos

✓ Your search history

If not protected, hackers can steal it

Example:

A shopping app knows:

✓ What you buy

✓ Where you live

It must keep that information safe

Simple Rule:

“Your data should be used safely and not misused”

3. Responsible AI

What is Responsible AI?

Responsible AI means:

“Building AI that is safe, fair, and helpful to humans.”

Simple Example:

Imagine you build a robot friend

You must make sure:

✓ It does not lie

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

80
✓ It does not harm people

✓ It treats everyone fairly

In Real Life:

Responsible AI means:

✓ Doctors can trust AI in hospitals

✓ Students can use AI for learning

✓ Banks use AI safely for loans

Example:

A responsible AI:

✓ Suggests helpful study tips

✓ But does NOT cheat for students

Summary Table

Topic Simple Meaning

Bias AI being unfair

Fairness Treating everyone equally

Data Privacy Keeping personal info safe

Responsible AI Building safe and helpful AI

Final Easy Explanation

Ethics in AI means:

✓ AI should be fair

✓ AI should protect privacy

✓ AI should not harm people

One-Line Memory Trick

“Ethical AI = Fair + Safe + Responsible”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

81
Real-World Applications
This module shows how Machine Learning is used in real life every day.

It means:

“Using AI to solve real problems in the world.”

1. Predictive Analytics

What is it?

Predictive analytics means:

“Using past data to guess what will happen in the future.”

Simple Example:

Imagine you always eat lunch at 1 PM

Your body starts feeling hungry before 1 PM.

Your brain predicts: “It’s almost lunch time!”

In AI:

AI looks at past data and predicts:

✓ Will it rain tomorrow?

✓ Will a student pass exam?

✓ Will a customer buy something?

Example:

A school uses AI to predict:


“Which student may fail exams?”

So teachers can help early

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

82
2. Fraud Detection

What is it?

Fraud detection means:

“Finding fake or illegal activities.”

Simple Example:

Imagine someone uses your toy money without permission

That is cheating (fraud).

In AI:

Banks use AI to detect:

✓ Fake transactions

✓ Stolen credit cards

✓ Unusual spending

Example:

If your card is used in:

• Nigeria 🇳🇬

• and 2 minutes later in USA 🇺🇸

AI says: “This is suspicious!”

3. Recommendation Systems

What is it?

Recommendation systems mean:

“AI suggesting things you may like.”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

83
Simple Example:

You watch cartoons on YouTube


Then YouTube suggests more cartoons.

That is a recommendation system!

In AI:

Used in:

✓ Netflix (movies)

✓ YouTube (videos)

✓ Amazon (shopping)

✓ Spotify (music)

Example:

If you like football videos


AI suggests:

✓ More football videos

✓ Football highlights

4. Image and Text Classification

What is Classification?

Classification means:

“Putting things into groups or categories.”

Image Classification

AI looks at images and says what they are.

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

84
Example:

AI sees a picture:

✓ → “Cat”

✓ → “Dog”

✓ → “Car”

Real Life:

✓ Face unlock on phones

✓ Google Photos sorting pictures

Text Classification

AI reads text and understands meaning.

Example:

Email:

✓ “Win $1,000,000 now!”


Spam

✓ “Your school results are ready”


Not spam

Used in:

✓ Spam detection

✓ Sentiment analysis (happy or sad messages)

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

85
Summary Table

Application Simple Meaning

Predictive Analytics Predict future events

Fraud Detection Find cheating or fake activity

Recommendation Systems Suggest things you like

Image Classification Identify pictures

Text Classification Understand words/messages

Final Easy Explanation

AI in real life is like:

✓ A smart helper

✓ That predicts things

✓ Detects problems

✓ And recommends useful things

One-Line Memory Trick

“AI helps us predict, protect, suggest, and understand”

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

86
HOW TO SET UP VS CODE FOR MACHINE LEARNING (STEP BY STEP)

STEP 1: Install VS Code

Download here:
[Link]

Install it normally:

✓ Click “Next” → “Next” → “Finish”

✓ Open VS Code after installation

STEP 2: Install Python

Download Python:
[Link]

IMPORTANT during install:

✔ Check “Add Python to PATH”


✔ Click Install

✔ Test Python works:

Open Command Prompt (CMD) and type:

python --version

If you see something like:

Python 3.x.x

You are good

STEP 3: Install VS Code Extensions

Open VS Code → go to:

Extensions (left sidebar)

Install:

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

87
1. Python (by Microsoft)

2. Pylance (for smart suggestions)

STEP 4: Create Your Project Folder

1. Create a folder on your computer:

ML_Project

2. Open VS Code

3. Click:

File → Open Folder → ML_Project

STEP 5: Create Your First Python File

Inside VS Code:

Create file:

[Link]

STEP 6: Install Machine Learning Libraries

Open VS Code terminal:

Click:
Terminal → New Terminal

Then run:

pip install numpy pandas matplotlib scikit-learn

CSC 413: MACHINE LEARNING WITH PYTHON. Compiled By: Mr Michael Dominic

88

You might also like