# Database & ML: Connect to Databases, Build ML Models

Connect to PostgreSQL/MySQL databases and perform advanced analytics directly in Excel using xlwings Lite. Run SQL queries, explore tables, perform EDA, and build XGBoost classification models with ROC curves and decile analysis.

## Links
- App: https://app.tigzig.com/xlwings-api-db
- Video Guide: https://youtu.be/rHERSN_Bay0
- Blog Post: https://www.tigzig.com/post/python-in-excel-with-xlwings-lite-part-2-connect-to-remote-databases
- GitHub (FastAPI server): https://github.com/amararun/shared-fastapi-rex-db-coolify

## Tags
python-in-excel, xlwings-lite, database-ai

## Download
- Excel Workbook: https://www.tigzig.com/files/xlwings/DATABASE_PULL_EDSACHARTS_TABLES_ML_MODEL_V3_1225.xlsx

## What It Does
- Connect to PostgreSQL/MySQL databases via FastAPI
- Explore tables, run custom SQL queries
- Statistical analysis and exploratory data analysis (EDA)
- Build ML models with XGBoost classifier
- Decile tables, ROC curves, gains charts
- Model scoring and evaluation metrics

### Architecture
- FastAPI server handles database connections
- API requests connect to PostgreSQL/MySQL
- All ML processing occurs locally in xlwings Lite (XGBoost runs in browser via Pyodide)

### Built-in Functions
- `list_tables` - List all database tables
- `get_custom_query` - Run SQL queries
- `perform_eda` - Exploratory data analysis with charts
- `score_and_deciles` - XGBoost classification + decile tables

Note: The ML pipeline demonstrates capabilities - not a point-and-click app. For new datasets, work iteratively with an AI coder to adapt the script.

### Free Database Options
- neon.tech - Postgres, 500MB free
- Supabase - Postgres + auth, 500MB free
- Aiven - Postgres/MySQL, 5GB free

## Resources
- xlwings Lite: https://lite.xlwings.org
- xlwings Documentation: https://docs.xlwings.org/en/latest/
