Skip to content

Commit

Permalink
Poker Hand Prediction (#628)
Browse files Browse the repository at this point in the history
## Pull Request for PyVerse 💡

### Requesting to submit a pull request to the PyVerse repository.
#532 
---

#### Issue Title
**Please enter the title of the issue related to your pull request.**
Poker Hand Prediction using Machine Learning
*Enter the issue title here.* Poker Hand Prediction using Machine
Learning

- [x] I have provided the issue title.

---

#### Info about the Related Issue
**What's the goal of the project?**  
*Describe the aim of the project.*
Predict poker hand using Machine learning, can be integrated in online
games
- [x] I have described the aim of the project.

---

#### Name
**Please mention your name.**  
*Enter your name here.* Aviral Garg

- [x] I have provided my name.

---

#### GitHub ID
**Please mention your GitHub ID.**  
*Enter your GitHub ID here.* aviralgarg05

- [x] I have provided my GitHub ID.

---

#### Email ID
**Please mention your email ID for further communication.**  
*Enter your email ID here.* [email protected]

- [x] I have provided my email ID.

---

#### Identify Yourself
**Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC,
SWOC).**
*Enter your participant role here.* GSSOC'24 Extended and Hacktoberfest

- [x] I have mentioned my participant role.

---

#### Closes
**Enter the issue number that will be closed through this PR.**  
*Closes: #issue-number* 
#532 

- [x] I have provided the issue number.

---

#### Describe the Add-ons or Changes You've Made
**Give a clear description of what you have added or modified.**  
*Describe your changes here.* New Code Feature Update

- [x] I have described my changes.

---

#### Type of Change
**Select the type of change:**  
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Code style update (formatting, local variables)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

---

#### How Has This Been Tested?
**Describe how your changes have been tested.**  
*Describe your testing process here.* Using Testing Datasets

- [x] I have described my testing process.

---

#### Checklist
**Please confirm the following:**  
- [x] My code follows the guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly wherever it was hard to
understand.
- [x] I have made corresponding changes to the documentation.
- [x] My changes generate no new warnings.
- [x] I have added things that prove my fix is effective or that my
feature works.
- [x] Any dependent changes have been merged and published in downstream
modules.
  • Loading branch information
UTSAVS26 authored Oct 19, 2024
2 parents 33acd8b + f650aa5 commit 9b2b6ef
Show file tree
Hide file tree
Showing 32 changed files with 1,027,997 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

251 changes: 251 additions & 0 deletions Machine_Learning/Poker Hand Prediction/Poker Hand Prediction/SVM.ipynb

Large diffs are not rendered by default.

145 changes: 145 additions & 0 deletions Machine_Learning/Poker Hand Prediction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Project Title
**Poker Hand Prediction**

---

### AIM
Predicting poker hands from a sequence of 5 'community' cards using machine learning models.

---

### DATASET LINK
[Poker Hand Data from UCI Machine Learning Repository](https://archive.ics.uci.edu/ml/datasets/Poker+Hand)

---

### MY NOTEBOOK LINK
[Poker Hand Prediction Notebook](#)

---

### DESCRIPTION
**What is the requirement of the project?**
The project aims to develop a model that predicts the poker hand strength based on the 5 community cards drawn in a Texas Hold'em poker game.

**Why is it necessary?**
Poker is a game of probabilities. Predicting hand strength can help players make better decisions during a game, offering an edge in terms of strategy and decision-making.

**How is it beneficial and used?**
The model helps in automating poker hand predictions which can be used in poker bots, game analysis, or training tools for poker players.

**How did you start approaching this project?**
The project began with acquiring the Poker Hand dataset from the UCI repository, followed by data exploration and understanding the classification problem. The plan involved training various machine learning models to evaluate their performance on this multi-class classification problem.

**Additional Resources Used:**
- Research papers on poker hand prediction
- Blogs on multi-class classification
- Tutorials on machine learning model training

---

### EXPLANATION

---

### DETAILS OF THE DIFFERENT FEATURES
**Key Features:**
- **Rank of Cards:** The 5 community cards' ranks are represented in the dataset.
- **Suit of Cards:** The suit (hearts, spades, diamonds, clubs) of the 5 community cards.
- **Hand Type:** The outcome or label, which represents the poker hand type (e.g., Royal Flush, Straight, etc.).

Each feature plays a vital role in determining the probability of different poker hands.

---

### WHAT I HAVE DONE

1. **Step 1:** Initial data exploration and understanding — explored the structure and distribution of the dataset.
2. **Step 2:** Data cleaning and preprocessing — handled missing values, if any, and prepared the data for model training.
3. **Step 3:** Feature engineering and selection — focused on the most critical features for hand prediction.
4. **Step 4:** Model training and evaluation — applied various machine learning models to the dataset.
5. **Step 5:** Model optimization and fine-tuning — optimized models for better performance.
6. **Step 6:** Validation and testing — tested models on unseen data and evaluated their accuracy.

---

### PROJECT TRADE-OFFS AND SOLUTIONS
**Trade-off 1:** Accuracy vs. computational efficiency
- **Solution:** SVM and Random Forest were computationally expensive. I addressed this by using Multi-Layer Perceptron (MLP), which offered better accuracy with manageable computational costs.

**Trade-off 2:** Model complexity vs. interpretability
- **Solution:** Opted for models like Random Forest and MLP that balanced performance and interpretability, providing insights into feature importance without overly complex operations.

---

### LIBRARIES NEEDED
- pandas
- numpy
- scikit-learn
- matplotlib
- seaborn
- tensorflow
- keras

---

### SCREENSHOTS
**Project Structure:**
- A tree diagram showing project structure and folder organization.

**Visualizations and EDA:**
- Distribution of poker hands.
- Correlation matrix of features.

**Model Performance Graphs:**
- Accuracy comparison across different models.

---

### MODELS USED AND THEIR ACCURACIES

| Model | Accuracy | MSE | R² Score |
|--------------------------|----------|------|----------|
| Linear Regression | 42% | 0.08 | 0.60 |
| Support Vector Machine | 58% | 0.06 | 0.72 |
| AdaBoost | 49% | 0.07 | 0.65 |
| Output Code Classifier | 61% | 0.05 | 0.75 |
| Random Forest | 56% | 0.06 | 0.70 |
| Artificial Neural Network | 45% | 0.07 | 0.63 |
| Deep Neural Network | 87% | 0.02 | 0.90 |
| Multi-Layer Perceptron | 97% | 0.01 | 0.95 |

---

### MODELS COMPARISON GRAPHS
- **Bar Chart:** Comparison of accuracy and MSE between models.
- **Line Plot:** Model performance metrics over epochs for deep learning models.

---

### CONCLUSION
The **Multi-Layer Perceptron (MLP)** provided the best accuracy for this dataset, outperforming other models by a significant margin.

---

### WHAT YOU HAVE LEARNED
- **Insights from the Data:**
Learned that certain card combinations heavily influence hand strength.

- **Improvements in ML Understanding:**
Gained a deeper understanding of multi-class classification problems and how different models handle such tasks.

- **Challenges Overcome:**
Faced difficulty in training the deep neural network but overcame it by tuning hyperparameters and adjusting model architecture.

---

### USE CASES OF THIS MODEL
1. **Poker Game Analysis:**
The model can assist in analyzing hands for poker players to improve their decision-making during a game.

2. **Poker Bots:**
Can be integrated into poker-playing bots to enhance their strategy in real-time games.


Aviral Garg
Loading

0 comments on commit 9b2b6ef

Please sign in to comment.