Code Monkey home page Code Monkey logo

pysimmmulator's Introduction

logo

PySiMMMulator

CodeFactor PyPI Downloads

PySiMMMulator is an open source Python adaption of the R-package siMMMulator, which allows users to generate simulated data to use in testing Marketing Mix Models (MMMs). While this package cointains a full pipeline for data generation (configurable via .conf file) it can also be utilized in parts to generate select portions of MMM input data (ie campaign/channel spend)

Installation

Accessable via PyPI

pip install pysimmmulator

Usage

PySiMMMulator's simulator can either be run on a step-by-step basis, or can be run single-shot by passing a config file.

Run via config

Run using this method, you'll be returned both a dataframe of for MMM input as well as the "True ROI" values for each of your channels. These true values are critical to validating your MMM model.

cfg = load_config(config_path="./my_config.yaml")
sim = simmm()
mmm_input_df, channel_roi = sim.run_with_config(config=cfg)

Run by stages

Alternatively you may run each of the stages independently, which allows for easier debugging and in-run adjustments based on the results of each stage. The order of the stages is reflected below (without their inputs). Once you've run through every stage, results are available by calling the sim.final_df object (channel ROI results are stored as sim.channel_roi).

sim = simmm()
sim.simulate_baseline()
sim.simulate_ad_spend()
sim.simulate_media()
sim.simulate_cvr()
sim.simulate_decay_returns()
sim.calculate_conversions()
sim.consolidate_dataframe()
sim.calculate_channel_roi()
sim.finalize_output()

Run via CLI

A configuration file is required as input for this and should be passed as seen below. An output path can also be passed via -o, however when not passed the current working directory will be used.

pysimmm -i example_config.yaml -o .

Development

Setting up a dev environment

conda create --prefix=./env python=3.11
conda activate ./env
pip install -e '.[dev]'

pysimmmulator's People

Contributors

ryanaugust avatar

Stargazers

Matthew Triggs avatar Kacper Solarski avatar Ryan avatar  avatar

Watchers

 avatar Ryan avatar

pysimmmulator's Issues

Cannot import the package

Describe the bug
After running pip3 install pysimmmulator, I tried to import the package and got the error.

To Reproduce
Steps to reproduce the behavior:

  1. pip3 install pysimmmulator
  2. Open Python and run import pysimmmulator

Expected behavior
Should run without problems.

Screenshots
Screenshot 2024-02-20 at 17 10 30

Desktop (please complete the following information):

  • OS: MacOS
  • Version 0.2.3

Additional context

frequency_of_campaigns > 1 causes missing values in calculation tables

Describe the bug
When frequency of campaigns is > 1, missing values are introduced in the mmm_df table. I assume (haven't checked) that this is because values are joined on an index of sorts.

For example, for three years of data (1095 entries), values are only populated for 546 of them when the campaign length is 2. Similar behavior can be observed for other campaign frequencies - rows are only populated for n/x rows where n is the total duration and x is the campaign duration.

To Reproduce

  1. Set campaign duration to > 1

Expected behavior
Rows are aggregated to either campaign date period, or values are spread out across dates.

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: N/A
  • Version: N/A

Additional context
Add any other context about the problem here.

Introduce Seed to Make Simulation Reproducible

Is your feature request related to a problem? Please describe.
Currently I see not way to make my simulation reproducible (please correct me if I'm wrong). If somebody discovers some issue with the package, it's easier to debug if one is able to fully reproduce the simulation.

Describe the solution you'd like
Add an optional seed using np.random.seed() function.

Getting Negative Impressions in Example

Describe the bug
When running the example config, I noticed that some metrics like impressions or clicks can become negative. I believe those column should have a lower bound of 0 to match the reality. I am also not sure whether revenue column should be allowed to be negative.

To Reproduce
Steps to reproduce the behaviour:

  1. Run things with example config and check minimum value at each column.

Expected behaviour
I do not expect to get any negative values for impressions and clicks.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS
  • Version 0.2.4
  • Pandas Version 2.0.2

Cannot Run Example With Aggregation Level Changed to Weekly

Describe the bug
When trying out the example config and changing aggregation level to weekly, I'm getting an error.

To Reproduce
Steps to reproduce the behavior:

  1. Change aggregation level to weekly in an example. And run:
cfg = load_config(config_path="example_config.yaml")
mmm_input_df, channel_roi = sim.run_with_config(config=cfg)

Expected behavior
Should work fine with both daily and weekly choices.

Screenshots
Screenshot 2024-02-20 at 18 37 24

Desktop (please complete the following information):

  • OS: MacOS
  • Version: 0.2.4
  • Pandas version: 2.0.2

Additional context
Can also dive into the issue myself and contribute.

Enable CLI usage

Add ability to run config based simulation directly from the command line

Necessary args:

  • path of config file
  • output path for simulation data (mmm_input & true channel ROI)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.