Download pages/Ensemble.py from Phaneendrabayi/Zero_To_Hero_Machine_Learning: direct link, hf CLI and curl.
- Browser
- Download file 5.25 kB
-
https://huggingface.co/spaces/Phaneendrabayi/Zero_To_Hero_Machine_Learning/resolve/main/pages/Ensemble.py
- Command line
-
hf download hf://spaces/Phaneendrabayi/Zero_To_Hero_Machine_Learning/pages/Ensemble.py
-
curl -L -o Ensemble.py https://huggingface.co/spaces/Phaneendrabayi/Zero_To_Hero_Machine_Learning/resolve/main/pages/Ensemble.py
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**. | |
| """) | |