pymc-labs / pymc-marketing

Bayesian marketing toolbox in PyMC. Media Mix (MMM), customer lifetime value (CLV), buy-till-you-die (BTYD) models and more.
https://www.pymc-marketing.io/
Apache License 2.0
694 stars 193 forks source link

closer access to Michaelis-Menten curve fit #446

Open wd60622 opened 11 months ago

wd60622 commented 11 months ago

Fitting the Michaelis-Menten curve (and sigmoid) require the arguments in DataFrame and xarray object. This is great for the use case but makes it hard to interact with for other purposes

https://github.com/pymc-labs/pymc-marketing/blob/30c91ee3568e853a18d7684182b54fa0d2c47b7f/pymc_marketing/mmm/utils.py#L98-L103

I would suggest a function to fit the curve with more direct arguments and then a function to fit based on the channel

def estimate_menten_parameters(x, y, alpha_initial_estimate=None, lam_initial_estimate=0.001, maxfev=5000): 
    # The actual curve fitting
    alpha_initial_estimate = alpha_initial_estimate or max(y)
    ...

def estimate_channel_menten_parameters(channel, original_dataframe, contribution, **kwargs): 
    # Function to be used for specific use-case
    return estimate_menten_parameters(
        x=original_dataframe[channel].to_numpy(), 
        y=contributions.sel(channel=channel).to_numpy()
        **kwargs
    )
wd60622 commented 9 months ago

@nialloulton do you have this already? I saw your LinkedIn post for this type of API