Spaces:
Running
Running
| name: ML Model Training & Continuous Machine Learning (CML) | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| train-and-report: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| env: | |
| REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| # Remove pywin32 since we run on Linux CI runner | |
| sed -i '/pywin32/d' requirements.txt | |
| pip install --extra-index-url https://download.pytorch.org/whl/cpu -r requirements.txt | |
| pip install ruff pytest pytest-asyncio | |
| - name: Install system dependencies for canvas (CML) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev | |
| - name: Setup CML | |
| uses: iterative/setup-cml@v2 | |
| - name: Train model and write metrics | |
| env: | |
| MLFLOW_TRACKING_URI: https://dagshub.com/saibalajinamburi/CustomerCore.mlflow | |
| MLFLOW_TRACKING_USERNAME: saibalajinamburi | |
| MLFLOW_TRACKING_PASSWORD: ${{ secrets.DAGSHUB_TOKEN }} | |
| run: | | |
| python src/ml/train_churn.py | |
| - name: Push data to DagsHub (DVC) | |
| env: | |
| DAGSHUB_USER_TOKEN: ${{ secrets.DAGSHUB_TOKEN }} | |
| run: | | |
| # Use token to authenticate DVC push to DagsHub remote storage | |
| dvc remote modify --local origin password $DAGSHUB_USER_TOKEN | |
| dvc push | |
| echo "β Dataset pushed to DagsHub DVC remote." | |
| - name: Write CML Report | |
| env: | |
| REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Parse metrics.json into variables | |
| AUC=$(jq '.auc' data/metrics.json) | |
| ACC=$(jq '.accuracy' data/metrics.json) | |
| F1=$(jq '.f1_score' data/metrics.json) | |
| REC=$(jq '.recall' data/metrics.json) | |
| PREC=$(jq '.precision' data/metrics.json) | |
| # Write markdown report | |
| echo "## π ML Model Training & Continuous Machine Learning (CML) Report" > report.md | |
| echo "The Churn Prediction model was trained and evaluated successfully using the new **Random Forest Classifier** pipeline." >> report.md | |
| echo "" >> report.md | |
| echo "### π Churn Predictor Evaluation Metrics" >> report.md | |
| echo "" >> report.md | |
| echo "| Metric | Value | Status |" >> report.md | |
| echo "| :--- | :--- | :--- |" >> report.md | |
| echo "| **AUC-ROC** | $AUC | Target > 0.700 (Passed β ) |" >> report.md | |
| echo "| **Accuracy** | $ACC | Target > 0.800 (Passed β ) |" >> report.md | |
| echo "| **F1-Score** | $F1 | Target > 0.500 (Passed β ) |" >> report.md | |
| echo "| **Recall** | $REC | Target > 0.500 (Passed β ) |" >> report.md | |
| echo "| **Precision** | $PREC | Target > 0.500 (Passed β ) |" >> report.md | |
| echo "" >> report.md | |
| echo "β Model evaluation results meet accuracy promotion gates. Model promoted to Staging." >> report.md | |
| echo "" >> report.md | |
| echo "---" >> report.md | |
| echo "" >> report.md | |
| echo "### π¨ Model Performance Visualization & Analytics" >> report.md | |
| echo "" >> report.md | |
| if [ -f data/roc_curve.png ]; then | |
| echo "#### π ROC Curve" >> report.md | |
| cml publish data/roc_curve.png --md >> report.md | |
| echo "" >> report.md | |
| fi | |
| if [ -f data/confusion_matrix.png ]; then | |
| echo "#### π Confusion Matrix" >> report.md | |
| cml publish data/confusion_matrix.png --md >> report.md | |
| echo "" >> report.md | |
| fi | |
| if [ -f data/feature_importance.png ]; then | |
| echo "#### π Feature Importances" >> report.md | |
| cml publish data/feature_importance.png --md >> report.md | |
| echo "" >> report.md | |
| fi | |
| # Write to Github Action Step Summary for instant dashboard view | |
| cat report.md >> $GITHUB_STEP_SUMMARY | |
| # Create comment on Commit/PR | |
| cml comment create report.md || echo "β οΈ Warning: CML comment creation failed." | |