{"id":13710051,"url":"https://github.com/DP6/Marketing-Attribution-Models","last_synced_at":"2025-05-06T18:33:50.195Z","repository":{"id":37523636,"uuid":"236500868","full_name":"DP6/Marketing-Attribution-Models","owner":"DP6","description":"Python Class created to address problems regarding Digital Marketing Attribution.","archived":false,"fork":false,"pushed_at":"2024-10-03T19:21:12.000Z","size":1764,"stargazers_count":327,"open_issues_count":24,"forks_count":87,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-05-05T02:43:59.474Z","etag":null,"topics":["attribution-model","digital-marketing-attribution","dp6","hacktoberfest","journey","mam","marketing-attribution"],"latest_commit_sha":null,"homepage":"https://dp6.github.io/Marketing-Attribution-Models","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DP6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-27T13:51:00.000Z","updated_at":"2025-03-29T15:29:21.000Z","dependencies_parsed_at":"2025-01-15T19:14:05.325Z","dependency_job_id":"5c803ba3-b6ba-438b-bc5d-4c3ad27cd81f","html_url":"https://github.com/DP6/Marketing-Attribution-Models","commit_stats":{"total_commits":76,"total_committers":15,"mean_commits":5.066666666666666,"dds":0.7631578947368421,"last_synced_commit":"72933d9835b334208c561fdfcb370ae1a1b406b4"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DP6%2FMarketing-Attribution-Models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DP6%2FMarketing-Attribution-Models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DP6%2FMarketing-Attribution-Models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DP6%2FMarketing-Attribution-Models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DP6","download_url":"https://codeload.github.com/DP6/Marketing-Attribution-Models/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252429968,"owners_count":21746571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attribution-model","digital-marketing-attribution","dp6","hacktoberfest","journey","mam","marketing-attribution"],"created_at":"2024-08-02T23:00:51.247Z","updated_at":"2025-05-06T18:33:48.901Z","avatar_url":"https://github.com/DP6.png","language":"Python","funding_links":[],"categories":["Attribution"],"sub_categories":[],"readme":"# Marketing Attribution Models\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/DP6/templates-centro-de-inovacoes/main/public/images/centro_de_inovacao_dp6.png\" height=\"100px\" /\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#badge\"\u003e\n    \u003cimg alt=\"semantic-release\" src=\"https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.codacy.com/gh/DP6/Marketing-Attribution-Models/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=DP6/Marketing-Attribution-Models\u0026amp;utm_campaign=Badge_Grade\"\u003e\n    \u003cimg src=\"https://app.codacy.com/project/badge/Grade/0d6e5f753b2b4289aa27cc572b474773\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n  \n## 1. About the Class  \nPython Class created to address problems regarding Digital Marketing Attribution.  \n  \n## 2. About Multi-Channel Attribution  \nWhile browsing online, an user has multiple touchpoints before converting, which could lead to ever so longer and more complex journeys.  \n  \n*How to duly credit conversions and optmize investment on media?*  \n  \nTo adress this, we apply **Attribution Models**.  \n  \n### 2.1 Attribution Models  \n**Heuristic Models**:  \n  \n- **Last Interaction**:  \n- Default attribution in Gogle Analytics and other media platforms such as Google Ads and Facebook Business manager;  \n- Only the last touchpoint is credited for the conversion.  \n  \n- **Last Click Non-Direct**:  \n- All direct traffic is ignored and so 100% of the result goes to the last channel through which the client got to the website before converting.  \n  \n- **First Interaction**:  \n- The result is wholly attributed to the first touchpoint.  \n  \n- **Linear**:  \n- Every touchpoint is equally credited.  \n  \n- **Time Decay**:  \n- The more recent a touchpoint is, the more credit it gets.  \n- **Position Based**:  \n- In this model, 40% of the result is attributed to the last touchpoint, another 40% to the first and the remaining 20% is equally distributed among the midway channels.  \n  \n**Algotithmic Models**  \n  \n**Shapley Value**  \n  \nUsed in Game Theory, this value is an estimation of the contribution of each individual player in a cooperative game.  \n  \nConversions are credited to the channels by a process of permutating the journeys. In each permutation a channel is given out to estimate how essencial it is overall.  \n  \n**As an example**, let's look at the following hypotherical journey:  \n  \nOrganic Search \u003e Facebook \u003e Direct \u003e **$19** (as revenue)  \n  \nTo obtain each channel's Shapley Value, we first need to consider all conversion values for the component permutations of this given journey.  \n  \n  \n\u003e Organic Search \u003e **$7**  \n  \n\u003e Facebook \u003e **$6**  \n  \n\u003e Direct \u003e **$4**  \n  \n\u003e Organic Search \u003e Facebook \u003e **$15**  \n  \n\u003e Organic Search \u003e Direct \u003e **$7**  \n  \n\u003e Facebook \u003e Direct \u003e **$9**  \n  \n\u003e Organic Search \u003e Facebook \u003e Direct \u003e **$19**  \n  \nThe number of component joneys increases exponentially the more distinct channels you have: The rate is 2^n (2 to the power of n) for **n channels**.  \n  \nIn other words, with 3 distinct touchpoints there are 8 permutations. **With over 15, for instance, this process is unfeasible**.  \n  \nBy default, the order of the touchpoints isn't taken into consideration when calculating the Shapley Value, only their presence or lack there of. In order to do so, the number of permutations **increases**.  \n  \nWith that in mind, note that it is pretty difficult to use this model when considering the order of interactions. For n channels, not only there are 2^n permutations of a given channel **i**, but also **every permutation containing i in a different position**.  \n  \n**Some issues and limitations of Shapley Value**  \n  \n- The number of distinct channels is limited by the exponential nature of the permutations.  \n- When not considering the order of the touchpoints, the contribution estimated for channel A is considered the same being it preceded by B or C.  \n- If the order is taken into account, the number of combinations skyrockets and if any combination does not exist among the observations the model considers that journey as existent with zero conversions.  \n- Touchpoints that are unfrequent or are only present in longer journeys have their contribution underestimated.  \n  \n  \n**Markov Chains**\nA Markov Chain is a particular Stochastic process in which the probability distribution of any next state depends only on what the current state is, disregarding any preceeding states and their sequence.\n\nIn multichannel attriution, we can use the Markov Chains to calculate the probability of interaction between pairs of media channels with the **Transition Matrix**.\n\nIn regard to each channel's contribution in conversions, the **Removal Effect** comes in: For each jorney a given channel is removed and a conversion probability is calculated.\n\nThe value attributed to a channel, then, is obtained by the ratio of the difference between the probability of conversion in general and the probability once said channel is removed over the general probability again. \n\nIn other words, the bigger a channel's removal effect, the larger their contribution is. \n\n**When working with Markovian Processes there are no restrictions due to the quantity or order of channels. Their sequence, itself, is a fundamental part of the algorithm.\n\n### 2.2 References\n- [Attribution Models in Marketing](https://data-science-blog.com/blog/2019/04/18/attribution-models-in-marketing/)\n- [Attribution Theory: The Two Best Models for Algorithmic Marketing Attribution – Implemented in Apache Spark and R](http://datafeedtoolbox.com/attribution-theory-the-two-best-models-for-algorithmic-marketing-attribution-implemented-in-apache-spark-and-r/)\n- [Game Theory Attribution: The Model You’ve Probably Never Heard Of](https://clearcode.cc/blog/game-theory-attribution/)\n- [Marketing Channel Attribution With Markov Models In R](https://www.bounteous.com/insights/2016/06/30/marketing-channel-attribution-markov-models-r/?ns=l)\n- [Multi-Channel Funnels Data-Driven Attribution](https://support.google.com/analytics/topic/3180362?hl=en\u0026ref_topic=3205717)\n- [Marketing Multi-Channel Attribution model with R (part 1: Markov chains concept)](https://analyzecore.com/2016/08/03/attribution-model-r-part-1/)\n- [Marketing Multi-Channel Attribution model with R (part 2: practical issues)](https://analyzecore.com/2017/05/31/marketing-multi-channel-attribution-model-r-part-2-practical-issues/)\n- [ml-book/shapley](https://christophm.github.io/interpretable-ml-book/shapley.html)\n- [Overview of Attribution modeling in MCF](https://support.google.com/analytics/answer/1662518?hl=en)\n\n## 3. Importing the Class\n```python\n\u003e\u003e pip install marketing_attribution_models\n```\n```python\nfrom marketing_attribution_models import MAM\n```\n\n## 4. Demonstration\n### Creation of the MAM Object\nWhen **creating a MAM Object** two Data Frame **templates** can be used as input depending on what is the value of the parameter *group_channels*. \n\n- ***group_channels* = True**: The input Data Frame has **one session** of each user's jorney **per row**.\n  - The values required in each row (in other words, the required columns) are some **distinct** user identification, a **boolean** indication of convertion or lack there of and the session's **source channel**.\n- ***group_channels* = False**: The input Data Frame has **the whole journey** of each user **per row**. In case you use Google Analytics, this template can be obtained by downloading the *Top Conversion Paths* report.    \n  - In this case, both the channels and time to conversion columns are agregated by journey with each touchpoint being separated by '**\u003e**' (the bigger than sign) by default. A different separator can be set in the *path_separator* parameter.\n\nFor this demostration we'll be using a Data Frame in which the journeys are **not yet grouped**, with each row as a different session and without an unique journey id.\n\n\u003e **Note:** The MAM Class has a built in parameter for journey id creation, *create_journey_id_based_on_conversion*, that if **True**, an id is created based on the user id, input in the *group_channels_id_list* parameter, and the column indicating wether there is a conversion or not, whose name is defined by the *journey_with_conv_colname* parameter.\n\nIn this scenario, all sessions from each distinct user will be ordered and for every conversion a new journey id is created. However, we **highly encourage** that this journey id creation is customized based on **knowledge specific to the business in hand** and exploratory conclusions. For instance if in a given business it is noted that the average journey duration is about a week, a new critereon may be defined so that once any user doesn't have any interaction for seven days the journey breaks under the assumption there was a loss of interest. \n\nAs for the parameters now, here's how they're configured for our *group_ channels* = True scenario:\n\n1. A **Pandas DataFrame** is input as a database;\n2. The *group_channels* parameter is set to True;\n3. The name of the column containing the channels in the original DataFrame is informed though the *channels_colname* parameter;\n4. The name of the boolean column that determines wether there is a conversion or not is informed through the *journey_with_conv_colname* parameter;\n5. The list containing the names of the columns used to compose the journey id is informed through the *group_channels_by_id_list*. Although the list could be longer, we're creating this id based on conversions (see item 7), so the user id alone is enough.\n6. The start time of each session is informed in the *group_timestamp_colname* parameter as the name of said column in the original Data Frame. It can be a date or a timestamp.\n7. And finally, in our scenario, we want to generate a journey id based on the columns already indicated on the parameters *group_channels_by_id_list* and *journey_with_conv_colname* by setting *create_journey_id_based_on_conversion* as **True**.\n\n```python\nattributions = MAM(df,\n    group_channels=True,\n    channels_colname = 'channels',\n    journey_with_conv_colname= 'has_transaction',\n    group_channels_by_id_list=['user_id'],\n    group_timestamp_colname = 'visitStartTime',\n    create_journey_id_based_on_conversion = True)\n```\n\nIn order to explore and understand the capabilities of MAM, a \"Random DataFrame Generator\" was implemented through the use of ***random_df*** parameter when set to **True**.\n\n```python\nattributions = MAM(random_df=True)\n```\n    \nAfter the Object MAM is created, we can check out our database now with the addition of our **journey_id** and with sessions grouped in **journeys** using the **attriute *\".DataFrame\"***.\n\n```python\nattributions.DataFrame\n```\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003ejourney_id\u003c/th\u003e\n      \u003cth\u003echannels_agg\u003c/th\u003e\n      \u003cth\u003etime_till_conv_agg\u003c/th\u003e\n      \u003cth\u003econverted_agg\u003c/th\u003e\n      \u003cth\u003econversion_value\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eid:0_J:0\u003c/td\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eid:0_J:1\u003c/td\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eid:0_J:10\u003c/td\u003e\n      \u003ctd\u003eGoogle Search \u0026gt; Organic \u0026gt; Email Marketing\u003c/td\u003e\n      \u003ctd\u003e72.0 \u0026gt; 24.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eid:0_J:11\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eid:0_J:12\u003c/td\u003e\n      \u003ctd\u003eEmail Marketing \u0026gt; Facebook\u003c/td\u003e\n      \u003ctd\u003e432.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20341\u003c/td\u003e\n      \u003ctd\u003eid:9_J:5\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Facebook\u003c/td\u003e\n      \u003ctd\u003e120.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20342\u003c/td\u003e\n      \u003ctd\u003eid:9_J:6\u003c/td\u003e\n      \u003ctd\u003eGoogle Search \u0026gt; Google Search \u0026gt; Google Search\u003c/td\u003e\n      \u003ctd\u003e48.0 \u0026gt; 24.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20343\u003c/td\u003e\n      \u003ctd\u003eid:9_J:7\u003c/td\u003e\n      \u003ctd\u003eOrganic \u0026gt; Organic \u0026gt; Google Search \u0026gt; Google Search\u003c/td\u003e\n      \u003ctd\u003e480.0 \u0026gt; 480.0 \u0026gt; 288.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20344\u003c/td\u003e\n      \u003ctd\u003eid:9_J:8\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Organic\u003c/td\u003e\n      \u003ctd\u003e168.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20345\u003c/td\u003e\n      \u003ctd\u003eid:9_J:9\u003c/td\u003e\n      \u003ctd\u003eGoogle Search \u0026gt; Organic \u0026gt; Google Search \u0026gt; Emai...\u003c/td\u003e\n      \u003ctd\u003e528.0 \u0026gt; 528.0 \u0026gt; 408.0 \u0026gt; 240.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\nThis attribute is **updated** for **every attribution model** generated. Only in the case of heuristic models, a new column is appended containing the attribution value given by said model.\n\n\u003e**Note:** The attribute *.DataFrame* does not interfere with any model calculations. Should it be altered by usage, the following results aren't affected.\n\n```python\nattributions.attribution_last_click()\nattributions.DataFrame\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003ejourney_id\u003c/th\u003e\n      \u003cth\u003echannels_agg\u003c/th\u003e\n      \u003cth\u003etime_till_conv_agg\u003c/th\u003e\n      \u003cth\u003econverted_agg\u003c/th\u003e\n      \u003cth\u003econversion_value\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eid:0_J:0\u003c/td\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eid:0_J:1\u003c/td\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eid:0_J:10\u003c/td\u003e\n      \u003ctd\u003eGoogle Search \u0026gt; Organic \u0026gt; Email Marketing\u003c/td\u003e\n      \u003ctd\u003e72.0 \u0026gt; 24.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eid:0_J:11\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eid:0_J:12\u003c/td\u003e\n      \u003ctd\u003eEmail Marketing \u0026gt; Facebook\u003c/td\u003e\n      \u003ctd\u003e432.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20341\u003c/td\u003e\n      \u003ctd\u003eid:9_J:5\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Facebook\u003c/td\u003e\n      \u003ctd\u003e120.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20342\u003c/td\u003e\n      \u003ctd\u003eid:9_J:6\u003c/td\u003e\n      \u003ctd\u003eGoogle Search \u0026gt; Google Search \u0026gt; Google Search\u003c/td\u003e\n      \u003ctd\u003e48.0 \u0026gt; 24.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20343\u003c/td\u003e\n      \u003ctd\u003eid:9_J:7\u003c/td\u003e\n      \u003ctd\u003eOrganic \u0026gt; Organic \u0026gt; Google Search \u0026gt; Google Search\u003c/td\u003e\n      \u003ctd\u003e480.0 \u0026gt; 480.0 \u0026gt; 288.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20344\u003c/td\u003e\n      \u003ctd\u003eid:9_J:8\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Organic\u003c/td\u003e\n      \u003ctd\u003e168.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e20345\u003c/td\u003e\n      \u003ctd\u003eid:9_J:9\u003c/td\u003e\n      \u003ctd\u003eGoogle Search \u0026gt; Organic \u0026gt; Google Search \u0026gt; Emai...\u003c/td\u003e\n      \u003ctd\u003e528.0 \u0026gt; 528.0 \u0026gt; 408.0 \u0026gt; 240.0 \u0026gt; 0.0\u003c/td\u003e\n      \u003ctd\u003eTrue\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\nUsually the volume of data worked with is extensive, so it is impractical or even impossible to analyse results attributed to **each** journey with transaction. With the attribute ***group_by_channels_models***, however, all results can be seen grouped by channel.\n\n\u003e**Note**: Grouped results **do not overwrite** each other in case the same model is used in two distinct instances. Both (or even more) of them are shown in \"*group_by_channels_models*\".\n\n```python\nattributions.group_by_channels_models\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003echannels\u003c/th\u003e\n      \u003cth\u003eattribution_last_click_heuristic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e2133\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eEmail Marketing\u003c/td\u003e\n      \u003ctd\u003e1033\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e3168\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eGoogle Display\u003c/td\u003e\n      \u003ctd\u003e1073\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e4255\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eInstagram\u003c/td\u003e\n      \u003ctd\u003e1028\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e6322\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eYoutube\u003c/td\u003e\n      \u003ctd\u003e1093\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\nAs with the *.DataFrame* attribute, *group_by_channels_models* is also updated for every model used **without the limitation** of not displaying algorithmic results.\n\n```python\nattributions.attribution_shapley()\nattributions.group_by_channels_models\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003echannels\u003c/th\u003e\n      \u003cth\u003eattribution_last_click_heuristic\u003c/th\u003e\n      \u003cth\u003eattribution_shapley_size4_conv_rate_algorithmic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e109\u003c/td\u003e\n      \u003ctd\u003e74.926849\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eEmail Marketing\u003c/td\u003e\n      \u003ctd\u003e54\u003c/td\u003e\n      \u003ctd\u003e70.558428\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e160\u003c/td\u003e\n      \u003ctd\u003e160.628945\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eGoogle Display\u003c/td\u003e\n      \u003ctd\u003e65\u003c/td\u003e\n      \u003ctd\u003e110.649352\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e193\u003c/td\u003e\n      \u003ctd\u003e202.179519\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003eInstagram\u003c/td\u003e\n      \u003ctd\u003e64\u003c/td\u003e\n      \u003ctd\u003e72.982433\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e315\u003c/td\u003e\n      \u003ctd\u003e265.768549\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e7\u003c/td\u003e\n      \u003ctd\u003eYoutube\u003c/td\u003e\n      \u003ctd\u003e58\u003c/td\u003e\n      \u003ctd\u003e60.305925\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n### About the Models\n\nAll heuristic models behave the same when using the attributes *.DataFrame* and *.group_by_channels_models*, as explained before, and the **output** of all heuristic **model's methods** return a **tuple** containing two **pandas Series**.\n\n```python\nattribution_first_click = attributions.attribution_first_click()\n```\n\nThe **first** Series of the tuple are the results in a **journey granularity**, similar to the observed in the *.DataFrame* attribute\n\n\n```python\nattribution_first_click[0]\n```\n\n```\n    0                          [1, 0, 0, 0, 0]\n    1                                      [1]\n    2              [1, 0, 0, 0, 0, 0, 0, 0, 0]\n    3                                   [1, 0]\n    4                                      [1]\n                           ...                \n    20512                               [1, 0]\n    20513                            [1, 0, 0]\n    20514    [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n    20515                            [1, 0, 0]\n    20516                         [1, 0, 0, 0]\n    Length: 20517, dtype: object\n```\n\nThe **second** one contains the results with a **channel granularity**, as seen in the **.group_by_channels_models** attribute.    \n\n```python\nattribution_first_click[1]\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003echannels\u003c/th\u003e\n      \u003cth\u003eattribution_first_click_heuristic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e2078\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eEmail Marketing\u003c/td\u003e\n      \u003ctd\u003e1095\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e3177\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eGoogle Display\u003c/td\u003e\n      \u003ctd\u003e1066\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e4259\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003eInstagram\u003c/td\u003e\n      \u003ctd\u003e1007\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e6361\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e7\u003c/td\u003e\n      \u003ctd\u003eYoutube\u003c/td\u003e\n      \u003ctd\u003e1062\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n#### Customizing Models\n\nOf all models present in the Object MAM, only Last Click, First Click and Linear have **no customizable parameters** but *group_by_channels_models*, which has a **boolean value** that when set to **False** the model doesn't return the attribution goruped by channels.\n\n##### Last Click Non- Model \n\nCreated to replicate Google Analytics' default attriution (*Last Click Non Direct*) in which **Direct traffic** is **overwritten** in case previous interations have a specific traffic source other than Direct itself in a given timespan (6 months by default).\n\nIf unspecified, the parameter *but_not_this_channel* is set to *'Direct'*, but it can be set to any other channel of interest to the business.\n\n```python\nattributions.attribution_last_click_non(but_not_this_channel='Direct')[1]\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003echannels\u003c/th\u003e\n      \u003cth\u003eattribution_last_click_non_Direct_heuristic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e11\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eEmail Marketing\u003c/td\u003e\n      \u003ctd\u003e60\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e172\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eGoogle Display\u003c/td\u003e\n      \u003ctd\u003e69\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e224\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003eInstagram\u003c/td\u003e\n      \u003ctd\u003e67\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e350\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e7\u003c/td\u003e\n      \u003ctd\u003eYoutube\u003c/td\u003e\n      \u003ctd\u003e65\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n##### Position Based Model \n\nThis model has a parameter *list_positions_first_middle_last* in which the weights respective to the positions of channels in each journey can me specified according to **business related** decisions. The default distribution of the parameter is **40%** for the **introducing** channel, **40%** for the **converting / last** channel and **20%** for the **intermidiate** ones.\n\n```python\nattributions.attribution_position_based(list_positions_first_middle_last=[0.3, 0.3, 0.4])[1]\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003echannels\u003c/th\u003e\n      \u003cth\u003eattribution_position_based_0.3_0.3_0.4_heuristic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e95.685085\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eEmail Marketing\u003c/td\u003e\n      \u003ctd\u003e57.617191\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e145.817501\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eGoogle Display\u003c/td\u003e\n      \u003ctd\u003e56.340693\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e193.282305\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003eInstagram\u003c/td\u003e\n      \u003ctd\u003e54.678557\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e288.148896\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e7\u003c/td\u003e\n      \u003ctd\u003eYoutube\u003c/td\u003e\n      \u003ctd\u003e55.629772\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n##### **Time Decay Model** \n\nThere are two customizable settings: The **decay rate**, throght the *decay_over_time** parameter, and the time (in hours) **between each decaiment** through the *frequency* parameter.\n\nIt is worth noting, however, that in case there is more than one touchpoint between frequency intervals the conversion value will be equally distributed among these channels.\n\nAs an example:\n- **Channels:** Facebook \u003e Organic \u003e Paid Search\n- **Time between touchpoints:** 14 \u003e 12 \u003e 0\n- **Decay Frequence:** 7\n- **Results:**\n  - 25% goes to Facebook;\n  - 25% goes to Organic;\n  - 50% goes to Paid Search;\n  \n```python\nattributions.attribution_time_decay(\n    decay_over_time=0.6,\n    frequency=7)[1]\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003echannels\u003c/th\u003e\n      \u003cth\u003eattribution_time_decay0.6_freq7_heuristic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e108.679538\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eEmail Marketing\u003c/td\u003e\n      \u003ctd\u003e54.425914\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e159.592216\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eGoogle Display\u003c/td\u003e\n      \u003ctd\u003e64.350107\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e192.838884\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003eInstagram\u003c/td\u003e\n      \u003ctd\u003e64.611414\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e314.920082\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e7\u003c/td\u003e\n      \u003ctd\u003eYoutube\u003c/td\u003e\n      \u003ctd\u003e58.581845\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n##### Markov Chains\n\nUppon being called, this model returns a tuple with **four** components. The first two (indexed 0 and 1) are just like with the heuristic models, with the representation of the *.DataFrame* and *.group_by_channels_models* respectively. As for the third and fourth components (indexed 2 and 3) the results are the **transition matrix** and the **removal effect table**.\n\nTo start off, it is possible to indicate if same **state transitions** are considered or not (*e.g.* Direct to Direct).\n\n```python\nattribution_markov = attributions.attribution_markov(transition_to_same_state=False)\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003echannels\u003c/th\u003e\n      \u003cth\u003eattribution_markov_algorithmic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e2305.324362\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eEmail Marketing\u003c/td\u003e\n      \u003ctd\u003e1237.400774\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eFacebook\u003c/td\u003e\n      \u003ctd\u003e3273.918832\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eYoutube\u003c/td\u003e\n      \u003ctd\u003e1231.183938\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eGoogle Search\u003c/td\u003e\n      \u003ctd\u003e4035.260685\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003eInstagram\u003c/td\u003e\n      \u003ctd\u003e1205.949095\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e5358.270644\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e7\u003c/td\u003e\n      \u003ctd\u003eGoogle Display\u003c/td\u003e\n      \u003ctd\u003e1213.691671\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\nThis configuration **does not affect** the overall attributed results for each channel, but the values observed in the **transition matrix**. Because we set *transition_to_same_state* to **False**, the diagonal, indicating states transitioning to themselves, is nulled.\n\n```python\nax, fig = plt.subplots(figsize=(15,10))\nsns.heatmap(attribution_markov[2].round(3), cmap=\"YlGnBu\", annot=True, linewidths=.5)\n```\n\n![png](readme-images/output_37_1.png)\n\n**Removal Effect**, the fourth *attribution_markov* output, is obtained by the ratio of the difference between the probability of conversion in general and the probability once said channel is removed over the general probability again.\n\n```python\nax, fig = plt.subplots(figsize=(2,5))\nsns.heatmap(attribution_markov[3].round(3), cmap=\"YlGnBu\", annot=True, linewidths=.5)\n```\n\n![png](readme-images/output_39_1.png)\n\n##### Shapley Value\n\nFinally, the second algorith model of **MAM** whose concept comes from **Game Theory**. The objective here is to distribute the contribution of each player (in our case, channel) in a game of cooperation calculated using combinations of journeys with and without a given channel.\n\nThe parameter **size** defines a limit of how **long** a **chain of channels** is in every journey. By default, it's value is set to **4**, meaning only the **four last channels preceding a conversion** are considered.\n\nThe calculation method of marginal contributions of each channel can vary with the ***order*** parameter. By default it is set to **False**, which means the contribution is calculated disregarding the order of each channel in the journeys.\n\n```python\nattributions.attribution_shapley(size=4, order=True, values_col='conv_rate')[0]\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003ecombinations\u003c/th\u003e\n      \u003cth\u003econversions\u003c/th\u003e\n      \u003cth\u003etotal_sequences\u003c/th\u003e\n      \u003cth\u003econversion_value\u003c/th\u003e\n      \u003cth\u003econv_rate\u003c/th\u003e\n      \u003cth\u003eattribution_shapley_size4_conv_rate_order_algorithmic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e909\u003c/td\u003e\n      \u003ctd\u003e926\u003c/td\u003e\n      \u003ctd\u003e909\u003c/td\u003e\n      \u003ctd\u003e0.981641\u003c/td\u003e\n      \u003ctd\u003e[909.0]\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Email Marketing\u003c/td\u003e\n      \u003ctd\u003e27\u003c/td\u003e\n      \u003ctd\u003e28\u003c/td\u003e\n      \u003ctd\u003e27\u003c/td\u003e\n      \u003ctd\u003e0.964286\u003c/td\u003e\n      \u003ctd\u003e[13.948270234099155, 13.051729765900845]\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Email Marketing \u0026gt; Facebook\u003c/td\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003e1.000000\u003c/td\u003e\n      \u003ctd\u003e[1.6636366232390172, 1.5835883671498818, 1.752...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Email Marketing \u0026gt; Facebook \u0026gt; Google D...\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1.000000\u003c/td\u003e\n      \u003ctd\u003e[0.2563402919193473, 0.2345560799963515, 0.259...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Email Marketing \u0026gt; Facebook \u0026gt; Google S...\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1.000000\u003c/td\u003e\n      \u003ctd\u003e[0.2522517802130265, 0.2401286956930936, 0.255...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1278\u003c/td\u003e\n      \u003ctd\u003eYoutube \u0026gt; Organic \u0026gt; Google Search \u0026gt; Google Dis...\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e0.500000\u003c/td\u003e\n      \u003ctd\u003e[0.2514214624662836, 0.24872101523605275, 0.24...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1279\u003c/td\u003e\n      \u003ctd\u003eYoutube \u0026gt; Organic \u0026gt; Google Search \u0026gt; Instagram\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1.000000\u003c/td\u003e\n      \u003ctd\u003e[0.2544401477637237, 0.2541071889956603, 0.253...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1280\u003c/td\u003e\n      \u003ctd\u003eYoutube \u0026gt; Organic \u0026gt; Instagram\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e1.000000\u003c/td\u003e\n      \u003ctd\u003e[1.2757196742326997, 1.4712839059493295, 1.252...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1281\u003c/td\u003e\n      \u003ctd\u003eYoutube \u0026gt; Organic \u0026gt; Instagram \u0026gt; Facebook\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e1.000000\u003c/td\u003e\n      \u003ctd\u003e[0.2357631944623868, 0.2610913781266248, 0.247...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1282\u003c/td\u003e\n      \u003ctd\u003eYoutube \u0026gt; Organic \u0026gt; Instagram \u0026gt; Google Search\u003c/td\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003e1.000000\u003c/td\u003e\n      \u003ctd\u003e[0.7223482210689489, 0.7769049003203142, 0.726...\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\nFinally, the parameter indicating what metric is used to calculate the Shapley Value is **values_col**, which by default is set to *conversion rate*. In doing so, journeys **without conversions** are taken into acount. \n\nIt is possible, however, to consider only **literal conversions** when using the model as seen below.\n\n```python\nattributions.attribution_shapley(size=3, order=False, values_col='conversions')[0]\n```\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003e\u003c/th\u003e\n      \u003cth\u003ecombinations\u003c/th\u003e\n      \u003cth\u003econversions\u003c/th\u003e\n      \u003cth\u003etotal_sequences\u003c/th\u003e\n      \u003cth\u003econversion_value\u003c/th\u003e\n      \u003cth\u003econv_rate\u003c/th\u003e\n      \u003cth\u003eattribution_shapley_size3_conversions_algorithmic\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e0\u003c/td\u003e\n      \u003ctd\u003eDirect\u003c/td\u003e\n      \u003ctd\u003e11\u003c/td\u003e\n      \u003ctd\u003e18\u003c/td\u003e\n      \u003ctd\u003e18\u003c/td\u003e\n      \u003ctd\u003e0.611111\u003c/td\u003e\n      \u003ctd\u003e[11.0]\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Email Marketing\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003e5\u003c/td\u003e\n      \u003ctd\u003e0.800000\u003c/td\u003e\n      \u003ctd\u003e[2.0, 2.0]\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Email Marketing \u0026gt; Google Search\u003c/td\u003e\n      \u003ctd\u003e1\u003c/td\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003e0.500000\u003c/td\u003e\n      \u003ctd\u003e[-3.1666666666666665, -7.666666666666666, 11.8...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Email Marketing \u0026gt; Organic\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003e6\u003c/td\u003e\n      \u003ctd\u003e0.666667\u003c/td\u003e\n      \u003ctd\u003e[-7.833333333333333, -10.833333333333332, 22.6...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003eDirect \u0026gt; Facebook\u003c/td\u003e\n      \u003ctd\u003e3\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e0.750000\u003c/td\u003e\n      \u003ctd\u003e[-8.5, 11.5]\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n      \u003ctd\u003e...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e75\u003c/td\u003e\n      \u003ctd\u003eInstagram \u0026gt; Organic \u0026gt; Youtube\u003c/td\u003e\n      \u003ctd\u003e46\u003c/td\u003e\n      \u003ctd\u003e123\u003c/td\u003e\n      \u003ctd\u003e123\u003c/td\u003e\n      \u003ctd\u003e0.373984\u003c/td\u003e\n      \u003ctd\u003e[5.833333333333332, 34.33333333333333, 5.83333...\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e76\u003c/td\u003e\n      \u003ctd\u003eInstagram \u0026gt; Youtube\u003c/td\u003e\n      \u003ctd\u003e2\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e4\u003c/td\u003e\n      \u003ctd\u003e0.500000\u003c/td\u003e\n      \u003ctd\u003e[2.0, 0.0]\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e77\u003c/td\u003e\n      \u003ctd\u003eOrganic\u003c/td\u003e\n      \u003ctd\u003e64\u003c/td\u003e\n      \u003ctd\u003e92\u003c/td\u003e\n      \u003ctd\u003e92\u003c/td\u003e\n      \u003ctd\u003e0.695652\u003c/td\u003e\n      \u003ctd\u003e[64.0]\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e78\u003c/td\u003e\n      \u003ctd\u003eOrganic \u0026gt; Youtube\u003c/td\u003e\n      \u003ctd\u003e8\u003c/td\u003e\n      \u003ctd\u003e11\u003c/td\u003e\n      \u003ctd\u003e11\u003c/td\u003e\n      \u003ctd\u003e0.727273\u003c/td\u003e\n      \u003ctd\u003e[30.5, -22.5]\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e79\u003c/td\u003e\n      \u003ctd\u003eYoutube\u003c/td\u003e\n      \u003ctd\u003e11\u003c/td\u003e\n      \u003ctd\u003e15\u003c/td\u003e\n      \u003ctd\u003e15\u003c/td\u003e\n      \u003ctd\u003e0.733333\u003c/td\u003e\n      \u003ctd\u003e[11.0]\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n### Visualization\nAfter obtaining every attribution from different models stored in our ***.group_by_channels_models*** object it is possible to plot and compare results for insights\n\n```python\nattributions.plot()\n```\n![png](readme-images/output_45_1.png)\n\nIn case you're only interested in the algorithmic models, this can me specified in the *model_type* parameter.\n\n```python\nattributions.plot(model_type='algorithmic')\n```\n\n![png](readme-images/output_47_1.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDP6%2FMarketing-Attribution-Models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDP6%2FMarketing-Attribution-Models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDP6%2FMarketing-Attribution-Models/lists"}