<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Leopold d’Avezac on Medium]]></title>
        <description><![CDATA[Stories by Leopold d’Avezac on Medium]]></description>
        <link>https://medium.com/@leopoldavezac?source=rss-c762a4a1b1f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*wFJhboYy01wG6UuezQieWw.png</url>
            <title>Stories by Leopold d’Avezac on Medium</title>
            <link>https://medium.com/@leopoldavezac?source=rss-c762a4a1b1f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:04:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leopoldavezac/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[BayesianMMM — State of the Art Media Mix Modelling]]></title>
            <link>https://medium.com/data-science/bayesianmmm-state-of-the-art-media-mix-modelling-9207c4445757?source=rss-c762a4a1b1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9207c4445757</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[model]]></category>
            <category><![CDATA[media-mix-modeling]]></category>
            <category><![CDATA[marketing-mix-modeling]]></category>
            <dc:creator><![CDATA[Leopold d’Avezac]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 13:29:04 GMT</pubDate>
            <atom:updated>2021-09-07T13:29:04.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kiIa8LyPznx6f9KG" /><figcaption>Photo by <a href="https://unsplash.com/@ro_ka?utm_source=medium&amp;utm_medium=referral">Robert Katzki</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>BayesianMMM — State of the Art Media Mix Modelling</h3><h4>Test a bayesian model of your media mix effortlessly</h4><p>Testing a new marketing mix model is time costly. That is the reason behind the development of BayesianMMM a script to fit MMM without writing code.</p><p>Within a few hours, you could be looking at the results of the state of the art model.</p><p><a href="https://github.com/leopoldavezac/BayesianMMM">GitHub - leopoldavezac/BayesianMMM: (ml) - python implementation of bayesian media mix modelling with shape and carryover effect</a></p><h3>Audience</h3><ul><li>marketing data scientist</li><li>marketing machine learning engineering</li><li>marketing data analyst</li><li>campaign manager/owner</li></ul><h3>Introduction</h3><p>Media Mix Modelling is the holy grail of marketing science. An accurate media mix model can give us the optimal media mix, the one that reduces media spending while increasing revenue.</p><p><em>A media mix model uncovers the </em><strong><em>causal </em></strong><em>relationship between media spends and revenue.</em></p><p>The dataset used to train such model generally is at a weekly level, and looks something like this,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*LscXPX6O0eeEosH-cLcI0A.png" /><figcaption>Image by Author</figcaption></figure><h3>Model</h3><p>The model used in BayesianMMM was proposed in <a href="https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/46001.pdf">Bayesian Methods for Media Mix Modeling with Carryover and Shape Effects</a> by a team of researchers from Google.</p><p>Just like a classic MMM, it aims to predict sales based on media spends and additional control variables (season, weather etc). However, there are three key updates to the classic regression model.</p><h4><strong>Carryover effect</strong></h4><p>Media spends have a lasting effect on sales, a dollar spent on a given week will contribute to sales for multiple weeks. We call this effect, the <strong>carryover effect</strong> and it is explicitly incorporated in the model.</p><p>Two mathematical functions can be used to model the carryover effect.</p><p><strong>Geodecay</strong></p><p>The <strong>geodecay transformation </strong><em>only </em>models the lasting impact of media spends.</p><p>This function takes as input media spends for a given media during L weeks periods, L and the retain-rate. L is the maximum duration effect of a spend. L can be treated as a hyperparameter, defined using business knowledge or set to 13 (in simulation settings L has been found to be a good approximation of infinity) as proposed in the research paper. The retain rate is the coefficient that gives us the retained spend during the next period (t+1) using the spend during the current period (t).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*5H0QpsxRAW9-TAEkCs8Vtg.png" /><figcaption>Image by Author</figcaption></figure><p>Here, we set the spend to be 1 at lag = 0 and 0 otherwise. With a retain rate of 0.7, we obtained the following carryover spend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*8972a-WGyEww1R0xwR6Jqw.png" /><figcaption>Image by Author</figcaption></figure><p><strong>Adstock transformation</strong></p><p>Sometimes we expect the media spends effect to peak after a certain duration. The <strong>adstock transformation </strong>models the lasting and delayed impact of media spends.</p><p>This function takes as input media spends for a given media during L weeks periods, L, the retain-rate and the delay of the peak. The delay is the number of periods before the peak effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*tp3YuApV5WAkDyGeqhjjrg.png" /><figcaption>Image by Author</figcaption></figure><p>Here again, we set the spend to be 1 at lag = 0 and 0 otherwise. With a retain rate of 0.7 and a delay of 5, we obtained the following adstock spend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*nHrLscmNIEyV0Sxolxf1Nw.png" /><figcaption>Image by Author</figcaption></figure><h4>Shape effect</h4><p>Media spends produce diminishing returns as they grow bigger. We call this the shape effect and it is explicitly incorporated in the model.</p><p><strong>Hill</strong></p><p>This function takes as input the spend at period t, the shape and the half-saturation. The parameters are not as interpretable as the ones of the carryover transformations. T understand them you would have to play around with them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*LHY7cPJDh88YJQcvlyy20g.png" /><figcaption>Image by Author</figcaption></figure><p>Here we set the spend to 1, the shape to 0.5 and the half-saturation to 0.5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*DPjvhMX-u5ejP-fkB-3TAg.png" /><figcaption>Image by Author</figcaption></figure><p>Putting it all together our model can be expressed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*Ssp328P7Oh-eMZHfFrzkbA.png" /><figcaption>Image by Author</figcaption></figure><h4>Fitting method</h4><p>The model parameters are estimated using MCMC via the pystan API.</p><p>We set the same priors on the parameters’ distribution as in the <a href="https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/46001.pdf">research paper</a>.</p><p>After a user-defined number of iterations, we obtained samples of our parameters’ posterior distribution. We use those samples to estimate the parameters true value.</p><h3>Challenges</h3><p>There are big challenges in fitting a media mix model, Here is a non-exhaustive list of them.</p><ul><li>The limited amount of data available</li></ul><p>The amount of data available is small compared to the number of parameters. This can lead to accuracy issues and introduce some bias in the test and evaluation accuracy.</p><ul><li>Correlation between the input variables</li></ul><p>Often there is a high correlation between the media spends. This can lead to bad attribution of sales to the sales channel.</p><ul><li>Limited range of data</li></ul><p>The limited range of data may also be a problem as marketing stakeholders always want to extrapolate the results.</p><p>You can read more on those challenges and how to approach them in <a href="https://storage.googleapis.com/pub-tools-public-publication-data/pdf/2d0395bc7d4d13ddedef54d744ba7748e8ba8dd1.pdf">Challenges And Opportunities In Media Mix Modeling</a>.</p><h3>Results</h3><p>After running the script we get the following results,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*Dvp6Mrji1sLspP0ZUKE9qw.png" /><figcaption>Image by Author</figcaption></figure><p>Here you can see the contribution analysis plot generated using a demo dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*qYvwJDGa703yV6LTc-B9dw.png" /><figcaption>Image by Author</figcaption></figure><h3>Usage</h3><p>To learn how to use BayesianMMM please refer to the Github repo.</p><p><a href="https://github.com/leopoldavezac/BayesianMMM">GitHub - leopoldavezac/BayesianMMM: (ml) - python implementation of bayesian media mix modelling with shape and carryover effect</a></p><h3>Conclusion</h3><p>While the BayesianMMM script will greatly reduce the time needed to test the state of the art media mix model, it does not deal with all the challenges. You will still have to handle those yourself!</p><p>Thanks for reading, you can connect with me on LinkedIn.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9207c4445757" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/bayesianmmm-state-of-the-art-media-mix-modelling-9207c4445757">BayesianMMM — State of the Art Media Mix Modelling</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Explore your data frictionless]]></title>
            <link>https://medium.com/data-science/explore-your-data-frictionless-adddb3759bb?source=rss-c762a4a1b1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/adddb3759bb</guid>
            <category><![CDATA[data-cleaning]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Leopold d’Avezac]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 11:58:57 GMT</pubDate>
            <atom:updated>2020-06-10T14:37:01.638Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introducing a new framework for data exploration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y1Wbw5LabCQAzf_M" /><figcaption>Photo by <a href="https://unsplash.com/@anphotos?utm_source=medium&amp;utm_medium=referral">Akshay Nanavati</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Problem</h3><p>As a data scientist, I always thought that code wasn’t the perfect solution for exploring data sets.</p><p>In my opinion, data exploration should be a smooth process, not a jerky one.</p><p>Another point I did not like about data exploration using code is the high code redundancy between projects.</p><p>If you aren’t a newbie, chances are that you have developed a function to identify and plot each variable of your data set. But still, you may find that this method doesn’t allow for in-depth exploration. You still need to tweak your code to go beyond the overall distribution.</p><p>A few months ago, I got tired of this.</p><p>I decided to code <strong>Smoof</strong> my first attempt at creating a software for frictionless data exploration.</p><h3>Solution</h3><blockquote>Smoof is not one stop for all solution but rather a productivity tool for data exploration.</blockquote><p>You can try Smoof with some demo datasets <a href="http://leopoldavezac.pythonanywhere.com/">here</a>. You can also test it on your own data by downloading the <a href="https://github.com/leopoldavezac/smoof">code</a> (python) to run it on your machine.</p><h4>How to use it</h4><p><strong>Navigate to your working directory and select a csv file</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*tEUHNvOx_4-QfMiO48Ov2A.gif" /></figure><p><strong>Output dataset key infos</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5eA77ZDrVHF2x8MIJ3MFYw.png" /></figure><p><strong>Output Variables key infos</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcnF00FjNAM53qSMkT05xA.png" /></figure><p>The number of outliers is estimated using interquartiles method. It surely isn’t the best method for identifying outliers but it is time efficient. The purpose here is to provide upfront infos about the potential presence of abnormal values.</p><p>All descriptive statistics on categorical variable are computed on the count per labels.</p><p><strong>Visualize variables distributions</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*okwjdDnM1S73GBRvDbCf9g.gif" /></figure><p><strong>Cross filtering</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U49y-BHaZptmfMa4HaiPPg.gif" /></figure><p><strong>Drill down</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*S01HFlrhGIgRUpEgBau24g.gif" /></figure><p><strong>Drop a a filter</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*efBq0h6G60dszVQQp8NbBA.gif" /></figure><h4>Notes on variables types and their implication</h4><p>In Smoof variables are recognized as one of the following types:</p><ul><li>Date</li><li>Numeric</li><li>Category Short (less than 15 unique labels)</li><li>Category Long (more than 15 unique labels)</li></ul><p>The reason for creating two sub types for categories is that a bar chart for more than 15 different labels is not easy to analyze. That’s why Category Long are represented as the distribution of the count of values per labels.</p><h4>Current Limits</h4><p>Smooth handles dataset up to 10 MB, for bigger datasets it still runs but loading and cross filtering operations might get slow.</p><p>The actual version lacks of some key features such as 2D and 3D plots and null values exploration. Those features will be added in the next version!</p><h3>Become a co-creator</h3><p>This is an open source project, I will be glad to have you develop the futures versions with me. If you are interested, please contact <a href="https://www.linkedin.com/in/leopolddavezac/">me</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adddb3759bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/explore-your-data-frictionless-adddb3759bb">Explore your data frictionless</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to efficiently design machine learning system]]></title>
            <link>https://medium.com/data-science/how-to-efficiently-design-machine-learning-system-caef9e05d5fb?source=rss-c762a4a1b1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/caef9e05d5fb</guid>
            <category><![CDATA[andrew-ng]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[machine-learning-tuning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Leopold d’Avezac]]></dc:creator>
            <pubDate>Thu, 28 May 2020 15:58:27 GMT</pubDate>
            <atom:updated>2020-05-28T15:58:27.932Z</atom:updated>
            <content:encoded><![CDATA[<h4>Key insights from Andrew Ng on Machine Learning Design</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yPK2TAxTUYwZ301X" /><figcaption>Photo by <a href="https://unsplash.com/@rohanmakhecha?utm_source=medium&amp;utm_medium=referral">Rohan Makhecha</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s say you’re designing a machine learning system, you have trained it on your data with the default parameters using your favorite model and its performance isn’t good enough.</p><p>From there chances are that you will navigate in the dark, trying thing here and there without a real plan and no guarantee that what you’re doing is going to increase the performance of your model.</p><p>Luckily for us, one of the god father of machine learning Andrew Ng has given us a way to effectively tune machine learning model. Here it is.</p><ol><li>Implement a data pipeline as quickly as possible</li><li>Diagnose high bias and/or high variance and act in consequence</li><li>Manually analyze miss classified records and look for patterns</li></ol><p><em>Continuously Test and learn using selected evaluation metric</em></p><h3>1. Implement a data pipeline as quickly as possible</h3><p>Your data pipeline should execute the following steps:</p><ul><li>Clean the undesired values (outliers)</li><li>Fill or drop null values</li><li>Normalize the numerical features</li><li>Encoded the categorical features</li><li>Split data into 3 sets train (70%) / cross-validation (15%) / test (15%) (sets size for non big data applications)</li><li>Fit and predict using your favorite model</li><li>Evaluate model performance on train / cross validation set using a metric of your choice (F1, Precision, Recall, MAE etc)</li></ul><p>Andrew advice on this is to write the code corresponding for each of the steps above as quickly as possible without worrying too much on the two first steps. They can quickly become time consuming, it is better to make strong assumptions on the first implementation and iterate on those later on.</p><h3>2. Diagnose high bias or/and high variance</h3><p>There are many ways of diagnosing bias and or variance Andrew proposes two ways of doing so :</p><h4>Learning curves</h4><p>Learning curves are defined as the representation of the evolution of the cost over the number of iterations of gradient descent for both the cross validation and the test set.</p><p>Sadly, it is by definition only relevant to algorithms using gradient descent or a variant for optimizing it parameters.</p><p>By looking at them you can quickly diagnose high bias vs high variance. The following image speak for itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*_VjFd1ByWY-todsA-omMKQ.png" /></figure><h4>Comparing cross-validation accuracy, train accuracy and human performance</h4><blockquote><strong>Bayes error :</strong> optimal (unreachable) error rate for a specific problem. Often approximated using best available human performance.</blockquote><p><em>High variance:</em> train error is quite close to the Bayes error and cross validation error is quite worst than both.</p><p><em>High bias:</em> train error is quite close to cross validation error and both are quite worst than the Bayes error.</p><p><em>High bias and high variance:</em> train error is quite better than cross validation error and both are quite worst than the Bayes error.</p><p>I have used the term “quite” to insist on the fact that there are no rules thumb to define how big or small the difference on cross-validation error train error and Bayes error should be for either of those cases.</p><h4>Taking actions based on diagnostic</h4><p>The action that you could take based on the bias/variance diagnostic differs from one model to another.</p><p>In this article I would only present the ones for Logistic and Linear Regression and Neural Network but you can find the corresponding actions for Tree based models, KNN and SVM with a quick Google search.</p><p>The key insights here is that you should diagnose the type of problem you have (high bias or high variance as quickly as possible).</p><p><strong>High bias:</strong></p><ul><li>Increase gradient descent number of iterations (all)</li><li>Add polynomial features (Linear &amp; Logistic Regression)</li><li>Feature engineering (all)</li><li>Increase number of layers / number of units per layer (Neural Network)</li></ul><p><strong>High variance:</strong></p><ul><li>Add regularization : L1 norm (all), Drop out regularization (Neural Network)</li><li>Add more data (all)</li></ul><h3>3. Error Analysis</h3><p>Error analysis consists in collecting a random sample of miss classified records in the case of a classification problem or records for which the prediction error was high in the case of a regression problem from the test set. Then you should analyze the distribution of the sample across various categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*OZAFv_2Mx4X3N9OyS1lEGQ.png" /></figure><p>In the upper error analysis output table, you can see a practical example of the method in the case of a cat detector algorithm.</p><p>The main insights that can be drawn from that table is that 61% of blurry images and 43% of miss classified records were miss classified. Based on those results, spending some time on improving the algorithms performance on Great Cat and Blurry images seems worthwhile.</p><p>The dataset may or not contained detailed informations about its records. That’s, why manually looking at the records may help you to create categories based on your observations.</p><p>In the upper example, it is only by manually looking and classifying images that the great insights on how to improve performance were discovered.</p><h3>Continuously test and learn using your evaluation metric</h3><p>Throughout the second and third step use your setup for evaluation build in step 1 to track the amelioration of your algorithm performance.</p><p>You should also use this setup, to test different hyper parameters/models and test different methods for filling null values and filtering out outliers.</p><p>If you feel I missed something please let me know!</p><p>All credits to Andrew Ng aka the pope of machine learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caef9e05d5fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-to-efficiently-design-machine-learning-system-caef9e05d5fb">How to efficiently design machine learning system</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to evaluate marketing in the B2B industry?]]></title>
            <link>https://medium.com/data-science/how-to-evaluate-marketing-in-the-b2b-retail-industry-5a183510006?source=rss-c762a4a1b1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a183510006</guid>
            <category><![CDATA[marketing]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[b2b]]></category>
            <category><![CDATA[metrics]]></category>
            <category><![CDATA[attribution]]></category>
            <dc:creator><![CDATA[Leopold d’Avezac]]></dc:creator>
            <pubDate>Sun, 01 Dec 2019 19:53:59 GMT</pubDate>
            <atom:updated>2020-05-25T13:55:31.736Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VlIuL8X50itt5ljC" /><figcaption>Photo by <a href="https://unsplash.com/@merakist?utm_source=medium&amp;utm_medium=referral">Merakist</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>How to evaluate the overall impact of marketing on sales in the B2B industry? 🤑</h3><h4>#marketing #b2b #datasciences #attribution #buyingbehaviour</h4><p>This article address the marketing attribution problem for B2B industries where customers have a purchase frequency (furnitures, it material etc).</p><h3>Marketing Attribution</h3><p>If you are a marketer in the B2B industry you are probably struggling to find the right metrics when it comes to evaluating the impact of your campaigns on sales. Sometimes campaigns facilitate a sale, sometimes they allow for introducing a new customer to the sales team and sometimes customers directly calls the sales team without having been incentivized by any of your campaigns.</p><p>A well-known way of dealing with this melting pot of sales and marketing interactions with the customers is to use the pipeline &amp; revenue generated by opportunities that started as leads raised through calls to action placed in marketing campaigns. Those are great metrics, but you may want to create new metrics to look at the overall picture like the support &amp; assist on sales over the customer base. Why is that? Because, you are probably missing a part of the revenue &amp; pipeline that you also influenced, a part that may be huge.</p><p>Let me explain myself, at some point prospects convert into customers that are assigned to a sales representative. Thus, whenever they are presented with a call to action in one campaign, they can either :</p><ul><li>Convert and proceed in the marketing funnel that is going to redirect them into a queue hopefully leading to their sales representative.</li><li>Directly call their sales representative.</li></ul><p>In short, if you are using the lead identifier created whenever customers or prospects click on one of your campaigns call to action to evaluate marketing impact on sales, you are mostly evaluating your department’s capabilities to convert new prospects into customers.</p><h3><strong>Influenced Pipeline &amp; Revenue</strong></h3><p>Those are simple metrics based on a journey approach of the attribution problem, that aims to map the opportunities on which marketing can take credit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*9lE7fDGfx0cP90QYscKLPA.png" /><figcaption>A simple attribution model</figcaption></figure><p>The approach presented in the upper figure works well to a certain extend. If the customer churn and go purchase his furnitures to the competition and then decide to buy again at your business the following miss-attribution problem is going to happened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*Cf7loUs0eeYaLYcnegWdpw.png" /><figcaption>A simple representation of the attribution problem</figcaption></figure><p>In the upper figure you can clearly understand the problem we are dealing with: whenever there is pipeline generated after one or many interactions with your campaigns, you are going to attribute it to marketing effort even if it doesn’t make sense.</p><p>Every customer has his own buying frequency if you can approximate it, you know at a customer level if it makes sense to attribute the opportunity to the previous engagements with marketing.</p><h3><strong>Creating an influenced flag for your opportunities (in python)</strong></h3><h4>1. Import libraries</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/881b419b4f2a83be738a7b53a92e7156/href">https://medium.com/media/881b419b4f2a83be738a7b53a92e7156/href</a></iframe><h4><strong>2. Load</strong></h4><p>First, load all your closed opportunities from salesforce or any other B2B CRM. From those you only need three fields: the account id, the opportunity id, the end date (if you have a lot of NAs in this field you can replace them with the last modified date 😉).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27e54a9c427ff3283d34329a84906063/href">https://medium.com/media/27e54a9c427ff3283d34329a84906063/href</a></iframe><h4><strong>3. Computing buying frequencies</strong></h4><p>You can calculate buying frequencies by computing the time range between consecutive opportunities at an account level.</p><p>You should save apart every accounts’ first opportunities. We can say little of the customer at that time so we cannot know if the opportunity creation was influenced by marketing (well we can but not with this method rather using lead generation analysis), he may have interacted with marketing campaigns many times, with the intention of creating an opportunity, but ended up going to the competition before having a first opportunity created for him at your business. Depending on your focus we will see how to handle those later.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36871f02aae5b8834f6f537601c8512c/href">https://medium.com/media/36871f02aae5b8834f6f537601c8512c/href</a></iframe><p>Now from those time ranges, you can extrapolate some interesting behavior about your population buying behavior, using the <a href="https://towardsdatascience.com/the-5-clustering-algorithms-data-scientists-need-to-know-a36d136ef68">K-means algorithm</a>.</p><h4><strong>4. Finding the optimal number of clusters &amp; fitting the data</strong></h4><p>K-means algorithms are unsupervised models that form groups out of uni or multi-dimensional (structured) data. The core concept is that the groups are formed with respects to two rules:</p><ul><li>Each point distance to their cluster’s centroid is minimized.</li><li>The points’ distance to the other clusters’ centroids is maximized.</li></ul><p>To find out how many clusters you should form, you can compute the <a href="https://hlab.stanford.edu/brian/error_sum_of_squares.html">SSE</a> (Sum of Squared Errors =&gt; the distance of the points to their group mean) and/or the <a href="https://scikit-learn.org/stable/auto_examples/cluster/plot_kmeans_silhouette_analysis.html">Silhouette Score</a> for a range of a clusters’ numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b72bcfe219d50275c265ccf70239f62/href">https://medium.com/media/4b72bcfe219d50275c265ccf70239f62/href</a></iframe><p>Once you have found the optimal number of clusters, you can train the model make sure to run the fitting process several times and choose the version with the lowest SSE otherwise your algorithm may end up converging to a local optima. Once done you can predict the clusters of each one of the computed time ranges.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45a684952d7b4d088909f30f7b629d52/href">https://medium.com/media/45a684952d7b4d088909f30f7b629d52/href</a></iframe><p>In order to have meaning full values defining each cluster, we should rename those based on their mean value. Cluster ‘0’ should be the cluster containing the slower buying frequencies whereas cluster ‘k’ should be the one containing the fastest buying frequencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4a07467943b1e3cd186dca1c2a84b72/href">https://medium.com/media/e4a07467943b1e3cd186dca1c2a84b72/href</a></iframe><h4><strong>5. Flagging changes of buying frequency’s cluster at an account level</strong></h4><p>At an account level, a change to a slower buying frequency cluster between consecutive opportunities is a sign of a lapsing period.</p><p>For each account, you can easily flag lapsing period (aka change from a cluster to another cluster defined by a slower mean buying frequency between consecutive opportunities) on the first opportunity after the lapsing period.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*4LpMRwMKi3ZF36f-p6PxIQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa33c29f030b64bcb6a08dac0962acbc/href">https://medium.com/media/aa33c29f030b64bcb6a08dac0962acbc/href</a></iframe><h4><strong>6. Create a temporary set of fake data points to indicate missed conversion</strong></h4><p>In order to avoid the miss attribution problem presented you can create a set of fake records corresponding to missed opportunities using the informations that you have collected so far. To do so, you just need to select all the flagged opportunities and individually dividing their buying frequency by the cluster mean buying frequency of the last opportunity which will give you an <strong>APPROXIMATE</strong> number of missed opportunities during the lapsing period.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43582df5795af861c45bade815920bc7/href">https://medium.com/media/43582df5795af861c45bade815920bc7/href</a></iframe><p>For each flag opportunities iterate on the number of missed conversions adding at each time a new observation of missed conversion in the dataset at the previous opportunity date plus the mean buying frequency of its cluster times the iterator index. Attribute a unique opportunity id to all created missed opportunities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*u7qlVZWSJeLiAL0xQw3BIQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba3a0f8646b3e81c758a87fab1bce707/href">https://medium.com/media/ba3a0f8646b3e81c758a87fab1bce707/href</a></iframe><h4><strong>7. Handle account’s first opportunities</strong></h4><p>You can put back in the first opportunities of each account. Depending on the outcomes of the analysis you could also assume that you cannot understand any buying behavior prior to the second sales and leave them out of the analysis and use other metrics to evaluate marketing capabilities to convert new prospects. If you do so don’t forget to filter correctly your marketing dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ac388f5801ae84ee28c6019aa2bfa2a/href">https://medium.com/media/7ac388f5801ae84ee28c6019aa2bfa2a/href</a></iframe><h4><strong>8. Mapping an influenced flag to opportunities</strong></h4><p>Bring in marketing engagement data and stack it to the opportunities dataset. Sort the dataset by account and date and propagate the opportunity id backward at an account level.</p><p>Also, suppress missed opportunities and engagements between opportunities end date and their end date. Those are the engagements which could have introduced biased attribution as it has been presented in the figure <em>A simple representation of the attribution problem.</em></p><p>Group on the opportunity id, if you got a number of observations superior to 1 (then you have marketing interactions prior to the opportunities) you can attribute a flag “influenced” to the opportunity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc97d054283334b4fbb577c2c3a5566b/href">https://medium.com/media/cc97d054283334b4fbb577c2c3a5566b/href</a></iframe><p>Now for each opportunity, you have a flag that you can use to evaluate influenced pipeline &amp; revenue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*fWrBgsxEr5WCqA1DPF6bJQ.png" /></figure><p>You can find all the code presented in this article on my <a href="https://github.com/leopoldavezac/Mapping-Influenced-Opportunities">Github</a>.</p><h3>Final thoughts</h3><p>In the proposed implementation, I have used opportunities end dates assuming that the end date and the creation date are relatively close. While it may be true in some industries it is not the case for all. One solution if your opportunities end date and creation date are far from each other could be to use the end dates for all the process except for step 8 for which you could change end dates for creation dates in (real) opportunities.</p><p>If you find this interesting and you have some ideas to improve it please <a href="https://www.linkedin.com/in/leopolddavezac/">reach out</a>. There is always room for improvement.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a183510006" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-to-evaluate-marketing-in-the-b2b-retail-industry-5a183510006">How to evaluate marketing in the B2B industry?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>