hç
commited on
Upload 8 files
Browse files- Mushroom Classification.ipynb +0 -0
- README.md +109 -3
- app.py +37 -0
- model.py +25 -0
- mushroom.csv +0 -0
- mushroom_model.pkl +3 -0
- requirements.txt +4 -0
- sample_input.json +9 -0
Mushroom Classification.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
README.md
CHANGED
|
@@ -1,3 +1,109 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🍄 Mushroom Classification with Machine Learning
|
| 2 |
+
|
| 3 |
+
This project uses machine learning to classify mushrooms as **edible** (`e`) or **poisonous** (`p`) based on various morphological features.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## 📁 Dataset
|
| 8 |
+
|
| 9 |
+
- **Source**: [UCI Mushroom Dataset](https://archive.ics.uci.edu/dataset/73/mushroom)
|
| 10 |
+
- **Samples**: 8124
|
| 11 |
+
- **Original Features**: 22 categorical (e.g., cap-shape, odor, stalk-root)
|
| 12 |
+
- **Preprocessing**: One-Hot Encoding applied for model compatibility
|
| 13 |
+
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
## 🧠 Model Information
|
| 17 |
+
|
| 18 |
+
- **Algorithm**: Decision Tree Classifier
|
| 19 |
+
- **Training/Test Split**: 80% / 20%
|
| 20 |
+
- **Cross-Validation**: 5-Fold (Average Accuracy: ~96.6%)
|
| 21 |
+
- **Test Accuracy**: ~100%
|
| 22 |
+
|
| 23 |
+
### 🔍 Feature Importance (Top 5)
|
| 24 |
+
|
| 25 |
+
Based on the Decision Tree model:
|
| 26 |
+
|
| 27 |
+
1. `odor=n`
|
| 28 |
+
2. `stalk-root=c`
|
| 29 |
+
3. `spore-print-color=r`
|
| 30 |
+
4. `stalk-surface-below-ring=y`
|
| 31 |
+
5. `habitat=d`
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## ⚙️ How It Works
|
| 36 |
+
|
| 37 |
+
You provide one-hot encoded features like `cap-shape=c`, `odor=n`, etc.
|
| 38 |
+
The model then predicts:
|
| 39 |
+
|
| 40 |
+
- `"e"` → Edible
|
| 41 |
+
- `"p"` → Poisonous
|
| 42 |
+
|
| 43 |
+
Sample input format is shown in `sample_input.json`.
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## 🚀 Quick Usage (Python)
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
import joblib
|
| 51 |
+
import pandas as pd
|
| 52 |
+
|
| 53 |
+
model = joblib.load("mushroom_model.pkl")
|
| 54 |
+
|
| 55 |
+
sample = pd.DataFrame([{
|
| 56 |
+
"cap-shape=c": 1,
|
| 57 |
+
"cap-color=n": 1,
|
| 58 |
+
"odor=n": 1,
|
| 59 |
+
...
|
| 60 |
+
}])
|
| 61 |
+
|
| 62 |
+
prediction = model.predict(sample)[0]
|
| 63 |
+
print("Prediction:", prediction)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
📦 Project Files
|
| 67 |
+
File Name Description
|
| 68 |
+
mushroom_model.pkl Trained Decision Tree model
|
| 69 |
+
sample_input.json Example of one-hot encoded input
|
| 70 |
+
model.py Script for model training
|
| 71 |
+
app.py Streamlit web interface
|
| 72 |
+
README.md This project explanation file
|
| 73 |
+
requirements.txt Python dependencies
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
How to Run Locally
|
| 77 |
+
Install dependencies:
|
| 78 |
+
|
| 79 |
+
pip install -r requirements.txt
|
| 80 |
+
|
| 81 |
+
Launch the Streamlit app:
|
| 82 |
+
streamlit run app.py
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
🌐 Live Demo and Deployment
|
| 86 |
+
You can deploy this model to:
|
| 87 |
+
|
| 88 |
+
Hugging Face for API access and hosting the model
|
| 89 |
+
|
| 90 |
+
GitHub for open sharing and collaboration
|
| 91 |
+
|
| 92 |
+
Streamlit Cloud for an interactive app
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
🧪 Model Testing on Hugging Face
|
| 96 |
+
You can test the model by uploading:
|
| 97 |
+
|
| 98 |
+
mushroom_model.pkl
|
| 99 |
+
|
| 100 |
+
sample_input.json
|
| 101 |
+
|
| 102 |
+
requirements.txt
|
| 103 |
+
|
| 104 |
+
README.md
|
| 105 |
+
|
| 106 |
+
Visit: https://huggingface.co (yazodi)
|
| 107 |
+
|
| 108 |
+
📄 License
|
| 109 |
+
MIT License – for educational and non-commercial purposes.
|
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# Modeli yükle
|
| 6 |
+
model = joblib.load("mushroom_model.pkl")
|
| 7 |
+
|
| 8 |
+
# Özellikler listesi
|
| 9 |
+
features = [
|
| 10 |
+
'cap-shape', 'cap-surface', 'cap-color', 'bruises', 'odor',
|
| 11 |
+
'gill-attachment', 'gill-spacing', 'gill-size', 'gill-color',
|
| 12 |
+
'stalk-shape', 'stalk-root', 'stalk-surface-above-ring',
|
| 13 |
+
'stalk-surface-below-ring', 'stalk-color-above-ring',
|
| 14 |
+
'stalk-color-below-ring', 'veil-type', 'veil-color',
|
| 15 |
+
'ring-number', 'ring-type', 'spore-print-color',
|
| 16 |
+
'population', 'habitat'
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
# Başlık
|
| 20 |
+
st.title("🍄 Mushroom Classification")
|
| 21 |
+
st.write("Bu uygulama, verilen mantar özelliklerine göre yenilebilir mi yoksa zehirli mi olduğunu tahmin eder.")
|
| 22 |
+
|
| 23 |
+
# Kullanıcı girişleri için alanlar
|
| 24 |
+
user_input = {}
|
| 25 |
+
for feature in features:
|
| 26 |
+
user_input[feature] = st.selectbox(f"{feature.replace('-', ' ').capitalize()}:",
|
| 27 |
+
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'])
|
| 28 |
+
|
| 29 |
+
# Tahmin butonu
|
| 30 |
+
if st.button("Tahmin Et"):
|
| 31 |
+
input_df = pd.DataFrame([user_input])
|
| 32 |
+
prediction = model.predict(input_df)[0]
|
| 33 |
+
|
| 34 |
+
if prediction == 'e':
|
| 35 |
+
st.success("✅ Tahmin: Edible (Yenilebilir)")
|
| 36 |
+
else:
|
| 37 |
+
st.error("❌ Tahmin: Poisonous (Zehirli)")
|
model.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from sklearn.model_selection import train_test_split
|
| 3 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Veriyi yükle
|
| 7 |
+
df = pd.read_csv("mushroom.csv")
|
| 8 |
+
|
| 9 |
+
# Hedef değişkeni oluştur (class=e sütunundan)
|
| 10 |
+
df["target"] = df["class=e"].apply(lambda x: 'e' if x == 1 else 'p')
|
| 11 |
+
|
| 12 |
+
# Özelliklerden class=e ve class=p sütunlarını çıkar
|
| 13 |
+
X = df.drop(columns=["class=e", "class=p", "target"])
|
| 14 |
+
y = df["target"]
|
| 15 |
+
|
| 16 |
+
# Eğitim/test ayrımı
|
| 17 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 18 |
+
|
| 19 |
+
# Model oluştur ve eğit
|
| 20 |
+
model = DecisionTreeClassifier(random_state=42)
|
| 21 |
+
model.fit(X_train, y_train)
|
| 22 |
+
|
| 23 |
+
# Kaydet
|
| 24 |
+
joblib.dump(model, "mushroom_model.pkl")
|
| 25 |
+
print("✅ Model eğitildi ve mushroom_model.pkl olarak kaydedildi.")
|
mushroom.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
mushroom_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f65d8c3ac0f6f49c1232232e1c07760874e8bf14050a8daec3dea7d31e9adce
|
| 3 |
+
size 6457
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
scikit-learn
|
| 3 |
+
streamlit
|
| 4 |
+
joblib
|
sample_input.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cap-shape=b": 0,
|
| 3 |
+
"cap-shape=c": 1,
|
| 4 |
+
"cap-shape=f": 0,
|
| 5 |
+
"cap-shape=k": 0,
|
| 6 |
+
...
|
| 7 |
+
"habitat=u": 0,
|
| 8 |
+
"habitat=w": 1
|
| 9 |
+
}
|