Skip to main content

A Bayesian time-series model for churn rates with changepoints and seasonality

Project description

Murphet

A Bayesian time-series model for churn rates and percentages with changepoints and seasonality. Inspired by Prophet but specifically designed for values between 0 and 1 (such as churn rates, conversion rates, or percentages).

Installation

pip install murphet

Requirements

  • Python 3.7 or higher
  • CmdStanPy 0.10.0 or higher
  • NumPy 1.19 or higher
  • Pandas 1.0.0 or higher

Features

  • Bayesian modeling of time series that represent rates or percentages (0-1 values)
  • Flexible trend with automatic changepoint detection
  • Seasonality modeling via Fourier series
  • Smooth changepoint transitions
  • Uncertainty intervals for forecasts
  • Compatible with monthly, weekly, or any regular time interval

Quick Start

import pandas as pd
import numpy as np
from murphet.churn_model import fit_churn_model

# Load time series data (with columns 'ds' for dates and 'y' for churn rates)
df = pd.read_csv('churn_data.csv')
df['ds'] = pd.to_datetime(df['ds'])

# Create a numeric time index
df['t'] = np.arange(len(df))

# For monthly data with yearly seasonality
model = fit_churn_model(
    t=df['t'].values,
    y=df['y'].values,
    num_harmonics=2,       # Use 2 Fourier terms for seasonality
    period=12.0,           # 12 months per year
    n_changepoints=3,      # Allow 3 potential changes in trend
)

# Forecast 6 months ahead
future_t = np.arange(len(df), len(df) + 6)
predictions = model.predict(future_t)

# Display summary of fitted parameters
print(model.summary())

Detailed Documentation

The model combines:

  1. Trend Component: Flexible trend with automatic changepoint detection

    • Linear + optional quadratic terms
    • Smooth transitions at changepoints
  2. Seasonal Component: Fourier series to model recurring patterns

    • Configurable harmonics and period
    • Handles any regular seasonality (yearly, weekly, etc.)
  3. Statistical Model:

    • Uses a Beta likelihood appropriate for rate/percentage data
    • Provides uncertainty intervals from the posterior distribution

License

MIT

Citation

If you use this package in your research, please cite:

Murphy, S. (2025). Murphet: A Bayesian Time-Series Model for Churn Rates with Changepoints and Seasonality. 
https://github.com/halsted312/murphet

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

murphet-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

murphet-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file murphet-0.1.0.tar.gz.

File metadata

  • Download URL: murphet-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for murphet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 56aef543a6e9c35b48d78e7c36910c6beb62a957cc7d9d3be8247d30ee329406
MD5 95d21b25f5f9b7f75f89f736be563855
BLAKE2b-256 782497212246967dc34c5712d456fd91a6151ba8f869fc6230d64ce16b449ffb

See more details on using hashes here.

File details

Details for the file murphet-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: murphet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for murphet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6ecd8261483b5ebe2acae7007e7e8098215dabb7f27e40a47c1b1e6255f12b5
MD5 a9437ae4aad9aaeedd83aea79003639d
BLAKE2b-256 cc895a9215f5d4b3c7835a6968e56b076ff75aeef2f4720ba4098b593aa3f962

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page