Skip to content

Repository files navigation

Analytics Store Tutorials - Insurance Data Analysis

CI Python 3.8+ Code style: black Ruff License: MIT

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.

πŸ“š Tutorial Overview

This repository contains hands-on exercises organized by difficulty level and topic:

Getting Started (Start Here!)

  1. Project Setup and Polars Basics - Environment setup and data manipulation fundamentals

Beginner Tutorials

  1. Introduction to Lift Analysis - Understanding lift curves with insurance claim predictions
  2. ROC Curve Analysis - Evaluating binary classification models for fraud detection
  3. Regression Metrics - Analyzing premium prediction models

Intermediate Tutorials

  1. Model Comparison - Comparing multiple models using double lift analysis
  2. Data Loading from SQL - Connecting to databases and loading insurance data
  3. Population Testing - Statistical tests for comparing customer segments

Advanced Tutorials

  1. Model Monitoring & Drift Detection - Tracking model performance over time
  2. Snowflake Integration - Working with cloud data warehouses
  3. End-to-End Pipeline - Complete workflow from data loading to reporting

🎯 Learning Objectives

By completing these tutorials, you will learn to:

  • Use analytics_store for 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

πŸ“‹ Prerequisites

  • Python 3.8 or higher
  • Basic understanding of Python and pandas/polars
  • Familiarity with machine learning concepts (helpful but not required)

πŸš€ Getting Started

Installation

  1. Clone this repository:
git clone https://github.com/Wicks-Analytics/analytics_tutorials.git
cd analytics_tutorials
  1. Choose your environment manager:

Option A: Using uv (Recommended - Fast & Modern)

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

Option B: Using pip (Traditional)

# 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_store

Running Tutorials

Option 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.py

Option 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.ipynb

Converting Scripts to Notebooks

Generate notebook versions from Python scripts:

python convert_to_notebooks.py

πŸ“ Repository Structure

analytics_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)

πŸ“Š Sample Datasets

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.

πŸ”Œ Database Integration

SQLite (Local)

Run the setup script to create a local SQLite database:

python setup_database.py

PostgreSQL/MySQL

Update the connection strings in utils/database_helpers.py with your credentials.

Snowflake

For Snowflake tutorials, you'll need:

  • Snowflake account credentials
  • Appropriate permissions to read data
  • Update config/snowflake_config.py with your connection details

πŸ“ Tutorial Descriptions

Beginner Level

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.

Intermediate Level

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.

Advanced Level

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.

πŸŽ“ Learning Path

Recommended order for beginners:

  1. Start with tutorials 01-03 to understand core concepts
  2. Move to tutorials 04-06 for practical integration skills
  3. Complete tutorials 07-09 for production-ready workflows

For experienced users:

  • Jump directly to intermediate or advanced tutorials
  • Use beginner tutorials as reference material

οΏ½ Testing & Development

Running Tests

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 auto

Code Quality

We use Ruff and Black for code quality:

# Lint with Ruff
ruff check .

# Format with Ruff
ruff format .

# Format with Black
black .

Pre-commit Hooks

Install pre-commit hooks to automatically check code quality:

uv pip install -e ".[dev]"
pre-commit install

Continuous Integration

All pull requests are automatically tested with GitHub Actions:

  • βœ… Linting (Ruff)
  • βœ… Formatting (Black + Ruff)
  • βœ… Tests (Python 3.8-3.12, Ubuntu/Windows/macOS)
  • βœ… Tutorial validation

οΏ½οΏ½ Contributing

We welcome contributions! If you have ideas for new tutorials or improvements:

  1. Fork the repository
  2. Create a feature branch
  3. Follow the guidelines in CONTRIBUTING.md
  4. Submit a pull request

See CONTRIBUTING.md for detailed development setup and guidelines.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Built using the analytics_store package by Wicks Analytics LTD
  • Powered by Polars for high-performance data processing

πŸ“§ Support

For questions or issues:

  • Open an issue on GitHub
  • Check the analytics_store documentation
  • Review the solutions folder for detailed explanations

Happy Learning! πŸŽ‰

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages