giodesi/Multi-class_Classification
๐ฏ Multi-class Classification Web App
Overview
This generalized Streamlit application enables you to perform multi-class classification analysis on any CSV dataset. While standard logistic regression is limited to binary outcomes, this tool utilizes One-vs-Rest (OvR) and One-vs-One (OvO) strategies to predict outcomes with three or more categories (e.g., Low/Medium/High, distinct species, or specific medical grades).
The app includes a complete pipeline from data preprocessing (handling missing values, scaling, encoding) to model training and prediction, making machine learning accessible for complex classification tasks.
How to Use
The application guides you through a step-by-step machine learning workflow using a tabbed interface.
- Upload Data: Upload your CSV file in the sidebar. The app automatically detects feature types.
- Configuration:
- Select your Target Column (the categorical variable to predict).
- Select Feature Columns (predictors).
- Choose Preprocessing options (Standardization, One-Hot Encoding).
- Select the Multi-class Strategy (OvR, OvO, or Auto) and Test Set size.
- Preprocessing: Go to the Preprocessing tab and click 'Apply Preprocessing'. This handles missing values (Median/Mode imputation), scales numerical data, and encodes categorical text data.
- Training: Switch to the Training tab and click 'Train Model' to fit the Logistic Regression classifier.
- Results: Analyze performance metrics (Accuracy, Precision, Recall, F1) and visualize the Confusion Matrix and Feature Importance.
- Predict: Use the Predict New Data tab to upload a new CSV or manually enter values to get predictions from your trained model.
Key Features
The application implements the logic defined in Multi-class_Classification.ipynb wrapped in an interactive app.py interface.
- Multi-class Strategies: Implements Logistic Regression capable of handling multiple classes via:
- One-vs-Rest (OvR): Trains a binary classifier for each class against all others.
- One-vs-One (OvO): Trains a binary classifier for every pair of classes.
- Advanced Preprocessing:
- Imputation: Automatically fills missing numerical values with the median and categorical values with the mode.
- Encoding: Uses
OneHotEncoderto convert categorical text features into a machine-readable format. - Scaling: Uses
StandardScalerto normalize numerical features for better model convergence. - Comprehensive Evaluation: Provides Weighted Precision, Recall, and F1-Scores, along with a heatmap-style Confusion Matrix.
- Feature Importance: Visualizes which features (based on average absolute coefficients) impact the model the most.
- Export Capabilities: Download predictions on new data or export the classification report as a CSV.
Data Requirements
The app is designed to be flexible:
- Format: CSV file.
- Features: Can be Numerical (continuous) or Categorical (text/object). The app handles encoding automatically.
- Target: Can be a text labels (e.g., "ObesityTypeI") or numeric codes.
- Missing Values: Supported. The app calculates training statistics (medians/modes) to impute missing data in both training and prediction phases.
Example Use Case: Obesity Risk
The repository includes Obesity_level_prediction_dataset.csv as a primary example.
- Goal: Predict the obesity level of an individual based on eating habits and physical condition.
- Classes: InsufficientWeight, NormalWeight, OverweightLevelI, OverweightLevelII, ObesityTypeI, ObesityTypeII, ObesityTypeIII.
- Features: Mix of numerical (Age, Height, Weight) and categorical (Gender, family_history, transportation method).
Technical Implementation
- Framework: Streamlit.
- Core Logic:
scikit-learn(LogisticRegression,OneVsOneClassifier,OneVsRestClassifier). - Preprocessing:
OneHotEncoder,StandardScaler,LabelEncoder. - State Management: Uses
st.session_stateto persist the trained model, encoders, and scalers, ensuring the prediction pipeline matches the training pipeline exactly.
Source Code
The project files are available on GitHub at **Multi-class_Classification**:
app.py: The main Streamlit application.Multi-class_Classification.ipynb: Jupyter notebook explaining the underlying logic and OvR/OvO concepts.Obesity_level_prediction_dataset.csv: Sample dataset.
License
This project is released under the MIT License.
