# Unable to use the budget allocation function for DelayedSaturatedMMM model

**URL:** <https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628>\
**Category:** v5\
**Tags:** bug, modeling\
**Created:** [June 17, 2024, 11:20pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628 "2024-06-17T23:20:22Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![JenniferSiwu](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@JenniferSiwu](https://discourse.pymc.io/u/JenniferSiwu)\
**Post date:** [June 17, 2024, 11:20pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/1 "2024-06-17T23:20:23Z")

</div>

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:

```auto
## 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
)

```

 ![Screenshot 2024-06-17 at 4.11.17 PM](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/0/0b1590c872b96ba39eae7a6a561525f4a8b1139e.png)

---

<div class="post-metadata">

**Author:** ![cetagostini](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cetagostini/32/6967_2.png) [@cetagostini](https://discourse.pymc.io/u/cetagostini)\
**Post date:** [June 18, 2024, 12:34pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/2 "2024-06-18T12:34:46Z")

</div>

Hello,

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

---

<div class="post-metadata">

**Author:** ![JenniferSiwu](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@JenniferSiwu](https://discourse.pymc.io/u/JenniferSiwu)\
**Post date:** [June 19, 2024, 7:26pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/3 "2024-06-19T19:26:16Z")

</div>

Hi Carlos, I’m using the 0.6.0 version…  
 ![Screenshot 2024-06-19 at 12.26.03 PM](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/c/cdbabf1a0b8a5b7ee363be765148ac4b2851d5d3.png)

---

<div class="post-metadata">

**Author:** ![YT19](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/yt19/32/8349_2.png) [@YT19](https://discourse.pymc.io/u/YT19)\
**Post date:** [July 19, 2024, 5:09pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/4 "2024-07-19T17:09:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [July 20, 2024, 2:10am UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/5 "2024-07-20T02:10:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![maresb](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@maresb](https://discourse.pymc.io/u/maresb)\
**Post date:** [July 20, 2024, 1:33pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/6 "2024-07-20T13:33:19Z")

</div>

~~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.~~

---

<div class="post-metadata">

**Author:** ![maresb](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@maresb](https://discourse.pymc.io/u/maresb)\
**Post date:** [July 20, 2024, 1:33pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/7 "2024-07-20T13:33:51Z")

</div>

~~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](https://github.com/pymc-devs/pytensor/pull/949) and a more detailed explanation in the linked issue.~~

---

<div class="post-metadata">

**Author:** ![maresb](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@maresb](https://discourse.pymc.io/u/maresb)\
**Post date:** [July 20, 2024, 1:55pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/8 "2024-07-20T13:55:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![YT19](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/yt19/32/8349_2.png) [@YT19](https://discourse.pymc.io/u/YT19)\
**Post date:** [July 22, 2024, 7:33pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/9 "2024-07-22T19:33:12Z")

</div>

Hi Thank you for responding! I am using 0.7.0

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [July 22, 2024, 7:47pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/10 "2024-07-22T19:47:39Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![JenniferSiwu](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@JenniferSiwu](https://discourse.pymc.io/u/JenniferSiwu)\
**Post date:** [July 22, 2024, 11:29pm UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/11 "2024-07-22T23:29:50Z")

</div>

> [@JenniferSiwu](#):
>
> `allocate_budget_to_maximize_response`

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 🙂

---

<div class="post-metadata">

**Author:** ![YT19](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/yt19/32/8349_2.png) [@YT19](https://discourse.pymc.io/u/YT19)\
**Post date:** [July 24, 2024, 1:08am UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/12 "2024-07-24T01:08:26Z")

</div>

Thanks @JenniferSiwu 🙂  
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?

---

<div class="post-metadata">

**Author:** ![YT19](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/yt19/32/8349_2.png) [@YT19](https://discourse.pymc.io/u/YT19)\
**Post date:** [July 24, 2024, 1:09am UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/13 "2024-07-24T01:09:30Z")

</div>

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’]

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [July 24, 2024, 1:25am UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/14 "2024-07-24T01:25:03Z")

</div>

> [@YT19](#):
>
> allocate\_budget\_to\_maximize\_response

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.?

---

<div class="post-metadata">

**Author:** ![YT19](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/yt19/32/8349_2.png) [@YT19](https://discourse.pymc.io/u/YT19)\
**Post date:** [July 24, 2024, 1:36am UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/15 "2024-07-24T01:36:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [July 24, 2024, 2:06am UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/16 "2024-07-24T02:06:26Z")

</div>

My suggestion is to open a new issue about that.

---

<div class="post-metadata">

**Author:** ![YT19](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/yt19/32/8349_2.png) [@YT19](https://discourse.pymc.io/u/YT19)\
**Post date:** [July 24, 2024, 2:23am UTC](https://discourse.pymc.io/t/unable-to-use-the-budget-allocation-function-for-delayedsaturatedmmm-model/14628/17 "2024-07-24T02:23:54Z")

</div>

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