Unable to use the budget allocation function for DelayedSaturatedMMM model

Hi there, I just built an mmm model using DelayedSaturatedMMM… I’m trying to create budget allocation scenario based on this example ()… However, when i called out the code block below, it gave me an error that says ‘DelayedSaturatedMMM’ object has no attribute ‘allocate_budget_to_maximize_response’

Here’s my code:

## Load pre trained model
mmm = DelayedSaturatedMMM.load("direct_mmm_with_lift_test_v2.nc")

total_budget = 1  
channels = spend_cols
budget_per_channel = total_budget / len(channels)
initial_budget_dict = {channel: budget_per_channel for channel in channels}
min_budget, max_budget = 0.05, .4
budget_bounds = {channel: [min_budget, max_budget] for channel in channels}


menten_params = mmm.compute_channel_curve_optimization_parameters_original_scale(
    method="michaelis-menten"
)


#### the code block below raised an error ####
response = mmm.allocate_budget_to_maximize_response(
    budget=total_budget,
    num_days=8,
    time_granularity="weekly",
    budget_bounds=budget_bounds
)

Hello,

Can you show which PyMC-Marketing version are you using?

Hi Carlos, I’m using the 0.6.0 version…
Screenshot 2024-06-19 at 12.26.03 PM

Hello,
Did this error get resolved? I am also facing the same error and am new to pymc so would like some direction.

What version of pymc-marketing are you using? If you are not using the most recent version, I would suggest trying to install that first.

If I’m correct this is a general Python issue having to do with the current working directory. If the current working directory has a pymc_marketing subdirectory (like a clone of the Git repo), then it will clobber the pymc_marketing package which is under pymc_marketing/pymc_marketing.

So make sure that you’re not in the parent directory of a pymc_marketing clone, and make sure you don’t have any other directories called pymc_marketing that aren’t the actual pymc_marketing package.

I have a proposed fix in Add an __init__.py in repo root to prevent import confusion by maresb · Pull Request #949 · pymc-devs/pytensor · GitHub and a more detailed explanation in the linked issue.

Sorry, I didn’t read this carefully enough. What I wrote was inapplicable.

1 Like

Hi Thank you for responding! I am using 0.7.0

Can you run the following and show what the output is?

from pymc_marketing.mmm.delayed_saturated_mmm import MMM
[m for m in dir(MMM) if callable(getattr(MMM, m))]

Hello! for me the problem is resolved when i update to pymc-marketing version 0.7.0… i also made sure that i’m using python 3.11… hope that helps :slight_smile:

Thanks @JenniferSiwu :slightly_smiling_face:
That helped but however now it’s throwing weird budgets which do not add up to the total budget - similar to what you were facing.

Also a qq - for your test data, what metrics are you using for evaluation?

Hi @cluhmann
Thanks for helping me out!
I see the following:
[‘class’,
delattr’,
dir’,
eq’,
format’,
ge’,
getattribute’,
gt’,
hash’,
init’,
init_subclass’,
le’,
lt’,
ne’,
new’,
reduce’,
reduce_ex’,
repr’,
setattr’,
sizeof’,
str’,
subclasshook’,
‘_channel_map_scales’,
‘_create_synth_dataset’,
‘_data_setter’,
‘_format_model_contributions’,
‘_generate_and_preprocess_model_data’,
‘_get_channel_contributions_share_samples’,
‘_get_fourier_models_data’,
‘_model_config_formatting’,
‘_plot_response_curve_fit’,
‘_process_decomposition_components’,
‘_save_input_params’,
‘_validate_data’,
‘add_lift_test_measurements’,
‘allocate_budget_to_maximize_response’,
‘build_model’,
‘channel_contributions_forward_pass’,
‘compute_channel_contribution_original_scale’,
‘compute_mean_contributions_over_time’,
‘fit’,
‘format_recovered_transformation_parameters’,
‘forward_pass’,
‘get_channel_contributions_forward_pass_grid’,
‘get_errors’,
‘get_params’,
‘get_target_transformer’,
‘graphviz’,
‘load’,
‘max_abs_scale_channel_data’,
‘max_abs_scale_target_data’,
‘new_spend_contributions’,
‘plot_allocated_contribution_by_channel’,
‘plot_budget_allocation’,
‘plot_channel_contribution_share_hdi’,
‘plot_channel_contributions_grid’,
‘plot_channel_parameter’,
‘plot_components_contributions’,
‘plot_direct_contribution_curves’,
‘plot_errors’,
‘plot_grouped_contribution_breakdown_over_time’,
‘plot_new_spend_contributions’,
‘plot_posterior_predictive’,
‘plot_prior_predictive’,
‘plot_waterfall_components_decomposition’,
‘predict’,
‘predict_posterior’,
‘predict_proba’,
‘preprocess’,
‘sample_posterior_predictive’,
‘sample_prior_predictive’,
‘save’,
‘set_idata_attrs’,
‘set_params’,
‘validate’,
‘validate_channel_columns’,
‘validate_control_columns’,
‘validate_date_col’,
‘validate_target’]

The method is right there, so I’m not sure why you are getting the error saying it’s not. Are you sure you spelled the function name correctly, etc.?

yes I am. On reinstalling the package it worked. Thank youuuu! Appreciate it! @cluhmann

However the budget that it’s showing is greater than by total budget for example when I used 5 for 500K my total is coming to be 6.83.

I am unsure of why this is happening - can you help me with that?

1 Like

My suggestion is to open a new issue about that.

Okayy thank you! I have opened a new issue about it. @cluhmann