SlideShare a Scribd company logo
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
WHAT IS A MARKOV CHAIN?
UNDERSTANDING MARKOV CHAINS WITH AN EXAMPLE
MARKOV CHAIN IN PYTHON
MARKOV CHAIN APPLICATIONS
TRANSITION MATRIX & TRANSISTION STATE DIAGRAM
www.edureka.co
WHAT IS A MARKOV CHAIN?
www.edureka.co
A stochastic process containing random variables, transitioning from one state to another
depending on certain assumptions and definite probabilistic rules.
What Is A Markov chain?
Markov Property states that the calculated probability of a random process transitioning to the
next possible state is only dependent on the current state and time and it is independent of the
series of states that preceded it.
Let the random process be, { 𝑋 𝑚 , m=0,1,2 … }
This process is a Markov chain only if,
𝑃 𝑋 𝑚+1 = ȁ𝑗 𝑋 𝑚 = ⅈ, 𝑋 𝑚−1 = ⅈ 𝑚−1, … , 𝑋0 = ⅈ0 = 𝑃 𝑋 𝑚+1 = ȁ𝑗 𝑋 𝑚 = ⅈ
𝑃𝑖𝑗 = 𝑃 𝑋 𝑚+1 = ȁ𝑗 𝑋 𝑚 = ⅈ
www.edureka.co
UNDERSTANDING MARKOV CHAINS
www.edureka.co
A Markov Model is a stochastic model that models random variables in such a manner that the variables
follow the Markov property.
• Keys denote the unique words in the sentence, i.e., 5 keys (one, two, hail, happy, edureka)
• Tokens denote the total number of words, i.e. 8 tokens.
one edureka two edureka hail edureka happy edureka
www.edureka.co
A Markov Model is a stochastic model that models random variables in such a manner that the variables
follow the Markov property.
one
edureka
two
hail
happy
1
4
1
1
1
Keys Frequencies
www.edureka.co
A Markov Model is a stochastic model that models random variables in such a manner that the variables
follow the Markov property.
one
edureka
two
hail
happy
1
4
1
1
1
Weighted distributions:
1. 'edureka' is 50% (4/8)
2. (one, two, hail, happy)
is ≈ 13% (1/8)
www.edureka.co
Start one edureka two edureka hail edureka happy edureka end
one
edureka
two
hail
happy
1
4
1
1
1
start
end
1
1
Keys Frequencies
www.edureka.co
(Start, one)
(one, edureka)
(edureka, two)
(two, edureka)
(edureka, hail)
(hail, edureka)
(edureka, happy)
(happy, edureka)
(edureka, end)
(end, none)
(Start, one)
(one, edureka)
(edureka, two) (edureka, hail) (edureka, happy) (edureka, end)
(two, edureka)
(hail, edureka)
(happy, edureka)
(end, none)
www.edureka.co
(Start, one)
(one, edureka)
(edureka, two) (edureka, hail) (edureka, happy) (edureka, end)
(two, edureka)
(hail, edureka)
(happy, edureka)
(end, none)
Start [one]
One [edureka]
Edureka [two, hail, happy, end]
Two [edureka]
Hail [edureka]
Happy [edureka]
End [none]
www.edureka.co
Start
One
hailtwo
happy
end
edureka
1
1
1
1
1
1/4
1/4
1/4
1/4
Start [one]
One [edureka]
Edureka [two, hail, happy, end]
Two [edureka]
Hail [edureka]
Happy [edureka]
End [none]
www.edureka.co
TRANSITION MATRIX & STATE DAIGRAM
www.edureka.co
In a Markov Process, we use a matrix to represent the transition probabilities from one state to
another. This matrix is called the Transition or probability matrix. It is usually denoted by P.
What Is A Transition Matrix?
𝑝11 𝑝12 𝑝1𝑟
𝑝21 𝑝22 𝑝2𝑟
𝑝21 𝑝22 𝑝2𝑟
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
P =
෍
𝑘=1
𝑟
𝑝𝑖𝑘 = ෍
𝑘=1
𝑟
𝑃 𝑋 𝑚+1 = ȁ𝑘 𝑋 𝑚 = ⅈ
Note, 𝑝ij ≥ 0, and 'i' for all values is,
www.edureka.co
Consider a Markov chain with three states 1, 2, and 3.
Transition Matrix & State Diagram Example
Transition matrix
1/4 0 3/4
P = 1/2 0 1/2
1/4 1/2 1/4
1 2
3
1/4
3/4
1/2
1/2
1/4
1/2
1/4
State Transition Diagram
www.edureka.co
DEMO
www.edureka.co
To apply Markov Property and create a Markov Model that can generate text simulations by
studying Donald Trump speech data set.
Problem Statement
Apply Markov property
Generate Text Simulations
Donald Trump speeches
www.edureka.co
MARKOV CHAIN APPLICATIONS
www.edureka.co
Markov Chain Applications
Google PageRank Autocomplete
www.edureka.co
Markov Chain Applications
Subreddit simulator Text generator
www.edureka.co
Copyright © 2017, edureka and/or its affiliates. All rights reserved.
www.edureka.co
www.edureka.co

