Skip to content

Commit

Permalink
Created Poker Probability Teaser
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharp-Data committed Aug 11, 2017
1 parent 6bb781f commit 7208099
Show file tree
Hide file tree
Showing 2 changed files with 342 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Poker Probability and Statistics\n",
"\n",
"For several years, beginning in 2010 I made a living playing online poker professionally. Data Science was a natural progression for me as it requires a similar skill-set as earning a profit at online poker. I wrote a blog about [what data analysis has in common with poker](https://medium.springboard.com/how-i-used-professional-poker-to-become-a-data-scientist-e49b75dfe8e3), and I mentioned that each time a poker hand is played at an online poker site, a hand history is generated that explains everything that each player did during the hand. I used software called [Hold’em Manager](https://holdemmanager.com/?a_aid=sharpdata) (think Tableau for poker), which downloads each of these hand histories in real time to a PostgreSQL database so you can keep track of your opponent’s tendencies. \n",
"\n",
"Before we get started, a little background info is in order. The game is No Limit Texas Hold’em, and if you’ve never played or are unfamiliar with poker terminology you can [click here](https://www.pokernews.com/poker-rules/texas-holdem.htm) for a concise but detailed explanation. In the business world, Data Science is used to make predictions and optimize decisions by creating machine learning models. In online poker, the decision that needs to be made is whether to bet, call, or fold, but you aren’t allowed to use software to make that decision for you. At most online poker sites, that is where the line is drawn in the rules. This means that the model that must be trained is your brain, and the training is done away from the table with an endless stream of equity calculations. \n",
"\n",
"Anytime I ran into a situation while playing that confused me, I would mark the hand for review later. After my poker playing session was done, I'd go back through the hands that I'd marked for review and break them down mathematically so I'd have a better idea of what to do in each situation the next time it arose. I picked out five hands from my poker career. Using the statistics on my opponents that I had available at the time, I’ll explain my thought process. Then you can analyze the hand using Python to determine which of your options offers the highest expected value.\n",
"\n",
"**Note**: *When reviewing poker hands, it is common to refer to our opponent as the \"Villain\" and ourselves as the \"Hero.\"*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hand 1 Overview:\n",
"\n",
"![Hand 1 Overview Image here](http://i1285.photobucket.com/albums/a584/daniel_poston1/Hand1Overview_zpscxcoeivo.png)\n",
"\n",
"- Hero bet 0.85 (Hero has 20.95 remaining);\n",
"- Opponent (Villain) raises to 2.50 (Villain has 30.35 remaining);\n",
" - In poker terminology, this is called a 3bet. The small blind and big blind make the first bet, and the Hero raised them which was the second bet.\n",
"- There is currently 3.70 Total in the Pot.\n",
"\n",
"Calling is not a good option for reasons that are beyond the scope of this blog post. The Hero must decide between raising with the plan of going All-In (Betting all remaining chips) or folding. Folding costs nothing so you will analyze the expected value of going all in. In this situation, I’d make a small raise to induce my opponent to All-in bluff, but we need to do the calculation as if I’m going All-in since that is the plan, so;\n",
"\n",
"- Hero risks 20.95 if All-in and loses;\n",
" - Going ‘All-in’ means to put all your money in the pot. The Hero has 20.95 remaining, so going All-in risks 20.95.\n",
"- Hero wins 23 if All-in and wins;\n",
" - There is currently 3.70 in the pot. Hero bet 0.85 and the Villain raised to 2.50. Hero must add 1.65 of remaining 20.95 to match Villain’s raise, leaving Hero with 19.30. This means the Hero can win an additional 19.30 on top of the 3.70 already in the pot for a total of 23.00.\n",
"- Hero wins 3.70 if Villain folds."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Hand1_AllIn_Loses = -20.95\n",
"Hand1_AllIn_Winnings = 23\n",
"Hand1_Fold_Winnings = 3.7"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Hand 1 Relevant Statistics:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Poker is a game of deductive reasoning based on incomplete information. Here is the information you have on this opponent:\n",
"\n",
"![Stats1](http://i1285.photobucket.com/albums/a584/daniel_poston1/Hand1Stats_zpsoiap7ejk.png) ![Stats2](http://i1285.photobucket.com/albums/a584/daniel_poston1/Hand1Stats1_zpsgzqgflpg.png)\n",
"\n",
"1. The Villian is in the Button position which is the first position to the right of the small and big blinds. Overall, from this position, villian 3bets 7.4% (27 trials);\n",
"2. Hero is in the Cut-Off position, which is the first position to the right of the Button. Overall, vs. the Cut-Off, villian 3bets 12.5% (16 trials);\n",
"3. When Villian is in the Button vs. a pre-flop raise from the Cut-Off, villian 3bets 25% (4 trials);\n",
"4. When Villian 3bets pre-flop and faces a raise, he folds 50% of the time (2 trials)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Hand 1 Assumptions:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Based on the above statistics, I’m going to make the following assumptions which are educated guesses;\n",
"\n",
"- Villian raises to 2.50 with about (~) 13-15% of the range of possible starting hands;\n",
"- Villian folds to a re-raise ~ 25% of the time and goes ‘All-in’ ~75% of the time;\n",
"- Villian re-raises ‘All-In’ with a ~10% range, which looks like this: ![9.7% range](http://i1285.photobucket.com/albums/a584/daniel_poston1/Hand1range_zpsu4o5h9zs.png)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"- The hands highlighted in yellow represent the Villian's range, which consists of 128 of the 1326 possible combinations of starting hands (9.7%);\n",
"- If you’re wondering why A5s and A2s are in the range, those represent Villian’s bluff hands.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Hand 1 Analysis:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that I have Villian’s range, I can plug the Hero's hand (10h10s) and the Villian’s range into an [equity calculator](http://www.acepokersolutions.com/Poker-equity-calculator/). The equity calculator simulates 10h10s vs. Villian’s range thousands of times and determines that the Hero wins ~53.77% of the time. \n",
"\n",
"Now you can create variables for `Fold_Percent` and `Equity`"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Hand1_Fold_Percent = .25\n",
"Hand1_Equity = .538"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now it’s a simple calculation. You need to build a function that represents the following equation:\n",
"\n",
"- $FoldEV = (FoldPercent * FoldWinnings)$\n",
"\n",
"- $AllinEV = (1 - FoldPercent) * ((AllInWinnings * Equity) + (AllInLoses * (1 - Equity)))$\n",
"\n",
"- $AllinExpectedValue = FoldEV + AllinEV$\n",
"\n",
"\n",
"## To be continued...\n",
"\n",
"**When complete, this post will be published to [DataCamp's Blog](https://www.datacamp.com/community/blog) and will include interactive code. In the meantime, [click here](https://www.datacamp.com/community/tutorials/python-statistics-data-science) for 40+ resources for learning about statistics with Python.**"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
171 changes: 171 additions & 0 deletions Poker Probability and Statistics Teaser.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Poker Probability and Statistics\n",
"\n",
"For several years, beginning in 2010 I made a living playing online poker professionally. Data Science was a natural progression for me as it requires a similar skill-set as earning a profit at online poker. I wrote a blog about [what data analysis has in common with poker](https://medium.springboard.com/how-i-used-professional-poker-to-become-a-data-scientist-e49b75dfe8e3), and I mentioned that each time a poker hand is played at an online poker site, a hand history is generated that explains everything that each player did during the hand. I used software called [Hold’em Manager](https://holdemmanager.com/?a_aid=sharpdata) (think Tableau for poker), which downloads each of these hand histories in real time to a PostgreSQL database so you can keep track of your opponent’s tendencies. \n",
"\n",
"Before we get started, a little background info is in order. The game is No Limit Texas Hold’em, and if you’ve never played or are unfamiliar with poker terminology you can [click here](https://www.pokernews.com/poker-rules/texas-holdem.htm) for a concise but detailed explanation. In the business world, Data Science is used to make predictions and optimize decisions by creating machine learning models. In online poker, the decision that needs to be made is whether to bet, call, or fold, but you aren’t allowed to use software to make that decision for you. At most online poker sites, that is where the line is drawn in the rules. This means that the model that must be trained is your brain, and the training is done away from the table with an endless stream of equity calculations. \n",
"\n",
"Anytime I ran into a situation while playing that confused me, I would mark the hand for review later. After my poker playing session was done, I'd go back through the hands that I'd marked for review and break them down mathematically so I'd have a better idea of what to do in each situation the next time it arose. I picked out five hands from my poker career. Using the statistics on my opponents that I had available at the time, I’ll explain my thought process. Then you can analyze the hand using Python to determine which of your options offers the highest expected value.\n",
"\n",
"**Note**: *When reviewing poker hands, it is common to refer to our opponent as the \"Villain\" and ourselves as the \"Hero.\"*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hand 1 Overview:\n",
"\n",
"![Hand 1 Overview Image here](http://i1285.photobucket.com/albums/a584/daniel_poston1/Hand1Overview_zpscxcoeivo.png)\n",
"\n",
"- Hero bet 0.85 (Hero has 20.95 remaining);\n",
"- Opponent (Villain) raises to 2.50 (Villain has 30.35 remaining);\n",
" - In poker terminology, this is called a 3bet. The small blind and big blind make the first bet, and the Hero raised them which was the second bet.\n",
"- There is currently 3.70 Total in the Pot.\n",
"\n",
"Calling is not a good option for reasons that are beyond the scope of this blog post. The Hero must decide between raising with the plan of going All-In (Betting all remaining chips) or folding. Folding costs nothing so you will analyze the expected value of going all in. In this situation, I’d make a small raise to induce my opponent to All-in bluff, but we need to do the calculation as if I’m going All-in since that is the plan, so;\n",
"\n",
"- Hero risks 20.95 if All-in and loses;\n",
" - Going ‘All-in’ means to put all your money in the pot. The Hero has 20.95 remaining, so going All-in risks 20.95.\n",
"- Hero wins 23 if All-in and wins;\n",
" - There is currently 3.70 in the pot. Hero bet 0.85 and the Villain raised to 2.50. Hero must add 1.65 of remaining 20.95 to match Villain’s raise, leaving Hero with 19.30. This means the Hero can win an additional 19.30 on top of the 3.70 already in the pot for a total of 23.00.\n",
"- Hero wins 3.70 if Villain folds."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Hand1_AllIn_Loses = -20.95\n",
"Hand1_AllIn_Winnings = 23\n",
"Hand1_Fold_Winnings = 3.7"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Hand 1 Relevant Statistics:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Poker is a game of deductive reasoning based on incomplete information. Here is the information you have on this opponent:\n",
"\n",
"![Stats1](http://i1285.photobucket.com/albums/a584/daniel_poston1/Hand1Stats_zpsoiap7ejk.png) ![Stats2](http://i1285.photobucket.com/albums/a584/daniel_poston1/Hand1Stats1_zpsgzqgflpg.png)\n",
"\n",
"1. The Villian is in the Button position which is the first position to the right of the small and big blinds. Overall, from this position, villian 3bets 7.4% (27 trials);\n",
"2. Hero is in the Cut-Off position, which is the first position to the right of the Button. Overall, vs. the Cut-Off, villian 3bets 12.5% (16 trials);\n",
"3. When Villian is in the Button vs. a pre-flop raise from the Cut-Off, villian 3bets 25% (4 trials);\n",
"4. When Villian 3bets pre-flop and faces a raise, he folds 50% of the time (2 trials)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Hand 1 Assumptions:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Based on the above statistics, I’m going to make the following assumptions which are educated guesses;\n",
"\n",
"- Villian raises to 2.50 with about (~) 13-15% of the range of possible starting hands;\n",
"- Villian folds to a re-raise ~ 25% of the time and goes ‘All-in’ ~75% of the time;\n",
"- Villian re-raises ‘All-In’ with a ~10% range, which looks like this: ![9.7% range](http://i1285.photobucket.com/albums/a584/daniel_poston1/Hand1range_zpsu4o5h9zs.png)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"- The hands highlighted in yellow represent the Villian's range, which consists of 128 of the 1326 possible combinations of starting hands (9.7%);\n",
"- If you’re wondering why A5s and A2s are in the range, those represent Villian’s bluff hands.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Hand 1 Analysis:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that I have Villian’s range, I can plug the Hero's hand (10h10s) and the Villian’s range into an [equity calculator](http://www.acepokersolutions.com/Poker-equity-calculator/). The equity calculator simulates 10h10s vs. Villian’s range thousands of times and determines that the Hero wins ~53.77% of the time. \n",
"\n",
"Now you can create variables for `Fold_Percent` and `Equity`"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Hand1_Fold_Percent = .25\n",
"Hand1_Equity = .538"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now it’s a simple calculation. You need to build a function that represents the following equation:\n",
"\n",
"- $FoldEV = (FoldPercent * FoldWinnings)$\n",
"\n",
"- $AllinEV = (1 - FoldPercent) * ((AllInWinnings * Equity) + (AllInLoses * (1 - Equity)))$\n",
"\n",
"- $AllinExpectedValue = FoldEV + AllinEV$\n",
"\n",
"\n",
"## To be continued...\n",
"\n",
"**When complete, this post will be published to [DataCamp's Blog](https://www.datacamp.com/community/blog) and will include interactive code. In the meantime, [click here](https://www.datacamp.com/community/tutorials/python-statistics-data-science) for 40+ resources for learning about statistics with Python.**"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

0 comments on commit 7208099

Please sign in to comment.