Documentation
Quickstart
Install Murphet and CmdStan, prepare a monthly rate series, and fit your first Bayesian forecast in Python.
Set up Python and Stan
Use a Python 3.11 or 3.12 environment with a C++ toolchain and GNU Make. The example uses the package and CmdStanPy versions from the original forecasting site. Install CmdStan once if you do not already have it.
python -m pip install "murphet==1.6.6" "cmdstanpy==1.2.5"
python -c "import cmdstanpy; cmdstanpy.install_cmdstan(version='2.35.0')"Murphet ships Stan source files. The first fit compiles the model locally. CmdStan installation guide ↗
Prepare a time series
Use the example CSV, or supply your own monthly file with ds dates and y proportions. Express 74% as 0.74. The Beta model requires every observation to be strictly between 0 and 1.
Fit and predict
import numpy as np
import pandas as pd
from murphet import fit_churn_model
df = pd.read_csv("hotel-occupancy.csv", parse_dates=["ds"])
df = df.sort_values("ds")
t = np.arange(len(df))
model = fit_churn_model(
t=t, y=df["y"], likelihood="beta",
periods=12, num_harmonics=3, inference="map", seed=42,
)
print(model.predict(np.arange(len(t), len(t) + 6)))The numbered time steps assume equally spaced months. A period of 12 represents one year. To run a complete example with data checks and dated output, open the forecast workflow.