More Related Content

PPTX
common laboratory animals part 1
PDF
power 6210.pdf
PPTX
Antioxidants treatment for diabetes mellitus.pptx
PPTX
Concept of rational drug design by vikas gupta.pptx
PPTX
Alternatives to animal experiments
PPT
Version spaces
PPTX
Rsrp、rsrq、sinr
PDF
Wireless communications
common laboratory animals part 1
power 6210.pdf
Antioxidants treatment for diabetes mellitus.pptx
Concept of rational drug design by vikas gupta.pptx
Alternatives to animal experiments
Version spaces
Rsrp、rsrq、sinr
Wireless communications

What's hot (19)

PPTX
Pharmacogenetics- Introduction, History with case Study - 2024
PPTX
Anti ulcer
PDF
Multi cycle cpu
PPT
Fuzzy relations
PPT
knowledge presentation of saroj kaushik slides
PPTX
Maintenance and breeding of laboratory animals
PPT
Cuckoo search final
PPTX
CPCSEA- Guidelines
PPTX
395317358-LTE-Resource-Usage-Optimization.pptx
PDF
3GPP SON Series: RACH Optimization
PPTX
Portable Ground Receving Station
PPTX
CPCSEA Guidelines
PPTX
Alzheimer models
PPTX
Maintence and breeding of laboratory animals
PPTX
Cordless Technology
DOCX
Dscp based service experience
PPT
frequency re use nb
PPTX
Immunoassay of digoxin
PPTX
common lab animals.pptx
Pharmacogenetics- Introduction, History with case Study - 2024
Anti ulcer
Multi cycle cpu
Fuzzy relations
knowledge presentation of saroj kaushik slides
Maintenance and breeding of laboratory animals
Cuckoo search final
CPCSEA- Guidelines
395317358-LTE-Resource-Usage-Optimization.pptx
3GPP SON Series: RACH Optimization
Portable Ground Receving Station
CPCSEA Guidelines
Alzheimer models
Maintence and breeding of laboratory animals
Cordless Technology
Dscp based service experience
frequency re use nb
Immunoassay of digoxin
common lab animals.pptx
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
PDF
Top 5 Trending Business Intelligence Tools | Edureka
PDF
Tableau Tutorial for Data Science | Edureka
PDF
Python Programming Tutorial | Edureka
PDF
Top 5 PMP Certifications | Edureka
PDF
Top Maven Interview Questions in 2020 | Edureka
PDF
Linux Mint Tutorial | Edureka
PDF
How to Deploy Java Web App in AWS| Edureka
PDF
Importance of Digital Marketing | Edureka
PDF
RPA in 2020 | Edureka
PDF
Email Notifications in Jenkins | Edureka
PDF
EA Algorithm in Machine Learning | Edureka
PDF
Cognitive AI Tutorial | Edureka
PDF
AWS Cloud Practitioner Tutorial | Edureka
PDF
Blue Prism Top Interview Questions | Edureka
PDF
Big Data on AWS Tutorial | Edureka
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
PDF
Kubernetes Installation on Ubuntu | Edureka
PDF
Introduction to DevOps | Edureka
What to learn during the 21 days Lockdown | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Tableau Tutorial for Data Science | Edureka
Python Programming Tutorial | Edureka
Top 5 PMP Certifications | Edureka
Top Maven Interview Questions in 2020 | Edureka
Linux Mint Tutorial | Edureka
How to Deploy Java Web App in AWS| Edureka
Importance of Digital Marketing | Edureka
RPA in 2020 | Edureka
Email Notifications in Jenkins | Edureka
EA Algorithm in Machine Learning | Edureka
Cognitive AI Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Blue Prism Top Interview Questions | Edureka
Big Data on AWS Tutorial | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Kubernetes Installation on Ubuntu | Edureka
Introduction to DevOps | Edureka
Ad

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Empathic Computing: Creating Shared Understanding
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Big Data Technologies - Introduction.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
Dropbox Q2 2025 Financial Results & Investor Presentation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Empathic Computing: Creating Shared Understanding
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine Learning_overview_presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
Unlocking AI with Model Context Protocol (MCP)
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Electronic commerce courselecture one. Pdf
Assigned Numbers - 2025 - Bluetooth® Document

