### Install Prophetverse using pip or poetry Source: https://github.com/felipeangelimvieira/prophetverse/blob/main/README.md Instructions for installing the Prophetverse library using either pip or poetry package managers. This is the first step before using the library's functionalities. ```bash pip install prophetverse ``` ```bash poetry add prophetverse ``` -------------------------------- ### Hierarchical Multivariate Forecasting with HierarchicalProphet Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Shows how to configure a HierarchicalProphet model to forecast multiple time series simultaneously. It includes shared feature configuration and MCMC inference engine setup. ```python import pandas as pd import numpy as np from prophetverse.sktime import HierarchicalProphet from prophetverse.effects import LinearEffect from prophetverse.engine import MCMCInferenceEngine from prophetverse.utils.regex import starts_with, no_input_columns dates = pd.period_range("2020-01-01", periods=100, freq="D") products = ["product_a", "product_b", "product_c"] y_list = [] X_list = [] for product in products: y_data = pd.DataFrame( index=dates, data={"revenue": np.random.rand(100) * 100} ) X_data = pd.DataFrame( index=dates, data={ "ad_spend": np.random.rand(100) * 50, "price": np.random.rand(100) * 10 } ) y_list.append(y_data) X_list.append(X_data) y = pd.concat(y_list, keys=products, names=["product", None]) X = pd.concat(X_list, keys=products, names=["product", None]) model = HierarchicalProphet( trend="linear", exogenous_effects=[ ("ad_spend", LinearEffect(), starts_with("ad")), ], shared_features=["ad_spend"], noise_scale=0.05, correlation_matrix_concentration=1.0, inference_engine=MCMCInferenceEngine( num_samples=500, num_warmup=200, num_chains=2 ) ) model.fit(y=y, X=X) ``` -------------------------------- ### Optimize Marketing Budget Allocation with Prophetverse Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Demonstrates how to use the BudgetOptimizer to maximize KPIs under specific budget and target constraints. It requires a fitted model and defined bounds for spend variables. ```python optimizer = BudgetOptimizer( objective=MaximizeKPI(), constraints=[ TotalBudgetConstraint(total=10000), MinimumTargetResponse(target_response=5000), ], method="SLSQP", bounds={"tv_spend": (0, 5000), "digital_spend": (0, 8000)}, options={"maxiter": 1000} ) horizon = pd.period_range("2021-01-01", periods=30, freq="D") columns = ["tv_spend", "digital_spend"] X_optimized = optimizer.optimize( model=model, X=X_future, horizon=horizon, columns=columns ) ``` -------------------------------- ### Univariate Forecasting with Prophetverse Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Demonstrates how to initialize and fit a univariate Prophetverse model using custom trend, seasonality, and exogenous effects. It shows how to generate point forecasts, quantiles, and component breakdowns. ```python import pandas as pd from prophetverse.sktime import Prophetverse from prophetverse.effects import LinearEffect, LinearFourierSeasonality from prophetverse.effects.trend import PiecewiseLinearTrend from prophetverse.engine import MAPInferenceEngine, MCMCInferenceEngine from prophetverse.utils.regex import starts_with, no_input_columns y = pd.DataFrame( index=pd.period_range("2020-01-01", periods=365, freq="D"), data={"revenue": [100 + i * 0.5 + 10 * (i % 7) for i in range(365)]} ) X = pd.DataFrame( index=y.index, data={ "ad_spend_tv": [50 + i % 30 for i in range(365)], "ad_spend_digital": [30 + i % 20 for i in range(365)], "price": [10 + i % 5 for i in range(365)] } ) trend = PiecewiseLinearTrend( changepoint_interval=30, changepoint_prior_scale=0.001, changepoint_range=0.8 ) seasonality = LinearFourierSeasonality( sp_list=[7, 365.25], fourier_terms_list=[3, 10], prior_scale=0.1, freq="D", effect_mode="multiplicative" ) ad_effect = LinearEffect(effect_mode="additive") model = Prophetverse( trend=trend, exogenous_effects=[ ("seasonality", seasonality, no_input_columns), ("ad_spend", ad_effect, starts_with("ad")), ], likelihood="normal", inference_engine=MAPInferenceEngine() ) model.fit(y=y, X=X) forecast_horizon = pd.period_range("2021-01-01", periods=30, freq="D") X_future = pd.DataFrame( index=forecast_horizon, data={ "ad_spend_tv": [60] * 30, "ad_spend_digital": [40] * 30, "price": [12] * 30 } ) predictions = model.predict(fh=forecast_horizon, X=X_future) quantiles = model.predict_quantiles(fh=forecast_horizon, X=X_future, alpha=[0.1, 0.9]) components = model.predict_components(fh=forecast_horizon, X=X_future) ``` -------------------------------- ### Load Built-in Datasets for Prophetverse Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Illustrates how to load standard time series datasets and synthetic Marketing Mix Modeling data provided by the library for testing and tutorials. ```python from prophetverse.datasets import load_peyton_manning, load_pedestrian_count, load_tourism from prophetverse.datasets._mmm.dataset1 import get_dataset y = load_peyton_manning() y, X, true_params, posterior_samples = get_dataset() ``` -------------------------------- ### Optimize Marketing Budgets Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Initializes the BudgetOptimizer to allocate marketing spend across channels based on model predictions and constraints. ```python from prophetverse.budget_optimization import BudgetOptimizer optimizer = BudgetOptimizer(model=model) # Further configuration of objectives and constraints follows ``` -------------------------------- ### Configure Likelihood Models in Prophetverse Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Shows how to define different observation models (Normal, Gamma, Negative Binomial, Beta) for various data types. Users can configure likelihoods via string parameters, specialized classes, or custom objects. ```python from prophetverse.sktime import Prophetverse, ProphetGamma, ProphetNegBinomial from prophetverse.effects import NormalTargetLikelihood, GammaTargetLikelihood, NegativeBinomialTargetLikelihood, BetaTargetLikelihood model_normal = Prophetverse(likelihood="normal") model_gamma = Prophetverse(likelihood="gamma") model_negbin = Prophetverse(likelihood="negbinomial") model_beta = Prophetverse(likelihood="beta") model_gamma = ProphetGamma(trend="linear") model_negbin = ProphetNegBinomial(trend="logistic") custom_gamma = GammaTargetLikelihood(noise_scale=0.1, epsilon=1e-5) model = Prophetverse(likelihood=custom_gamma) ``` -------------------------------- ### Forecasting with Prophetverse sktime interface Source: https://github.com/felipeangelimvieira/prophetverse/blob/main/README.md Demonstrates how to use the Prophetverse model with its sktime-compatible interface for time series forecasting. It includes model initialization, fitting with historical data (y and X), and making in-sample predictions. ```python from prophetverse.sktime import Prophetverse # Create the model model = Prophetverse() # Fit the model model.fit(y=y, X=X) # Forecast in sample y_pred = model.predict(X=X, fh=[1,2,3,4]) ``` -------------------------------- ### Configure MCMC and MAP Inference Engines Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Sets up Bayesian inference using MCMC for uncertainty quantification or MAP for faster point estimation. ```python from prophetverse.engine import MCMCInferenceEngine, MAPInferenceEngine from prophetverse.engine.optimizer import LBFGSSolver, AdamOptimizer # MCMC mcmc_engine = MCMCInferenceEngine(num_samples=1000, num_warmup=500, num_chains=4) # MAP map_engine = MAPInferenceEngine(optimizer=LBFGSSolver(), num_steps=10000, num_samples=1000) ``` -------------------------------- ### Predicting with Prophetverse Models Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Demonstrates how to generate predictions for multiple series using a defined model and a period range. ```python fh = pd.period_range("2020-04-11", periods=30, freq="D") predictions = model.predict(fh=fh, X=X) ``` -------------------------------- ### Configure Seasonality and Exogenous Effects Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Defines weekly and yearly seasonality using Fourier terms and integrates them into the Prophetverse model as exogenous effects. ```python seasonality = LinearFourierSeasonality( sp_list=[7, 365.25], fourier_terms_list=[3, 10], freq="D", prior_scale=0.1, effect_mode="multiplicative", start_period="2020-01-01", end_period="2022-12-31" ) model = Prophetverse( exogenous_effects=[ ("seasonality", seasonality, no_input_columns), ] ) ``` -------------------------------- ### Calibrate Effects with Lift Experiments Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Wraps an effect with LiftExperimentLikelihood to calibrate model coefficients using external experimental lift test data. ```python from prophetverse.effects import LiftExperimentLikelihood, LinearEffect calibrated_effect = LiftExperimentLikelihood( effect=LinearEffect(), lift_test_results=lift_results, prior_scale=0.1, likelihood_scale=1.0 ) ``` -------------------------------- ### Modeling Saturation with HillEffect Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Implements a sigmoid-like saturation curve using HillEffect to model diminishing returns in marketing data. ```python from prophetverse.effects import HillEffect from numpyro import distributions as dist hill_effect = HillEffect( effect_mode="multiplicative", half_max_prior=dist.Gamma(2, 1), slope_prior=dist.HalfNormal(5), max_effect_prior=dist.Gamma(2, 1), input_scale=1000.0 ) model = Prophetverse( exogenous_effects=[ ("tv_ads", hill_effect, "tv_spend"), ("digital_ads", HillEffect(), "digital_spend"), ] ) ``` -------------------------------- ### Modeling Saturation with MichaelisMentenEffect Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Uses the Michaelis-Menten equation to model saturation effects, providing an alternative to Hill curves for marketing spend. ```python from prophetverse.effects import MichaelisMentenEffect from numpyro import distributions as dist mm_effect = MichaelisMentenEffect( effect_mode="multiplicative", max_effect_prior=dist.Gamma(2, 1), half_saturation_prior=dist.Gamma(1, 1) ) model = Prophetverse( exogenous_effects=[ ("marketing", mm_effect, "marketing_spend"), ] ) ``` -------------------------------- ### Implement Piecewise Linear and Logistic Trends Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Configures trend components for modeling linear segments with changepoints or logistic growth with inferred capacity. ```python from prophetverse.effects.trend import PiecewiseLinearTrend, PiecewiseLogisticTrend from numpyro import distributions as dist # Piecewise Linear trend = PiecewiseLinearTrend( changepoint_interval=25, changepoint_range=0.8, changepoint_prior_scale=0.001, offset_prior_scale=0.1 ) # Piecewise Logistic logistic_trend = PiecewiseLogisticTrend( changepoint_interval=30, changepoint_range=0.8, changepoint_prior_scale=0.001, capacity_prior=dist.TransformedDistribution( dist.HalfNormal(0.2), dist.transforms.AffineTransform(loc=1.1, scale=1) ) ) ``` -------------------------------- ### Modeling Flexible Carryover with WeibullAdstockEffect Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Provides flexible decay patterns for carryover effects using the Weibull probability density function. ```python from prophetverse.effects import WeibullAdstockEffect from prophetverse.distributions import GammaReparametrized weibull_adstock = WeibullAdstockEffect( scale_prior=GammaReparametrized(2, 1), concentration_prior=GammaReparametrized(2, 1), max_lag=14, initial_history=0.0 ) model = Prophetverse( exogenous_effects=[ ("radio_carryover", weibull_adstock, "radio_spend"), ] ) ``` -------------------------------- ### Composing Effects with ChainedEffects Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Allows sequential application of multiple effects, such as combining adstock transformations with saturation curves. ```python from prophetverse.effects import ChainedEffects, GeometricAdstockEffect, HillEffect marketing_effect = ChainedEffects( steps=[ ("adstock", GeometricAdstockEffect(normalize=True)), ("saturation", HillEffect(effect_mode="additive")), ] ) model = Prophetverse( exogenous_effects=[ ("tv", marketing_effect, "tv_spend"), ("digital", ChainedEffects(steps=[ ("adstock", GeometricAdstockEffect()), ("hill", HillEffect()), ]), "digital_spend"), ] ) ``` -------------------------------- ### Modeling Carryover with GeometricAdstockEffect Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Captures lagged marketing effects where the impact of past spending decays geometrically over time. ```python from prophetverse.effects import GeometricAdstockEffect from numpyro import distributions as dist adstock_effect = GeometricAdstockEffect( decay_prior=dist.Beta(2, 2), normalize=True ) model = Prophetverse( exogenous_effects=[ ("tv_carryover", adstock_effect, "tv_spend"), ] ) ``` -------------------------------- ### Modeling Linear Exogenous Effects Source: https://context7.com/felipeangelimvieira/prophetverse/llms.txt Uses the LinearEffect class to model linear relationships between exogenous variables and the target. Supports additive or multiplicative modes and custom priors. ```python from prophetverse.effects import LinearEffect from numpyro import distributions as dist linear_effect = LinearEffect( effect_mode="additive", prior=dist.Normal(0, 0.1) ) model = Prophetverse( exogenous_effects=[ ("price", linear_effect, "price"), ("controls", LinearEffect(), "control_.*"), ] ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.