SlideShare a Scribd company logo
1 of 22
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
Copyright Β© 2017, edureka and/or its affiliates. All rights reserved.
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
www.edureka.co

More Related Content

More from Edureka!

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaEdureka!
Β 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaEdureka!
Β 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaEdureka!
Β 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
Β 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
Β 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaEdureka!
Β 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaEdureka!
Β 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaEdureka!
Β 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaEdureka!
Β 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaEdureka!
Β 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | EdurekaEdureka!
Β 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEdureka!
Β 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEdureka!
Β 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaEdureka!
Β 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaEdureka!
Β 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaEdureka!
Β 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Edureka!
Β 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaEdureka!
Β 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaEdureka!
Β 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | EdurekaEdureka!
Β 

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
Β 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
Β 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
Β 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
Β 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
Β 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
Β 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
Β 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
Β 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
Β 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
Β 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
Β 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
Β 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
Β 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
Β 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
Β 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
Β 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
Β 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Β 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
Β 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
Β 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
Β 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
Β 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
Β 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
Β 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
Β 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
Β 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
Β 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
Β 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
Β 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
Β 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
Β 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
Β 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
Β 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
Β 
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Wonjun Hwang
Β 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
Β 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
Β 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
Β 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Β 
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort ServiceHot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Β 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Β 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
Β 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
Β 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Β 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Β 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
Β 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
Β 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Β 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
Β 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Β 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Β 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Β 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
Β 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
Β 
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Β 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
Β 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
Β 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Β 

Markov Chains | Edureka

  • 1.
  • 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. Copyright Β© 2017, edureka and/or its affiliates. All rights reserved. www.edureka.co
  • 18. 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
  • 20. Markov Chain Applications Google PageRank Autocomplete www.edureka.co
  • 21. Markov Chain Applications Subreddit simulator Text generator www.edureka.co