Repository navigation
Mushroom classifier/issue#1714 - #1723
Conversation
Mushroom Classifier (KNN, RandomForest, LogisticRegression)
Mushroom Classifier (KNN, RandomForest, LogisticRegression).ipynb , mushrooms.csv
WalkthroughAdds a new README at Machine_Learning/Mushroom Classification/README.md describing a Mushroom Classification project, dataset, preprocessing (label encoding, train/test split, scaling), and model evaluation for KNN, Logistic Regression, and Random Forest with reported metrics and a brief summary. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Suggested labels
Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
👋 Thank you for opening this pull request! We're excited to review your contribution. Please give us a moment, and we'll get back to you shortly! Feel free to join our community on Discord to discuss more! |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
17 similar comments
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
2 similar comments
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
|
✅ PR validation passed! Syncing labels and assignees from the linked issue... |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (5)
Machine_Learning/Mushroom Classification/README.md (5)
1-3: Tighten intro (trailing space, minor formatting).
- Line 1 has a trailing space after the heading.
- Consider adding a one-line “What’s inside” summary to anchor readers.
Apply:
-# 🍄 Mushroom Classification +# 🍄 Mushroom Classification + +Builds and compares KNN, Logistic Regression, and Random Forest to classify mushrooms as edible (e) or poisonous (p).
66-73: Results table: specify averaging, seeds, and add CV; interpretation wording.
- State averaging for precision/recall/F1 (macro/micro/weighted). Common: weighted for class imbalance or macro for parity.
- Report split seed and optionally 5-fold CV mean ± std to reduce variance.
- Column header casing (“interpretation”) and phrasing could be more specific.
-| Model | Accuracy | Precision | Recall | F1-Score | interpretation | +| Model | Accuracy | Precision (macro) | Recall (macro) | F1-Score (macro) | Interpretation |Add below the table:
+Notes: +- Metrics computed on a stratified 20% hold-out (random_state=42). For robustness, also report 5-fold CV mean ± std on the training set.Also verify LR preprocessing; with proper one-hot, LR typically reaches near-perfect on this dataset. Re-run to confirm whether 94.77% persists.
76-84: Add a clear safety disclaimer.Even with 100% test accuracy, readers should not use this model for real-life foraging decisions.
📌 In practical applications, **Random Forest** is preferred due to efficiency and robustness. + +> Safety disclaimer: This project is for educational purposes only and must not be used to identify wild mushrooms for consumption.
86-90: Add License & Citation section.Include project license and credit the dataset provider(s).
GitHub: [archangel2006](https://github.com/archangel2006/) +--- +## 📄 License & Citation + +- Code license: MIT (or repository’s default). Update if different. +- Data: “Mushroom” dataset from the UCI Machine Learning Repository. If using the Kaggle mirror, also cite the Kaggle dataset page. Review and comply with dataset terms.
49-55: EDA: treat "?" as unknowns; clarify "correlation" for categorical features.Found evidence: the notebook includes "?" placeholders (stalk-root). Recommend updating README to note handling of "?" and to use a precise association measure for categorical features.
Files to update:
- Machine_Learning/Mushroom Classification/README.md (EDA section, lines ~49–55)
- Machine_Learning/Mushroom Classification/Mushroom Classifier (KNN, RandomForest, LogisticRegression).ipynb — shows "stalk-root: ['e' 'c' 'b' 'r' '?']" (ipynb:1266)
Suggested diff:
- - Checked shape, data types, null values (none found). + - Checked shape, dtypes, null values, and “?” placeholders for unknowns (e.g., stalk-root contains '?') — treat/encode these as missing during preprocessing. ... - - Visualized correlation between selected categorical features and class. + - Assessed association between categorical features and class using chi-square / Cramér’s V (or mutual information) rather than an ambiguous "correlation" term.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
Machine_Learning/Mushroom Classification/mushrooms.csvis excluded by!**/*.csv
📒 Files selected for processing (1)
Machine_Learning/Mushroom Classification/README.md(1 hunks)
🧰 Additional context used
🪛 LanguageTool
Machine_Learning/Mushroom Classification/README.md
[grammar] ~1-~1: There might be a mistake here.
Context: # 🍄 Mushroom Classification This project builds and compares multiple...
(QB_NEW_EN)
[grammar] ~10-~10: There might be a mistake here.
Context: ... evaluating three classification models: - K-Nearest Neighbors (KNN) - Logistic Reg...
(QB_NEW_EN)
[grammar] ~11-~11: There might be a mistake here.
Context: ...tion models: - K-Nearest Neighbors (KNN) - Logistic Regression - Random Forest … a...
(QB_NEW_EN)
[grammar] ~12-~12: There might be a mistake here.
Context: ...st Neighbors (KNN) - Logistic Regression - Random Forest … and determine which per...
(QB_NEW_EN)
[grammar] ~20-~20: There might be a mistake here.
Context: ...classification. --- ## 📂 Dataset Source: [UCI Mushroom Dataset](https://...
(QB_NEW_EN)
[grammar] ~20-~20: There might be a mistake here.
Context: ...aset Source: UCI Mushroom Dataset Target Variable: class (e = edible, p...
(QB_NEW_EN)
[grammar] ~25-~25: There might be a mistake here.
Context: ...= poisonous) Features : - cap-shape - cap-surface - cap-color - bruises - odor...
(QB_NEW_EN)
[grammar] ~26-~26: There might be a mistake here.
Context: ...Features : - cap-shape - cap-surface - cap-color - bruises - odor - gill-attach...
(QB_NEW_EN)
[grammar] ~27-~27: There might be a mistake here.
Context: ...** - cap-shape - cap-surface - cap-color - bruises - odor - gill-attachment - gill-...
(QB_NEW_EN)
[grammar] ~28-~28: There might be a mistake here.
Context: ...hape - cap-surface - cap-color - bruises - odor - gill-attachment - gill-spacing - ...
(QB_NEW_EN)
[grammar] ~29-~29: There might be a mistake here.
Context: ...cap-surface - cap-color - bruises - odor - gill-attachment - gill-spacing - gill-si...
(QB_NEW_EN)
[grammar] ~30-~30: There might be a mistake here.
Context: ...color - bruises - odor - gill-attachment - gill-spacing - gill-size - gill-color ...
(QB_NEW_EN)
[grammar] ~31-~31: There might be a mistake here.
Context: ... - odor - gill-attachment - gill-spacing - gill-size - gill-color - stalk-shape -...
(QB_NEW_EN)
[grammar] ~32-~32: There might be a mistake here.
Context: ...ll-attachment - gill-spacing - gill-size - gill-color - stalk-shape - stalk-root ...
(QB_NEW_EN)
[grammar] ~33-~33: There might be a mistake here.
Context: ... - gill-spacing - gill-size - gill-color - stalk-shape - stalk-root - stalk-surface...
(QB_NEW_EN)
[grammar] ~34-~34: There might be a mistake here.
Context: ...- gill-size - gill-color - stalk-shape - stalk-root - stalk-surface-above-ring - ...
(QB_NEW_EN)
[grammar] ~35-~35: There might be a mistake here.
Context: ... gill-color - stalk-shape - stalk-root - stalk-surface-above-ring - stalk-surface...
(QB_NEW_EN)
[grammar] ~36-~36: There might be a mistake here.
Context: ... - stalk-root - stalk-surface-above-ring - stalk-surface-below-ring - stalk-color-a...
(QB_NEW_EN)
[grammar] ~37-~37: There might be a mistake here.
Context: ...ce-above-ring - stalk-surface-below-ring - stalk-color-above-ring - stalk-color-bel...
(QB_NEW_EN)
[grammar] ~38-~38: There might be a mistake here.
Context: ...face-below-ring - stalk-color-above-ring - stalk-color-below-ring - veil-type veil-...
(QB_NEW_EN)
[grammar] ~39-~39: There might be a mistake here.
Context: ...olor-above-ring - stalk-color-below-ring - veil-type veil-color - ring-number - rin...
(QB_NEW_EN)
[grammar] ~40-~40: There might be a mistake here.
Context: ...ing - stalk-color-below-ring - veil-type veil-color - ring-number - ring-type - s...
(QB_NEW_EN)
[grammar] ~40-~40: There might be a mistake here.
Context: ...-color-below-ring - veil-type veil-color - ring-number - ring-type - spore-print-co...
(QB_NEW_EN)
[grammar] ~41-~41: There might be a mistake here.
Context: ...ing - veil-type veil-color - ring-number - ring-type - spore-print-color - populati...
(QB_NEW_EN)
[grammar] ~42-~42: There might be a mistake here.
Context: ...ype veil-color - ring-number - ring-type - spore-print-color - population - habitat...
(QB_NEW_EN)
[grammar] ~43-~43: There might be a mistake here.
Context: ...g-number - ring-type - spore-print-color - population - habitat --- ## 🔍 Explora...
(QB_NEW_EN)
[grammar] ~44-~44: There might be a mistake here.
Context: ...ng-type - spore-print-color - population - habitat --- ## 🔍 Exploratory Data Ana...
(QB_NEW_EN)
[grammar] ~50-~50: There might be a mistake here.
Context: ...## 🔍 Exploratory Data Analysis (EDA) - Checked shape, data types, null values (n...
(QB_NEW_EN)
[grammar] ~50-~50: There might be a mistake here.
Context: ...lysis (EDA) - Checked shape, data types, null values (none found). - Examined cla...
(QB_NEW_EN)
[grammar] ~51-~51: There might be a mistake here.
Context: ...data types, null values (none found). - Examined class distribution – fairly bala...
(QB_NEW_EN)
[grammar] ~51-~51: There might be a mistake here.
Context: ...ed class distribution – fairly balanced. - Analyzed frequency of each feature's uni...
(QB_NEW_EN)
[grammar] ~52-~52: There might be a mistake here.
Context: ...equency of each feature's unique values. - Visualized correlation between selected ...
(QB_NEW_EN)
[grammar] ~61-~61: There might be a mistake here.
Context: ...Scaler` (for KNN & Logistic Regression). - All models trained on the same preproces...
(QB_NEW_EN)
[grammar] ~66-~66: There might be a mistake here.
Context: ...comparison. --- ## 🧠 Model Comparison | Model | Accuracy | Precis...
(QB_NEW_EN)
[grammar] ~68-~68: There might be a mistake here.
Context: ...n | Recall | F1-Score | interpretation | |--------------------|----------|-------...
(QB_NEW_EN)
[grammar] ~69-~69: There might be a mistake here.
Context: ...-----------|--------|----------|-------| | KNN | 100% | 1.00 ...
(QB_NEW_EN)
[grammar] ~70-~70: There might be a mistake here.
Context: ... | 1.00 | 1.00 | Great accuracy | | Logistic Regression | 94.77% | 0.94 ...
(QB_NEW_EN)
[grammar] ~71-~71: There might be a mistake here.
Context: ... | 0.94 | Strong linear separator | | Random Forest | 100% | 1.00 ...
(QB_NEW_EN)
[grammar] ~76-~76: There might be a mistake here.
Context: ...robust model | --- ## 🏆 Final Verdict Both KNN and Random Forest achiev...
(QB_NEW_EN)
[grammar] ~83-~83: There might be a mistake here.
Context: ...ferred due to efficiency and robustness. --- ## 👤 Author GitHub: [archangel2006](https:...
(QB_NEW_EN)
[grammar] ~86-~86: There might be a mistake here.
Context: ...ciency and robustness. --- ## 👤 Author GitHub: [archangel2006](https://github.co...
(QB_NEW_EN)
🪛 markdownlint-cli2 (0.17.2)
Machine_Learning/Mushroom Classification/README.md
40-40: Hard tabs
Column: 12
(MD010, no-hard-tabs)
| ## 📂 Dataset | ||
| **Source:** [UCI Mushroom Dataset](https://www.kaggle.com/datasets/uciml/mushroom-classification) | ||
|
|
||
| **Target Variable:** `class` (e = edible, p = poisonous) | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Fix dataset attribution and citation (Kaggle mirror vs. UCI source).
The link points to Kaggle but the text says “UCI Mushroom Dataset.” Please credit UCI as the source and note Kaggle as a mirror. Add a brief citation and licensing note to avoid ambiguity.
-## 📂 Dataset
-**Source:** [UCI Mushroom Dataset](https://www.kaggle.com/datasets/uciml/mushroom-classification)
+## 📂 Dataset
+**Source:** UCI Machine Learning Repository (Mushroom dataset). Kaggle link below is a mirrored copy.
+
+- UCI: https://archive.ics.uci.edu/ml/datasets/Mushroom
+- Kaggle mirror: https://www.kaggle.com/datasets/uciml/mushroom-classification
+
+Please review dataset licensing/terms at the source before redistribution.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ## 📂 Dataset | |
| **Source:** [UCI Mushroom Dataset](https://www.kaggle.com/datasets/uciml/mushroom-classification) | |
| **Target Variable:** `class` (e = edible, p = poisonous) | |
| ## 📂 Dataset | |
| **Source:** UCI Machine Learning Repository (Mushroom dataset). Kaggle link below is a mirrored copy. | |
| - UCI: https://archive.ics.uci.edu/ml/datasets/Mushroom | |
| - Kaggle mirror: https://www.kaggle.com/datasets/uciml/mushroom-classification | |
| Please review dataset licensing/terms at the source before redistribution. | |
| **Target Variable:** `class` (e = edible, p = poisonous) |
🧰 Tools
🪛 LanguageTool
[grammar] ~20-~20: There might be a mistake here.
Context: ...classification. --- ## 📂 Dataset Source: [UCI Mushroom Dataset](https://...
(QB_NEW_EN)
[grammar] ~20-~20: There might be a mistake here.
Context: ...aset Source: UCI Mushroom Dataset Target Variable: class (e = edible, p...
(QB_NEW_EN)
🤖 Prompt for AI Agents
In Machine_Learning/Mushroom Classification/README.md around lines 19 to 23, the
dataset attribution is ambiguous (linking to a Kaggle mirror but naming UCI as
the source); update the text to clearly credit the UCI Mushroom Dataset as the
original source, mention the Kaggle link as a mirror, and add a short citation
and licensing note (e.g., reference the UCI dataset page and state mirror on
Kaggle, plus any applicable license or usage terms) so readers know provenance
and reuse constraints.
| **Features :** | ||
| - cap-shape | ||
| - cap-surface | ||
| - cap-color | ||
| - bruises | ||
| - odor | ||
| - gill-attachment | ||
| - gill-spacing | ||
| - gill-size | ||
| - gill-color | ||
| - stalk-shape | ||
| - stalk-root | ||
| - stalk-surface-above-ring | ||
| - stalk-surface-below-ring | ||
| - stalk-color-above-ring | ||
| - stalk-color-below-ring | ||
| - veil-type veil-color | ||
| - ring-number | ||
| - ring-type | ||
| - spore-print-color | ||
| - population | ||
| - habitat |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Correct feature list; remove hard tab and split “veil-type/veil-color.”
- “veil-type veil-color” contains a hard tab (MD010) and merges two features.
- Normalize punctuation (“Features :” → “Features:”).
- Keep one item per bullet for grep-ability.
-**Features :**
+**Features:**
...
-- veil-type veil-color
+- veil-type
+- veil-color📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| **Features :** | |
| - cap-shape | |
| - cap-surface | |
| - cap-color | |
| - bruises | |
| - odor | |
| - gill-attachment | |
| - gill-spacing | |
| - gill-size | |
| - gill-color | |
| - stalk-shape | |
| - stalk-root | |
| - stalk-surface-above-ring | |
| - stalk-surface-below-ring | |
| - stalk-color-above-ring | |
| - stalk-color-below-ring | |
| - veil-type veil-color | |
| - ring-number | |
| - ring-type | |
| - spore-print-color | |
| - population | |
| - habitat | |
| **Features:** | |
| - cap-shape | |
| - cap-surface | |
| - cap-color | |
| - bruises | |
| - odor | |
| - gill-attachment | |
| - gill-spacing | |
| - gill-size | |
| - gill-color | |
| - stalk-shape | |
| - stalk-root | |
| - stalk-surface-above-ring | |
| - stalk-surface-below-ring | |
| - stalk-color-above-ring | |
| - stalk-color-below-ring | |
| - veil-type | |
| - veil-color | |
| - ring-number | |
| - ring-type | |
| - spore-print-color | |
| - population | |
| - habitat |
🧰 Tools
🪛 LanguageTool
[grammar] ~25-~25: There might be a mistake here.
Context: ...= poisonous) Features : - cap-shape - cap-surface - cap-color - bruises - odor...
(QB_NEW_EN)
[grammar] ~26-~26: There might be a mistake here.
Context: ...Features : - cap-shape - cap-surface - cap-color - bruises - odor - gill-attach...
(QB_NEW_EN)
[grammar] ~27-~27: There might be a mistake here.
Context: ...** - cap-shape - cap-surface - cap-color - bruises - odor - gill-attachment - gill-...
(QB_NEW_EN)
[grammar] ~28-~28: There might be a mistake here.
Context: ...hape - cap-surface - cap-color - bruises - odor - gill-attachment - gill-spacing - ...
(QB_NEW_EN)
[grammar] ~29-~29: There might be a mistake here.
Context: ...cap-surface - cap-color - bruises - odor - gill-attachment - gill-spacing - gill-si...
(QB_NEW_EN)
[grammar] ~30-~30: There might be a mistake here.
Context: ...color - bruises - odor - gill-attachment - gill-spacing - gill-size - gill-color ...
(QB_NEW_EN)
[grammar] ~31-~31: There might be a mistake here.
Context: ... - odor - gill-attachment - gill-spacing - gill-size - gill-color - stalk-shape -...
(QB_NEW_EN)
[grammar] ~32-~32: There might be a mistake here.
Context: ...ll-attachment - gill-spacing - gill-size - gill-color - stalk-shape - stalk-root ...
(QB_NEW_EN)
[grammar] ~33-~33: There might be a mistake here.
Context: ... - gill-spacing - gill-size - gill-color - stalk-shape - stalk-root - stalk-surface...
(QB_NEW_EN)
[grammar] ~34-~34: There might be a mistake here.
Context: ...- gill-size - gill-color - stalk-shape - stalk-root - stalk-surface-above-ring - ...
(QB_NEW_EN)
[grammar] ~35-~35: There might be a mistake here.
Context: ... gill-color - stalk-shape - stalk-root - stalk-surface-above-ring - stalk-surface...
(QB_NEW_EN)
[grammar] ~36-~36: There might be a mistake here.
Context: ... - stalk-root - stalk-surface-above-ring - stalk-surface-below-ring - stalk-color-a...
(QB_NEW_EN)
[grammar] ~37-~37: There might be a mistake here.
Context: ...ce-above-ring - stalk-surface-below-ring - stalk-color-above-ring - stalk-color-bel...
(QB_NEW_EN)
[grammar] ~38-~38: There might be a mistake here.
Context: ...face-below-ring - stalk-color-above-ring - stalk-color-below-ring - veil-type veil-...
(QB_NEW_EN)
[grammar] ~39-~39: There might be a mistake here.
Context: ...olor-above-ring - stalk-color-below-ring - veil-type veil-color - ring-number - rin...
(QB_NEW_EN)
[grammar] ~40-~40: There might be a mistake here.
Context: ...ing - stalk-color-below-ring - veil-type veil-color - ring-number - ring-type - s...
(QB_NEW_EN)
[grammar] ~40-~40: There might be a mistake here.
Context: ...-color-below-ring - veil-type veil-color - ring-number - ring-type - spore-print-co...
(QB_NEW_EN)
[grammar] ~41-~41: There might be a mistake here.
Context: ...ing - veil-type veil-color - ring-number - ring-type - spore-print-color - populati...
(QB_NEW_EN)
[grammar] ~42-~42: There might be a mistake here.
Context: ...ype veil-color - ring-number - ring-type - spore-print-color - population - habitat...
(QB_NEW_EN)
[grammar] ~43-~43: There might be a mistake here.
Context: ...g-number - ring-type - spore-print-color - population - habitat --- ## 🔍 Explora...
(QB_NEW_EN)
[grammar] ~44-~44: There might be a mistake here.
Context: ...ng-type - spore-print-color - population - habitat --- ## 🔍 Exploratory Data Ana...
(QB_NEW_EN)
🪛 markdownlint-cli2 (0.17.2)
40-40: Hard tabs
Column: 12
(MD010, no-hard-tabs)
🤖 Prompt for AI Agents
In Machine_Learning/Mushroom Classification/README.md around lines 24 to 45,
normalize the header punctuation and clean the feature list: change "Features :"
to "Features:", remove the hard tab between "veil-type" and "veil-color" and
split them into two separate bullet items (one feature per line) so each feature
is its own list entry and grep-able; also ensure no trailing spaces and
consistent hyphenation across items.
| ## ⚙️ Preprocessing | ||
| - Label encoding applied to all categorical variables. | ||
| - Train-test split using `train_test_split` (test size = 20%). | ||
| - Feature scaling using `StandardScaler` (for KNN & Logistic Regression). | ||
| - All models trained on the same preprocessed data for fair comparison. | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Preprocessing: avoid ordinal leakage; use per-model pipelines and stratification.
- Label encoding all categoricals imposes arbitrary order, harming LR/KNN and explaining LR ≈95%.
- Scale only numeric (or one-hot) features; never scale label-encoded category IDs.
- Fit transformers on train only; use stratified split with fixed random_state.
- - Label encoding applied to all categorical variables.
- - Train-test split using `train_test_split` (test size = 20%).
- - Feature scaling using `StandardScaler` (for KNN & Logistic Regression).
- - All models trained on the same preprocessed data for fair comparison.
+ - Encoding:
+ - Use `OneHotEncoder(handle_unknown="ignore", sparse_output=False)` for KNN & Logistic Regression.
+ - Random Forest can use one-hot as well (keeps consistency) or `OrdinalEncoder` if desired.
+ - Split: `train_test_split(..., test_size=0.2, stratify=y, random_state=42)`.
+ - Scaling: apply `StandardScaler` only to one-hot/continuous features used by KNN/LR.
+ - Implement per-model `Pipeline` + `ColumnTransformer`, fit on train, transform test to prevent leakage.If helpful, I can provide a minimal sklearn Pipeline snippet tailored to your notebook.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ## ⚙️ Preprocessing | |
| - Label encoding applied to all categorical variables. | |
| - Train-test split using `train_test_split` (test size = 20%). | |
| - Feature scaling using `StandardScaler` (for KNN & Logistic Regression). | |
| - All models trained on the same preprocessed data for fair comparison. | |
| ## ⚙️ Preprocessing | |
| - Encoding: | |
| - Use `OneHotEncoder(handle_unknown="ignore", sparse_output=False)` for KNN & Logistic Regression. | |
| - Random Forest can use one-hot as well (keeps consistency) or `OrdinalEncoder` if desired. | |
| - Split: `train_test_split(..., test_size=0.2, stratify=y, random_state=42)`. | |
| - Scaling: apply `StandardScaler` only to one-hot/continuous features used by KNN/LR. | |
| - Implement per-model `Pipeline` + `ColumnTransformer`, fit on train, transform test to prevent leakage. |
🧰 Tools
🪛 LanguageTool
[grammar] ~61-~61: There might be a mistake here.
Context: ...Scaler` (for KNN & Logistic Regression). - All models trained on the same preproces...
(QB_NEW_EN)
🤖 Prompt for AI Agents
In Machine_Learning/Mushroom Classification/README.md around lines 58 to 63, the
preprocessing notes are unsafe: label-encoding all categoricals creates
artificial ordinality and can leak information to models like
LogisticRegression/KNN, scaling is being applied to encoded category IDs, and
transformers may be fit on full data without stratification. Fix by performing a
stratified train_test_split(test_size=0.2, random_state=...) on the target, then
build per-model sklearn Pipelines that fit transformers only on the training
fold: for linear models and KNN use OneHotEncoder (or ColumnTransformer) for
categoricals and StandardScaler only on numeric (or on the one-hot outputs if
needed), avoid using ordinal LabelEncoder for features, and ensure all
fit/transform calls happen inside the pipeline so preprocessing is not exposed
to the test set.
Pull Request for PyVerse 💡
Requesting to submit a pull request to the PyVerse repository.
Issue Title
Please enter the title of the issue related to your pull request.
[Code Addition Request]: Mushroom Classifier (KNN, RandomForest, LogisticRegression) #1714
Info about the Related Issue
What's the goal of the project?
To classify mushrooms as edible (e) or poisonous (p) based on their categorical features. The goal is to build a robust model that generalizes well and can assist in safe mushroom identification.
Comparing and evaluating three classification models:
K-Nearest Neighbors (KNN)
Logistic Regression
Random Forest
Evaluation metrics such as accuracy, precision, recall, and F1-score are used to compare model performance.
I have described the aim of the project.
Name
Please mention your name.
Vaibhavi Srivastava
GitHub ID
Please mention your GitHub ID.
archangel2006
Email ID
Please mention your email ID for further communication.
26.archangel@gmail.com
Identify Yourself
Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC, SWOC).
Contributor SSoC25
Closes
Enter the issue number that will be closed through this PR.
Closes: #1714
Describe the Add-ons or Changes You've Made
Give a clear description of what you have added or modified.
Added Files in Mushroom Classification (new folder created) : Mushroom Classifier (KNN, RandomForest, LogisticRegression).ipynb , mushrooms.csv , README.md for the project
Type of Change
Select the type of change:
How Has This Been Tested?
Describe how your changes have been tested.
All cells have been run on colab notebook
Checklist
Please confirm the following:
Summary by CodeRabbit