<?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 Karthik Subramanian on Medium]]></title>
        <description><![CDATA[Stories by Karthik Subramanian on Medium]]></description>
        <link>https://medium.com/@karthiksdipa?source=rss-ebc0693a7cac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2C9SS1Qi4VKD4F0HFCUVxg.jpeg</url>
            <title>Stories by Karthik Subramanian on Medium</title>
            <link>https://medium.com/@karthiksdipa?source=rss-ebc0693a7cac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:23:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karthiksdipa/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[Efficiency Redefined: Linear Modeling Approach to Accelerate Attribution Analysis]]></title>
            <link>https://python.plainenglish.io/efficiency-redefined-linear-modeling-approach-to-accelerate-attribution-analysis-a92df3ea111d?source=rss-ebc0693a7cac------2</link>
            <guid isPermaLink="false">https://medium.com/p/a92df3ea111d</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[advanced-analytics]]></category>
            <category><![CDATA[attribution]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Karthik Subramanian]]></dc:creator>
            <pubDate>Wed, 28 Feb 2024 02:55:25 GMT</pubDate>
            <atom:updated>2024-03-11T03:18:06.758Z</atom:updated>
            <content:encoded><![CDATA[<h4>Faster insights, better decisions, and effortless attribution</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UfClg7xlLXelgHVz" /><figcaption>Photo by <a href="https://unsplash.com/@isaacmsmith?utm_source=medium&amp;utm_medium=referral">Isaac Smith</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>Background</strong></h3><p>Data analysts are often asked to explain what’s driving a drop in business productivity. This is not a simple question to answer especially when you are dealing with a complex system that involves several business factors that influence the top-line productivity metric. It’s often seen that analysts manually collect and aggregate this information comparing good and degraded periods to explain what changed and summarize them manually trying to stitch and tell a story. It’s a bigger problem when one has to do this repeatedly whenever there is a degradation in the top-line productivity metric.</p><h3>Concept</h3><p>To address this, a Python class was developed for analyzing and visualizing differences in productivity rate and its business drivers between the two periods, allowing for easy comparison and identification of allocation changes over time. This model accepts a date-time range for the 2 periods and an optional parameter to set the timezone to UTC.</p><h3>Linear Attribution Methodology</h3><p>In summary, the allocate() method performs a weighted average of the data from two periods, then calculates the allocation for each metric based on the differences in the data between the two periods. It essentially determines how much of the change in each metric is attributable to each period, providing insights into the shifts over time.</p><ul><li>Upon initialization, the class accepts data for the two periods and an optional parameter to specify the timezone. It converts the timestamps of the periods to pd.Timestamp objects and handles timezone conversions based on the provided information. The model creates an empty series object to store the allocation results and defines a <em>linear space (t)</em> for weighting the data between the two periods. The linear space <strong>t</strong> is created usingnp.linspace(0, 1, 200), which generates 200 evenly spaced points between 0 and 1. This <strong>t</strong> represents a range of weights that determine the contribution of each period&#39;s data to the final allocated value.</li><li>Using the generatedt, the method calculates a weighted average of data from both periods (period_1 and period_2). This is achieved by blending the data based on the weights assigned by t.</li><li>The weighted data X is calculated using the formula: <em>X</em>=(<em>Dataperiod</em>2​*<em>t</em>)+(<em>Dataperiod</em>1​*(1−<em>t</em>)). For each metric and each point in t, X calculates a weighted average of the corresponding data from both periods. When t is closer to 1, more weight is given to period_2 data, and when t is closer to 0, more weight is given to period_1 data.</li><li>For each metric defined in_metrics_mapper, the method calculates the mean value of the weighted data X. This mean value represents the weighted average value of the metric across both periods. The difference in data between period_2 and period_1 (stored in delta) is then multiplied by this mean value to obtain the allocation for that metric. This allocates the change in the metric between the two periods based on the weighted average of the data.</li></ul><p>By utilizing the linear space t to weight the data from both periods, the allocate() method effectively distributes the change in each metric between the two periods, providing insight into the contribution of each period to the overall change observed in the metrics.</p><h3>Visualizing the Output</h3><p>The show_waterfall_plot() method within the determined class is a visualization tool that presents a detailed comparison of productivity rates (the output metric) and allocation results between two specified periods. It utilizes matplotlib to generate a waterfall plot, which elegantly displays the distribution of changes in metrics across the periods. The plot consists of stacked bars representing the productivity rate for each period, along with the allocation results for various metrics. By stacking these bars and incorporating color coding, the plot illustrates the cumulative effect of metric changes, allowing users to visually identify the contributions of each period to the overall allocation. Additionally, the method includes annotations to denote the starting and ending productivity rates for each period, enhancing the interpretability of the plot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mk24U0ekDhZ8mDUkaCOn3w.png" /></figure><p>Overall, the show_waterfall_plot() method provides a clear and insightful visualization of temporal metric attribution, aiding in the analysis of trends and patterns over time.</p><h3>Python Code</h3><pre>class Diagnostic:<br>    def __init__(self, period_1, period_2, utc=True):<br>        self.timezone = &#39;UTC&#39;<br>        self.period_1 = period_1<br>        self.period_2 = period_2<br><br>        self.period_1[&#39;timezone&#39;] = &#39;UTC&#39;<br>        self.period_2[&#39;timezone&#39;] = &#39;UTC&#39;<br><br>        self.period_1[&#39;start_time&#39;] = pd.Timestamp(self.period_1[&#39;start_time&#39;])<br>        self.period_1[&#39;end_time&#39;] = pd.Timestamp(self.period_1[&#39;end_time&#39;])<br><br>        self.period_2[&#39;start_time&#39;] = pd.Timestamp(self.period_2[&#39;start_time&#39;])<br>        self.period_2[&#39;end_time&#39;] = pd.Timestamp(self.period_2[&#39;end_time&#39;])<br><br>        if not utc:<br>            self.timezone = query(_timezone_query.format(period_1[&#39;building&#39;], period_2[&#39;building&#39;]))<br>            self.period_1[&#39;timezone&#39;] = self.timezone.loc[<br>                self.timezone.building == self.period_1[&#39;building&#39;], &#39;timezone&#39;].values[0]<br><br>            self.period_2[&#39;timezone&#39;] = self.timezone.loc[<br>                self.timezone.building == self.period_2[&#39;building&#39;], &#39;timezone&#39;].values[0]<br><br>            self.period_1[&#39;start_time&#39;] = self.period_1[&#39;start_time&#39;] \<br>                .tz_localize(self.period_1[&#39;timezone&#39;]) \<br>                .tz_convert(&#39;UTC&#39;)<br><br>            self.period_1[&#39;end_time&#39;] = self.period_1[&#39;end_time&#39;] \<br>                .tz_localize(self.period_1[&#39;timezone&#39;]) \<br>                .tz_convert(&#39;UTC&#39;)<br><br>            self.period_2[&#39;start_time&#39;] = self.period_2[&#39;start_time&#39;] \<br>                .tz_localize(self.period_2[&#39;timezone&#39;]) \<br>                .tz_convert(&#39;UTC&#39;)<br><br>            self.period_2[&#39;end_time&#39;] = self.period_2[&#39;end_time&#39;] \<br>                .tz_localize(self.period_2[&#39;timezone&#39;]) \<br>                .tz_convert(&#39;UTC&#39;)<br><br>        self.get_data()<br>        self.allocate()<br><br>    def get_data(self):<br>        self.DFs = list()<br>        for p in (self.period_1, self.period_2):<br>            # execute a query to get the data  <br>            query_string = diagnostic_query.format(<br>                date1=p[&#39;start_time&#39;].strftime(&#39;%Y-%m-%d&#39;),<br>                date2=p[&#39;end_time&#39;].strftime(&#39;%Y-%m-%d&#39;),<br>                tz=self.timezone,<br>                **p)<br>            self.DFs.append(query(query_string))<br><br>    def allocate(self):<br>        allocation = pd.Series(index=_metrics_mapper.keys())<br>        # abritrary number set after experiments<br>        t = np.linspace(0, 1, 200).reshape(1, 200)<br>        delta = self.DFs[1] - self.DFs[0]<br>        X = (self.DFs[1].T.dot(t)).T + (self.DFs[0].T.dot(1-t)).T<br><br>        # print(X)<br>        for i in allocation.index:<br>            allocation[i] = np.mean(_metrics_mapper[i](X)) * delta.loc[0, i]<br><br>        self.allocation = allocation<br>        self.period_1_rate = self.DFs[0].loc[0, &#39;pick_rate&#39;]<br>        self.period_2_rate = self.DFs[1].loc[0, &#39;pick_rate&#39;]<br><br>        # return allocation<br><br>    def show_waterfall_plot(self):<br>        import matplotlib.pyplot as plt<br>        # ax = self.allocation.cumsum().plot(&#39;bar&#39;)<br>        rate1 = pd.Series(self.DFs[0][&#39;productivity_rate&#39;].values, index=[&#39;Period 1\nRate&#39;])<br>        rate2 = pd.Series(self.DFs[1][&#39;productivity_rate&#39;].values, index=[&#39;Period 2\nRate&#39;])<br><br>        s_plot = rate1.append(self.allocation.copy()).append(rate2)<br>        bottom = s_plot.copy()<br>        bottom[self.allocation.index] = self.allocation.cumsum().shift(1).fillna(0) + rate1.values[0]<br>        bottom[&#39;Period 1\nRate&#39;] = 0<br>        bottom[&#39;Period 2\nRate&#39;] = 0<br>        ax = s_plot.plot(&#39;bar&#39;, stacked=True, bottom=bottom)<br>        ax.plot(s_plot.index, s_plot+bottom, color=&#39;red&#39;)<br>        plt.tight_layout()<br>        plt.show()</pre><h3>About me</h3><blockquote><strong>Karthik Subramanian (</strong><a href="https://www.linkedin.com/in/karthik-subramanian-503bb515/"><strong>LinkedIn</strong></a><strong>)<br></strong>Experienced data professional with over a decade of experience in the field of data science &amp; analytics.</blockquote><p><a href="https://medium.com/@karthiksdipa/subscribe">Get an email whenever Karthik Subramanian publishes.</a></p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a><strong> | </strong><a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a><strong> | </strong><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a><strong> | </strong><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a><strong> | </strong><a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://stackademic.com/"><strong>Stackademic</strong></a><strong> | </strong><a href="https://cofeed.app/"><strong>CoFeed</strong></a><strong> | </strong><a href="https://venturemagazine.net/"><strong>Venture</strong></a><strong> | </strong><a href="https://blog.cubed.run/"><strong>Cubed</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a92df3ea111d" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/efficiency-redefined-linear-modeling-approach-to-accelerate-attribution-analysis-a92df3ea111d">Efficiency Redefined: Linear Modeling Approach to Accelerate Attribution Analysis</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>