Phaneendrabayi's picture
Create Ensemble.py
f73cf4b verified
Raw History Blame Contribute Delete
5.25 kB
import streamlit as st
import pandas as pd
st.set_page_config(page_title="Ensemble Learning Techniques")
st.title("🧠 Ensemble Machine Learning Techniques")
# Topic selector
view = st.radio("πŸ” Select Ensemble Technique", [
"🌳 Random Forest (Classification)",
"🌳 Random Forest (Regression)",
"🌲 Gradient Boosting (Classification)",
"🌲 Gradient Boosting (Regression)",
"πŸ”₯ AdaBoost (Classification)",
"πŸ”₯ AdaBoost (Regression)"
], horizontal=True)
if view == "🌳 Random Forest (Classification)":
st.header("🌳 Random Forest Classifier")
st.markdown("""
Random Forest is an ensemble method that builds multiple **decision trees** and combines their results to improve accuracy and reduce overfitting.
### πŸ” How it Works:
- Trains multiple decision trees on bootstrapped samples.
- Each tree votes; majority class wins.
### βœ… Use Cases:
- Spam detection
- Medical diagnosis
### πŸ”§ Key Parameters:
- `n_estimators`: Number of trees in the forest.
- `max_depth`: Maximum depth of each tree.
- `min_samples_split`: Minimum samples to split a node.
- `min_samples_leaf`: Minimum samples in a leaf node.
- `max_features`: Number of features to consider when looking for best split.
- `bootstrap`: Whether bootstrap samples are used.
### Pros:
- Handles high-dimensional data well
- Reduces variance (robust to overfitting)
### Cons:
- Slower for real-time predictions
- Can be less interpretable
""")
elif view == "🌳 Random Forest (Regression)":
st.header("🌳 Random Forest Regressor")
st.markdown("""
Random Forest for regression aggregates the output of multiple regression trees by **averaging their outputs**.
### πŸ” How it Works:
- Each tree predicts a value.
- Final output = average of all tree outputs.
### βœ… Use Cases:
- Price prediction
- Forecasting trends
### πŸ”§ Key Parameters:
- Same as classifier (`n_estimators`, `max_depth`, etc.)
### Pros:
- Captures complex relationships
- Handles non-linearity well
### Cons:
- Slower than simpler models
- Overfitting if not tuned properly
""")
elif view == "🌲 Gradient Boosting (Classification)":
st.header("🌲 Gradient Boosting Classifier")
st.markdown("""
Gradient Boosting is a sequential ensemble technique that builds trees one after another, **each trying to correct the error** of the previous one.
### πŸ” How it Works:
- Uses gradient descent to minimize the loss.
- Trees are shallow (weak learners).
### βœ… Use Cases:
- Customer churn prediction
- Credit scoring
### πŸ”§ Key Parameters:
- `n_estimators`: Number of boosting stages.
- `learning_rate`: Shrinks the contribution of each tree.
- `max_depth`: Depth of each individual tree.
- `subsample`: Fraction of samples used for fitting.
### Pros:
- High accuracy
- Handles mixed data well
### Cons:
- Sensitive to hyperparameters
- Can overfit on noisy data
""")
elif view == "🌲 Gradient Boosting (Regression)":
st.header("🌲 Gradient Boosting Regressor")
st.markdown("""
Similar to classification but optimized for **continuous values** using gradient descent on regression loss functions.
### βœ… Use Cases:
- Demand forecasting
- House price prediction
### πŸ”§ Parameters:
- Same as classification (`n_estimators`, `learning_rate`, etc.)
### Pros:
- Excellent performance on tabular data
### Cons:
- Training is slower
""")
elif view == "πŸ”₯ AdaBoost (Classification)":
st.header("πŸ”₯ AdaBoost Classifier")
st.markdown("""
AdaBoost stands for **Adaptive Boosting**. It combines weak learners sequentially, **giving more weight to misclassified instances**.
### πŸ” How it Works:
- Learns sequentially.
- Harder instances are focused in later learners.
### βœ… Use Cases:
- Fraud detection
- Face detection
### πŸ”§ Key Parameters:
- `n_estimators`: Number of weak learners.
- `learning_rate`: Weight given to each learner.
- `base_estimator`: Default is decision stump.
### Pros:
- Simple and effective
- Works well with fewer features
### Cons:
- Sensitive to noise
- Poor with complex data unless base estimator is strong
""")
elif view == "πŸ”₯ AdaBoost (Regression)":
st.header("πŸ”₯ AdaBoost Regressor")
st.markdown("""
Boosts weak regressors sequentially, correcting residual errors of previous models.
### βœ… Use Cases:
- Stock price prediction
- Insurance risk modeling
### πŸ”§ Parameters:
- Same as classifier (`n_estimators`, `learning_rate`, `loss`, etc.)
### Pros:
- Robust to overfitting if tuned
### Cons:
- Sensitive to outliers
""")
st.markdown("""
---
πŸ“Œ **Note**: Ensemble methods perform better with **hyperparameter tuning**. Use tools like `Optuna`, `GridSearchCV`, or `RandomizedSearchCV` to find the best model parameters.
πŸ“Œ **Pro Tip**: Feature importance scores from tree-based models help in **feature selection** and **interpretability**.
""")