<?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 Ahlem Marzouk on Medium]]></title>
        <description><![CDATA[Stories by Ahlem Marzouk on Medium]]></description>
        <link>https://medium.com/@ahlemmarzouk?source=rss-265d18487325------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5kQVGLki8vCGrEp1y9R6PA.jpeg</url>
            <title>Stories by Ahlem Marzouk on Medium</title>
            <link>https://medium.com/@ahlemmarzouk?source=rss-265d18487325------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:30:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahlemmarzouk/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[Ad Hoc Models]]></title>
            <link>https://medium.com/@ahlemmarzouk/ad-hoc-models-f089dfafe5d1?source=rss-265d18487325------2</link>
            <guid isPermaLink="false">https://medium.com/p/f089dfafe5d1</guid>
            <category><![CDATA[ad-hoc-testing]]></category>
            <category><![CDATA[ad-hoc-reporting-tool]]></category>
            <category><![CDATA[ad-hoc]]></category>
            <category><![CDATA[ad-hoc-reporting]]></category>
            <category><![CDATA[ad-hoc-analysis]]></category>
            <dc:creator><![CDATA[Ahlem Marzouk]]></dc:creator>
            <pubDate>Mon, 14 Jul 2025 16:01:05 GMT</pubDate>
            <atom:updated>2025-07-14T16:47:53.071Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Ad Hoc</strong> models are models designed to respond to a specific problem or situation.</p><p>They are not general models that can be reused everywhere but they are customized to be adapted to a context or a specific business hypothesis.</p><p>They are used to :</p><ol><li>Incorporate specific business rules.</li><li>Test a business hypothesis quickly.</li><li>Improve performance by adding human insights.</li></ol><p>Key features:</p><ul><li>High Specificity: Designed by and for a unique context/data.</li><li>Pragmatism: Immediate usefulness over theoretical rigor and favors practical efficiency.</li><li>Low generalizability: It works very well for the situation for which it was created but its results cannot be general for any other situation or extended.</li><li>Simpler: Simpler than other general model, because it ignores variables that are irrelevant in the specific context.</li></ul><p>Types of Ad Hoc models:</p><ol><li>Diagnostic(or Explanatory) Ad Hoc Models.</li><li>Predictive Ad Hoc Models.</li><li>Decision Ad Hoc Models.</li></ol><h3>1. Diagnostic Ad Hoc Models:</h3><p>The diagnostic Ad Hoc Model is used to understand why <strong>something happened </strong>or <strong>explain relationships </strong>between variables.</p><h4>Use case: Business Problem</h4><p>The company has seen that more and more users are abandoning its platform (attrition/churn). In order to create successful retention methods, they wish to comprehend the primary motivators.</p><p><em>Goal: “Create an Ad Hoc model to understand why customers are leaving the platform”</em></p><ul><li>Let’s start first with the libraries we need in this article.</li></ul><pre>import numpy as np<br>import pandas as pd<br>import statsmodels.api as sm<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br>from sklearn.metrics import confusion_matrix, roc_curve, auc<br><br></pre><ul><li>We’ll create a synthetic dataset for demonstration.</li></ul><pre>#The data contains 1000 customers<br>np.random.seed(42)<br>n = 1000<br>data = pd.DataFrame({<br>    &#39;satisfaction&#39;: np.random.normal(loc=7.0, scale=2.0, size=n),<br>    &#39;usage&#39;: np.random.normal(loc=15.0, scale=5.0, size=n),<br>    &#39;complaints&#39;: np.random.poisson(lam=1.5, size=n),<br>})<br>data[&#39;satisfaction&#39;] = data[&#39;satisfaction&#39;].clip(0, 10)</pre><p>Output<strong>:</strong></p><pre>  satisfaction  usage        complaints<br>0  7.993428      21.996777    1<br>1  6.723471      19.623168    1<br>2  8.295377      15.298152    2<br>3  10.000000     11.765316    2<br>4  6.531693      18.491117    0</pre><p><em>satisfaction</em>: A numerical score (0–10) representing customer satisfaction based on surveys.</p><p>usage: The average number of hours the customer uses the platform per month.</p><p>complaints: The number of complaints the customer has made in the last 6 months.</p><ul><li>In order to forecast whether or not there will be in a churn, we will create the target variable.</li></ul><p><em>attrition</em>: The target variable is binary (1 = churned, 0 = stayed).</p><pre>log_odds = (-2.5 + <br>            -0.5 * data[&#39;satisfaction&#39;] + <br>            0.8 * data[&#39;complaints&#39;] + <br>            -0.05 * data[&#39;usage&#39;])<br><br>attrition_prob = 1 / (1 + np.exp(-log_odds))<br>data[&#39;attrition&#39;] = np.random.binomial(1, attrition_prob, size=n)</pre><p>the log_odds, a key component in logistic regression, is the algorithm of the odds of an event and it is represented as a linear combination of <em>satisfaction, complaints </em>and <em>usage.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*Y8Xw42T8RE9wtkEQyqV4zw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2gp11uxSMn4em9JmWkZug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*YLXxrRFNsZvCTDlt__esDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*MU0samoEWXH3bMTv2NhXKA.png" /></figure><p>output:</p><pre>  satisfaction  usage      complaints  attrition<br>0  7.993428      21.996777     1           0<br>1  6.723471      19.623168     1           0<br>2  8.295377      15.298152     2           0<br>3  10.046060     11.765316     2           0<br>4  6.531693      18.491117     0           0</pre><ul><li>We will use a Logistic Regression model to understand the factors leading to the churn since it provides probabilities and interpret-able coefficients and it’s suitable for binary outcomes.</li></ul><pre>X = data[[&#39;satisfaction&#39;, &#39;usage&#39;, &#39;complaints&#39;]]<br>X = sm.add_constant(X)  # add intercept<br>y = data[&#39;attrition&#39;]<br>model = sm.Logit(y, X).fit()<br>print(model.summary())</pre><p>output:</p><pre>Optimization terminated successfully.<br>         Current function value: 0.486076<br>         Iterations 6<br>                           Logit Regression Results                           <br>==============================================================================<br>Dep. Variable:              attrition   No. Observations:                 1000<br>Model:                          Logit   Df Residuals:                      996<br>Method:                           MLE   Df Model:                            3<br>Date:               We,14 August 2024   Pseudo R-squ.:                  0.1802<br>Time:                        17:20:11   Log-Likelihood:                -486.08<br>converged:                       True   LL-Null:                       -592.95<br>Covariance Type:            nonrobust   LLR p-value:                 4.496e-46<br>================================================================================<br>                   coef    std err          z      P&gt;|z|      [0.025      0.975]<br>--------------------------------------------------------------------------------<br>const            1.4759      0.407      3.630      0.000       0.679       2.273<br>satisfaction    -0.4066      0.046     -8.808      0.000      -0.497      -0.316<br>usage           -0.0592      0.016     -3.651      0.000      -0.091      -0.027<br>complaints       0.7399      0.071     10.411      0.000       0.601       0.879<br>================================================================================</pre><ul><li>Coefficients represent the change in log-odds of the outcome.</li><li>A negative coefficient decreases the likelihood of attrition.</li><li>A positive coefficient increases the likelihood of attrition</li></ul><pre>Variable       Coef      p-value  CI                   Interpretation<br>=============  ========  ======== ===============      ================<br>satisfaction   -0.4066   0        [-0.497 -0.316]      Statistically significant<br>                                                       More satisfaction =&gt; less attrition<br>Interpretation<br>==============<br>- More satisfaction =&gt; less attrition by almost 0.41.<br>- OR=0.666 =&gt; percentage= 1-0R =&gt; 33% decrease in odds of retrition.</pre><pre>Variable       Coef      p-value  CI                   Interpretation<br>=============  ========  ======== ===============      ================<br>usage          -0.0592   0        [-0.091 -0.027]      Statistically significant<br>                                                       More usage =&gt; less attrition<br>Interpretation<br>==============<br>- More usage=&gt; less probability of attrition by almost 0.06.<br>- OR=0.942 =&gt; percentage= 1-0R =&gt; 5.8% decrease in odds of retrition.</pre><pre>Variable       Coef      p-value  CI                   Interpretation<br>=============  ========  ======== ===============      ================<br>complaints     0.7399    0        [0.601 0.879]        Statistically significant<br>                                                       More complaints =&gt; more attrition<br>Interpretation<br>==============<br>- More complaints =&gt; strong probability of attrition by almost 0.74.<br>- OR=2.096 =&gt; percentage= 1-0R =&gt; 110% increases in odds of retrition.</pre><p>The results indicate that we need to focus on the customers’ satisfactions, encourage usage and resolve complaints.</p><p>Let’s visualize the variables effect on the attrition.</p><pre>plt.figure(figsize=(15, 10))<br><br>coefs = model.params.drop(&#39;const&#39;)<br>coefs.plot(kind=&#39;bar&#39;, color=[&#39;red&#39; if x &gt; 0 else &#39;green&#39; for x in coefs])<br>plt.title(&#39;Impact on Attrition Probability&#39;)<br>plt.ylabel(&#39;Log-Odds Coefficient&#39;)<br>plt.axhline(0, color=&#39;grey&#39;, linestyle=&#39;--&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*tWguxKd7RgHMoMGBiQa2jA.png" /></figure><pre>| Feature          | Effect Direction    | Strength               | Business Insight                          |<br>| ---------------- | ------------------- | ---------------------- | ----------------------------------------- |<br>| satisfaction     | Decreases attrition | Strong negative effect | Improve satisfaction to retain people     |<br>| usage            | Decreases attrition | Mild negative effect   | Encourage engagement and usage            |<br>| complaints       | Increases attrition | Strong positive effect | Resolve complaints quickly and thoroughly |</pre><pre>plt.figure(figsize=(15, 10))<br>sns.kdeplot(data=data, x=&#39;satisfaction&#39;, hue=&#39;attrition&#39;, common_norm=False, fill=True)<br>plt.title(&#39;Satisfaction vs Attrition&#39;)<br>plt.xlabel(&#39;Satisfaction Score&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HK1TPjuj69ihGf3sW8Ra2Q.png" /><figcaption>Satisfaction vs Attrition</figcaption></figure><ul><li>Curve Orange : The customers with satisfaction between 4 and 6 are the most leaving. Very few of them had high score of satisfaction (≥9).</li><li>Curve Blue: The customers with satisfaction ≥6 are the most staying. Very few of them had low satisfaction.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f089dfafe5d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>