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.3.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.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: murphet-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 71cee13b968441a730e865c53ae062c68786a3f074189926426192836430f303
MD5 4efb3372a9209b17a57688bbb5df6008
BLAKE2b-256 b26d007b46e8a7b5b16c5c5ab77655d0e0f10887394077528db0aa259ff98c8b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: murphet-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b88c8a60c1639fd3c8a5fb81f59673846e707dd24003d0791c2d1f1bd8bd2094
MD5 484ac888b31d019b10fe7ef931041625
BLAKE2b-256 daf7a9e29f9208396c4393e5dc3710d655523c159c5214a92eba0b07a962181c

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