A comprehensive tutorial series demonstrating the capabilities of the analytics_store package using insurance industry datasets. These exercises cover data loading, model validation, performance monitoring, and advanced analytics techniques.
This repository contains hands-on exercises organized by difficulty level and topic:
- Project Setup and Polars Basics - Environment setup and data manipulation fundamentals
- Introduction to Lift Analysis - Understanding lift curves with insurance claim predictions
- ROC Curve Analysis - Evaluating binary classification models for fraud detection
- Regression Metrics - Analyzing premium prediction models
- Model Comparison - Comparing multiple models using double lift analysis
- Data Loading from SQL - Connecting to databases and loading insurance data
- Population Testing - Statistical tests for comparing customer segments
- Model Monitoring & Drift Detection - Tracking model performance over time
- Snowflake Integration - Working with cloud data warehouses
- End-to-End Pipeline - Complete workflow from data loading to reporting
By completing these tutorials, you will learn to:
- Use
analytics_storefor comprehensive model evaluation - Work with Polars DataFrames for high-performance data analysis
- Load data from various sources (CSV, SQL, Snowflake)
- Evaluate classification and regression models
- Monitor model performance and detect data drift
- Compare multiple models and scoring approaches
- Generate professional analytics reports
- Python 3.8 or higher
- Basic understanding of Python and pandas/polars
- Familiarity with machine learning concepts (helpful but not required)
- Clone this repository:
git clone https://github.com/Wicks-Analytics/analytics_tutorials.git
cd analytics_tutorials- Choose your environment manager:
uv is an extremely fast Python package installer and resolver.
# Install uv (if not already installed)
# Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .
# Install optional dependencies
uv pip install -e ".[jupyter]" # For Jupyter notebooks
uv pip install -e ".[snowflake]" # For Snowflake tutorials
uv pip install -e ".[all]" # Install everything
# Install analytics_store
uv pip install git+https://github.com/Wicks-Analytics/analytics_store# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install analytics_store
pip install git+https://github.com/Wicks-Analytics/analytics_storeOption 1: Python Scripts
Start with Tutorial 00, then proceed through the beginner tutorials:
# Start here - setup and Polars basics
python tutorials/00_getting_started/00_setup_and_polars_basics.py
# Then proceed to beginner tutorials
python tutorials/01_beginner/01_lift_analysis.py
python tutorials/01_beginner/02_roc_analysis.py
python tutorials/01_beginner/03_regression_metrics.pyOption 2: Jupyter Notebooks (Recommended for Learning)
Interactive notebook versions are available in the notebooks/ folder:
# Install Jupyter
pip install jupyter jupyterlab
# Start JupyterLab
jupyter lab
# Navigate to notebooks/01_beginner/01_lift_analysis.ipynbConverting Scripts to Notebooks
Generate notebook versions from Python scripts:
python convert_to_notebooks.pyanalytics_tutorials/
βββ README.md # This file
βββ QUICKSTART.md # 5-minute setup guide
βββ TUTORIAL_INDEX.md # Complete tutorial reference
βββ requirements.txt # Python dependencies
βββ setup_database.py # Script to set up local SQLite database
βββ convert_to_notebooks.py # Convert Python scripts to Jupyter notebooks
βββ data/ # Sample datasets
β βββ insurance_claims.csv # Dummy insurance claims data
β βββ insurance_policies.csv # Dummy policy data
β βββ fraud_predictions.csv # Model predictions for fraud detection
βββ tutorials/ # Tutorial exercises (Python scripts)
β βββ 00_getting_started/
β β βββ 00_setup_and_polars_basics.py
β βββ 01_beginner/
β β βββ 01_lift_analysis.py
β β βββ 02_roc_analysis.py
β β βββ 03_regression_metrics.py
β βββ 02_intermediate/
β β βββ 04_model_comparison.py
β β βββ 05_sql_integration.py
β β βββ 06_population_testing.py
β βββ 03_advanced/
β βββ 07_model_monitoring.py
β βββ 08_snowflake_integration.py
β βββ 09_end_to_end_pipeline.py
βββ notebooks/ # Jupyter notebook versions
β βββ README.md # Notebook usage guide
β βββ 01_beginner/
β βββ 02_intermediate/
β βββ 03_advanced/
βββ solutions/ # Solutions with detailed explanations
β βββ 01_beginner/
β βββ 02_intermediate/
β βββ 03_advanced/
βββ utils/ # Helper utilities
β βββ __init__.py
β βββ data_generators.py # Functions to generate dummy data
β βββ database_helpers.py # Database connection utilities
βββ outputs/ # Generated plots and reports (gitignored)
The repository includes realistic dummy insurance datasets:
- insurance_claims.csv - Historical claims data with features and outcomes
- insurance_policies.csv - Policy information and customer demographics
- fraud_predictions.csv - Model predictions for fraud detection exercises
All data is synthetically generated and does not contain real customer information.
Run the setup script to create a local SQLite database:
python setup_database.pyUpdate the connection strings in utils/database_helpers.py with your credentials.
For Snowflake tutorials, you'll need:
- Snowflake account credentials
- Appropriate permissions to read data
- Update
config/snowflake_config.pywith your connection details
01 - Lift Analysis Learn to calculate and visualize lift curves for insurance claim predictions. Understand how to interpret lift metrics and identify model performance across deciles.
02 - ROC Analysis Evaluate binary classification models using ROC curves and AUC scores. Learn to find optimal thresholds for fraud detection models.
03 - Regression Metrics Analyze regression model performance for premium predictions. Calculate RMSE, MAE, R-squared, and create diagnostic plots.
04 - Model Comparison Compare multiple scoring models using double lift analysis. Understand joint and conditional lift metrics.
05 - SQL Integration Load insurance data from SQL databases using Polars. Learn efficient data loading patterns and query optimization.
06 - Population Testing Perform statistical tests to compare different customer segments. Use t-tests and Mann-Whitney U tests with effect size calculations.
07 - Model Monitoring Implement comprehensive model monitoring with drift detection. Track feature drift using PSI and performance metrics over time.
08 - Snowflake Integration Connect to Snowflake data warehouse and perform analytics at scale. Learn best practices for cloud data integration.
09 - End-to-End Pipeline Build a complete analytics pipeline from data loading through model evaluation to automated reporting.
Recommended order for beginners:
- Start with tutorials 01-03 to understand core concepts
- Move to tutorials 04-06 for practical integration skills
- Complete tutorials 07-09 for production-ready workflows
For experienced users:
- Jump directly to intermediate or advanced tutorials
- Use beginner tutorials as reference material
This project uses pytest for testing:
# Run all tests
pytest
# Run with coverage
pytest --cov=. --cov-report=term-missing
# Run tests in parallel (faster)
pytest -n autoWe use Ruff and Black for code quality:
# Lint with Ruff
ruff check .
# Format with Ruff
ruff format .
# Format with Black
black .Install pre-commit hooks to automatically check code quality:
uv pip install -e ".[dev]"
pre-commit installAll pull requests are automatically tested with GitHub Actions:
- β Linting (Ruff)
- β Formatting (Black + Ruff)
- β Tests (Python 3.8-3.12, Ubuntu/Windows/macOS)
- β Tutorial validation
We welcome contributions! If you have ideas for new tutorials or improvements:
- Fork the repository
- Create a feature branch
- Follow the guidelines in CONTRIBUTING.md
- Submit a pull request
See CONTRIBUTING.md for detailed development setup and guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- Built using the
analytics_storepackage by Wicks Analytics LTD - Powered by Polars for high-performance data processing
For questions or issues:
- Open an issue on GitHub
- Check the analytics_store documentation
- Review the solutions folder for detailed explanations
Happy Learning! π