File size: 2,230 Bytes
b98c2d0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | # 🍄 Mushroom Classification with Machine Learning
This project uses machine learning to classify mushrooms as **edible** (`e`) or **poisonous** (`p`) based on various morphological features.
---
## 📁 Dataset
- **Source**: [UCI Mushroom Dataset](https://archive.ics.uci.edu/dataset/73/mushroom)
- **Samples**: 8124
- **Original Features**: 22 categorical (e.g., cap-shape, odor, stalk-root)
- **Preprocessing**: One-Hot Encoding applied for model compatibility
---
## 🧠 Model Information
- **Algorithm**: Decision Tree Classifier
- **Training/Test Split**: 80% / 20%
- **Cross-Validation**: 5-Fold (Average Accuracy: ~96.6%)
- **Test Accuracy**: ~100%
### 🔍 Feature Importance (Top 5)
Based on the Decision Tree model:
1. `odor=n`
2. `stalk-root=c`
3. `spore-print-color=r`
4. `stalk-surface-below-ring=y`
5. `habitat=d`
---
## ⚙️ How It Works
You provide one-hot encoded features like `cap-shape=c`, `odor=n`, etc.
The model then predicts:
- `"e"` → Edible
- `"p"` → Poisonous
Sample input format is shown in `sample_input.json`.
---
## 🚀 Quick Usage (Python)
```python
import joblib
import pandas as pd
model = joblib.load("mushroom_model.pkl")
sample = pd.DataFrame([{
"cap-shape=c": 1,
"cap-color=n": 1,
"odor=n": 1,
...
}])
prediction = model.predict(sample)[0]
print("Prediction:", prediction)
📦 Project Files
File Name Description
mushroom_model.pkl Trained Decision Tree model
sample_input.json Example of one-hot encoded input
model.py Script for model training
app.py Streamlit web interface
README.md This project explanation file
requirements.txt Python dependencies
How to Run Locally
Install dependencies:
pip install -r requirements.txt
Launch the Streamlit app:
streamlit run app.py
🌐 Live Demo and Deployment
You can deploy this model to:
Hugging Face for API access and hosting the model
GitHub for open sharing and collaboration
Streamlit Cloud for an interactive app
🧪 Model Testing on Hugging Face
You can test the model by uploading:
mushroom_model.pkl
sample_input.json
requirements.txt
README.md
Visit: https://huggingface.co (yazodi)
📄 License
MIT License – for educational and non-commercial purposes. |