Introduction To Markov Chains | Markov Chains in Python | Edureka

  • 1. Copyright © 2017, edureka and/or its affiliates. All rights reserved.
  • 2. WHAT IS A MARKOV CHAIN? UNDERSTANDING MARKOV CHAINS WITH AN EXAMPLE MARKOV CHAIN IN PYTHON MARKOV CHAIN APPLICATIONS TRANSITION MATRIX & TRANSISTION STATE DIAGRAM www.edureka.co
  • 3. WHAT IS A MARKOV CHAIN? www.edureka.co
  • 4. A stochastic process containing random variables, transitioning from one state to another depending on certain assumptions and definite probabilistic rules. What Is A Markov chain? Markov Property states that the calculated probability of a random process transitioning to the next possible state is only dependent on the current state and time and it is independent of the series of states that preceded it. Let the random process be, { 𝑋 𝑚 , m=0,1,2 … } This process is a Markov chain only if, 𝑃 𝑋 𝑚+1 = ȁ𝑗 𝑋 𝑚 = ⅈ, 𝑋 𝑚−1 = ⅈ 𝑚−1, … , 𝑋0 = ⅈ0 = 𝑃 𝑋 𝑚+1 = ȁ𝑗 𝑋 𝑚 = ⅈ 𝑃𝑖𝑗 = 𝑃 𝑋 𝑚+1 = ȁ𝑗 𝑋 𝑚 = ⅈ www.edureka.co
  • 6. A Markov Model is a stochastic model that models random variables in such a manner that the variables follow the Markov property. • Keys denote the unique words in the sentence, i.e., 5 keys (one, two, hail, happy, edureka) • Tokens denote the total number of words, i.e. 8 tokens. one edureka two edureka hail edureka happy edureka www.edureka.co
  • 7. A Markov Model is a stochastic model that models random variables in such a manner that the variables follow the Markov property. one edureka two hail happy 1 4 1 1 1 Keys Frequencies www.edureka.co
  • 8. A Markov Model is a stochastic model that models random variables in such a manner that the variables follow the Markov property. one edureka two hail happy 1 4 1 1 1 Weighted distributions: 1. 'edureka' is 50% (4/8) 2. (one, two, hail, happy) is ≈ 13% (1/8) www.edureka.co
  • 9. Start one edureka two edureka hail edureka happy edureka end one edureka two hail happy 1 4 1 1 1 start end 1 1 Keys Frequencies www.edureka.co
  • 10. (Start, one) (one, edureka) (edureka, two) (two, edureka) (edureka, hail) (hail, edureka) (edureka, happy) (happy, edureka) (edureka, end) (end, none) (Start, one) (one, edureka) (edureka, two) (edureka, hail) (edureka, happy) (edureka, end) (two, edureka) (hail, edureka) (happy, edureka) (end, none) www.edureka.co
  • 11. (Start, one) (one, edureka) (edureka, two) (edureka, hail) (edureka, happy) (edureka, end) (two, edureka) (hail, edureka) (happy, edureka) (end, none) Start [one] One [edureka] Edureka [two, hail, happy, end] Two [edureka] Hail [edureka] Happy [edureka] End [none] www.edureka.co
  • 12. Start One hailtwo happy end edureka 1 1 1 1 1 1/4 1/4 1/4 1/4 Start [one] One [edureka] Edureka [two, hail, happy, end] Two [edureka] Hail [edureka] Happy [edureka] End [none] www.edureka.co
  • 13. TRANSITION MATRIX & STATE DAIGRAM www.edureka.co
  • 14. In a Markov Process, we use a matrix to represent the transition probabilities from one state to another. This matrix is called the Transition or probability matrix. It is usually denoted by P. What Is A Transition Matrix? 𝑝11 𝑝12 𝑝1𝑟 𝑝21 𝑝22 𝑝2𝑟 𝑝21 𝑝22 𝑝2𝑟 . . . . . . . . . . . . . . . . . P = ෍ 𝑘=1 𝑟 𝑝𝑖𝑘 = ෍ 𝑘=1 𝑟 𝑃 𝑋 𝑚+1 = ȁ𝑘 𝑋 𝑚 = ⅈ Note, 𝑝ij ≥ 0, and 'i' for all values is, www.edureka.co
  • 15. Consider a Markov chain with three states 1, 2, and 3. Transition Matrix & State Diagram Example Transition matrix 1/4 0 3/4 P = 1/2 0 1/2 1/4 1/2 1/4 1 2 3 1/4 3/4 1/2 1/2 1/4 1/2 1/4 State Transition Diagram www.edureka.co
  • 17. To apply Markov Property and create a Markov Model that can generate text simulations by studying Donald Trump speech data set. Problem Statement Apply Markov property Generate Text Simulations Donald Trump speeches www.edureka.co
  • 19. Markov Chain Applications Google PageRank Autocomplete www.edureka.co
  • 20. Markov Chain Applications Subreddit simulator Text generator www.edureka.co
  • 21. Copyright © 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co