Practical AI with
Python
Unlocking the power of coding and artificial
intelligence
Session 10: Introduction to Deep Learning
Copyright © Laura Wang 2025
Curriculum
Practical AI and Python
Class Content Tasks:
1 Introduction to Python and AI - Intelligent Greetings Write a simple AI greeting program
2 Conditions and AI Decision Making Design an AI "selector"
3 Loops and AI Pattern Recognition Use loops to detect simple patterns
4 Functions and AI Modularization Write AI "helper" functions
5 Data Structures and AI Data Foundations Use data structures to store and analyze small datasets
6 Files and AI Data Collection Read data from files and generate simple AI suggestions
7 Visualization and AI Insights Visualize datasets and extract AI insights using simple rules
8 Introduction to Machine Learning with Python Train an AI model with Python to predict values
9 Classification and AI Decision Trees Build an AI classifier
10 Introduction to Deep Learning Review projects and explore projects for after class study
Copyright © Laura Wang 2025 2
Practical AI and Python
Agenda
● Deep Learning
● Neural Networks
● How do Neural Networks work?
● Types of Neural Networks: CNN RNN
● Neural networks comparison
Copyright © Laura Wang 2025 3
Practical AI and Python
Warm up and Review
● Quiz:
○ How does a Random Forest reduce overfitting compared to a single Decision Tree? (Select
all that apply.)
A) By averaging predictions from multiple trees.
B) By restricting each tree to a random subset of features.
C) By pruning all trees to the same depth.
D) By training on bootstrapped samples of the data.
Answer: A, B, D (C is incorrect—trees in a Random Forest are typically not pruned to the same
depth).
Copyright © Laura Wang 2025 4
Practical AI and Python
Deep Learning
● Deep Learning is a subset of Artificial Intelligence
(AI) that enables learning from large sets of data.
● It uses neural networks with 3+ layers to find
patterns and make predictions.
● Deep learning models doesn’t need manual feature
extraction. Learning is directly from data.
● Applications of Deep Learning: chatbot, LLM,
self-driving cars, medical image analysis, search
engines, recommendation systems, and many more.
Copyright © Laura Wang 2025 5
Practical AI and Python
Neural networks
● A neural network is an AI model that makes decisions like the
human brain, using processes that mimic how biological neurons
work together to identify phenomena, weigh options, and arrive at
conclusions.
● Neural network consists of an input layer, one or more hidden
layers, and an output layer.
● Each layer consists of nodes, also called artificial neurons.
● Each node connects to others and has its associated weight and
threshold.
● Layers organize nodes into structures that process data
sequentially, while nodes are the individual computational
elements that perform transformations on the input data.
Copyright © Laura Wang 2025 6
Practical AI and Python
How do neural networks work?
● Think about how the human brain works.
● A neural network is composed of interconnected artificial neurons that collaborate to address a
specific issue.
● Artificial neurons are software modules, called nodes, and artificial neural networks are
software programs or algorithms that, at their core, use computing systems to solve
mathematical calculations.
● Input Layer takes information from the outside world. Input nodes process the data, analyze or
categorize it, and pass it on to the next layer.
● Hidden Layers take input from the input layer or other hidden layers. Each hidden layer
analyzes the output from the previous layer, processes it further, and passes it on to the next
layer.
● Output Layer generates the output results. It can have single or multiple nodes.
Copyright © Laura Wang 2025 7
Practical AI and Python
Types of neural networks
● Convolutional neural networks (CNNs) are usually utilized for image recognition, pattern
recognition, and/or computer vision.
○ These networks harness principles from linear algebra, particularly matrix multiplication,
to identify patterns within an image.
○ The word convolution comes from the process of sliding a filter designed to detect certain
features over the input image, the output is a feature map that highlights the presence of
the detected features in the image.
● Recurrent neural networks (RNNs) are identified by their feedback loops.
○ These learning algorithms are primarily leveraged when using time-series data to make
predictions about future outcomes, such as stock market predictions or sales forecasting.
Copyright © Laura Wang 2025 8
Practical AI and Python
3+ neural networks = Deep Learning
● A neural network of more than three
layers, including the inputs and the output,
can be considered a deep-learning
algorithm.
● Most deep neural networks are
feed-forward, meaning they only flow in
one direction from input to output.
● Model can have back-propagation,
meaning moving from output to input.
● Back-propagation allows us to calculate
and attribute the error that is associated
with each neuron, allowing us to adjust
and fit the algorithm appropriately.
Copyright © Laura Wang 2025 9
Practical AI and Python
Deep Learning vs. machine learning
● Deep learning is a part of Machine
Learning.
● The primary differences between non-deep
machine learning and deep learning is how
algorithm learns and how much data
algorithm uses.
● Deep learning automate feature extraction
process, eliminating human intervention.
Copyright © Laura Wang 2025 10
Practical AI and Python
Convolutional Neural Networks
● Convolutional Neural Network (CNN) is designed to extract features from grid-like matrix datasets.
● CNNs is widely used in computer vision applications with visual datasets such as images or videos.
● CNNs consist of multiple layers like the input layer, Convolutional layer, pooling layer, and fully
connected layers.
● A complete Convolution Neural Networks architecture is also known as covnets. A covnets is a
sequence of layers, and every layer transforms one volume to another through a differentiable
function.
Copyright © Laura Wang 2025 11
Practical AI and Python
Convolution process
● A convolution process is a mathematical operation that combines two functions or signals to
produce a third function, often used in signal processing, image processing, and other fields.
● Mathematical Operation: The convolution process involves flipping one function, shifting it over the
other, and performing a weighted sum of the overlapping regions.
● Applications:
○ Signal Processing: Analyzing and modifying signals, like audio and video.
○ Image Processing: Blurring, sharpening, edge detection, and noise reduction.
○ Deep Learning: In convolutional neural networks (CNNs), convolution is used to extract
features from images and other data.
● Kernel:
○ In image processing, a small matrix called a kernel is used in the convolution process to define
the type of transformation being performed (e.g., blurring, sharpening).
● Think of it like a "sliding window" or "filter" that moves across the input data, performing
calculations at each position and producing a new output that reflects the combined effect of the
functions
Copyright © Laura Wang 2025 12
Practical AI and Python
CNN layers
● Input Layers: layer we give input to CNN model. Generally, the input will be an image or a sequence
of images. This layer holds the raw input of the image.
● Convolutional Layers: layer used to extract the feature from the input dataset. It applies a set of
learnable filters known as the kernels to the input images. The filters/kernels are smaller matrices
which slides over the input image data and computes the dot product between kernel weight and the
corresponding input image patch. The output of this layer is referred as feature maps.
● Activation Layer: By adding an activation function to the output of the preceding layer, activation
layers add nonlinearity to the network. it will apply an element-wise activation function to the
output of the convolution layer.
● Pooling layer: This layer is inserted in the covnets to reduce the size of volume, hence to improve
performance (runtime and memory) and reduce overfitting.
● Dense Layer: The resulting feature maps are flattened into a one-dimensional vector after the
convolution and pooling layers so they can be passed into a completely linked layer for
categorization or regression.
Copyright © Laura Wang 2025 13
Practical AI and Python
Recurrent Neural Networks(RNN)
● RNN: Neural networks for sequential data (time series, text, speech).
● Core Idea: Loops to persist information (memory of past inputs).
● Usage example: "Predicting the next word in a sentence."
● Why RNNs?
○ Handles variable-length input/output (unlike CNNs for fixed-size grids).
Copyright © Laura Wang 2025 14
Practical AI and Python
How RNN works?
RNNs have a feedback loop that allows them to maintain a form of memory by considering previous
inputs when processing the current input.
1. Input:
● At each time step (t), the RNN cell receives a current input (x_t). This could be a word in a sentence,
a data point in a time series, or any element of a sequence.
2. Hidden State:
● The RNN cell receives the previous hidden state as input.
● The cell combines the current input and the previous hidden state to calculate a new hidden state.
● This calculation involves transformations using weight matrices and an activation function.
● The hidden state acts as the network's memory, encoding information from all previous inputs.
3. Output:
● Based on the current hidden state, the RNN cell can generate an output.
● The output could be a prediction, a classification, or another element of a sequence.
● The output is calculated by applying another transformation to the hidden state and an activation
function.
Copyright © Laura Wang 2025 15
Practical AI and Python
Improving RNNs
LSTM (Long Short-Term Memory):
Gates (input, forget, output) to control memory.
GRU (Gated Recurrent Unit):
Simpler than LSTM, merges forget/input gates.
Applications:
● Machine translation (e.g., Google Translate).
● Speech recognition (e.g., Siri).
Copyright © Laura Wang 2025 16
Practical AI and Python
When to Use RNNs vs. CNNs?
Feature CNN RNN
Input Grid-like (images, pixels) Sequential (text, time series)
Memory Local patterns (no memory) Persists past information
Applications Image classification, object detection Language modeling, speech recognition
● CNNs: Space-invariant patterns (e.g., edges in images).
● RNNs: Time-invariant patterns (e.g., context in sentences).
● Hybrid Use Cases:
○ Image captioning: CNN (extract features) + RNN (generate text).
Copyright © Laura Wang 2025 17
Practical AI and Python
Neural Network Model Comparison
Copyright © Laura Wang 2025 18
Practical AI and Python
Quiz:
● Would you use a CNN or RNN for stock price prediction AI program?
Copyright © Laura Wang 2025 19
Practical AI and Python
CNN or RNN for Stock Prediction?
RNN (LSTM/GRU): CNN
Pros: Pros:
● Time-series data (sequential dependence). ● Extracting local patterns (e.g., short-term
● Capturing long-term trends/patterns. spikes).
● Example: Predicting next day’s price based on ● Parallel processing (faster than RNNs).
past 30 days.
Limitations:
Limitations: ● No inherent memory of past sequences.
● Slow training for very long sequences. ● Requires clever input framing (e.g., 1D
● May struggle with sudden market shocks. convolutions over time windows).
Stock prediction: hybrid Approach: CNN + LSTM:
● CNNs can be useful for detecting local patterns in price movements
● CNN-LSTM hybrids where CNNs extract features from price windows, then feed into LSTMs for
sequence modeling
● Transformer models (attention-based) are increasingly popular and often outperform both CNNs
and RNNs
Copyright © Laura Wang 2025 20
Practical AI and Python
Homework
● Review projects and explore projects for after class study.
● These projects can be used for science fair.
● Please reach out to me if you are seeking advice/mentoring for middle/high school science
projects.
● Provide your feedbacks for this class!
Copyright © Laura Wang 2025 21