<?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 Swanandiug on Medium]]></title>
        <description><![CDATA[Stories by Swanandiug on Medium]]></description>
        <link>https://medium.com/@swanandiug?source=rss-be9474ba11d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WESypiINm0IGVyOs</url>
            <title>Stories by Swanandiug on Medium</title>
            <link>https://medium.com/@swanandiug?source=rss-be9474ba11d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:17:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swanandiug/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[Black Box to XAI : A story of LIME, SHAP, GRAD- CAM and a curvy graph of ROC]]></title>
            <link>https://medium.com/@swanandiug/black-box-to-xai-a-story-of-lime-shap-grad-cam-and-a-curvy-graph-of-roc-2f2e33e40ed3?source=rss-be9474ba11d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f2e33e40ed3</guid>
            <category><![CDATA[model-training]]></category>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[shap]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Swanandiug]]></dc:creator>
            <pubDate>Sat, 10 Oct 2026 17:29:12 GMT</pubDate>
            <atom:updated>2026-10-10T17:29:12.849Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>David Heinemeier Hansson, the creator of the RAILS framework</strong>, alleged that Apple Pay allocated him <strong>20x higher credit than his wife</strong>, even though they had the <strong>same assets, returns statements</strong>. This led to New York’s Department of Financial Services (DFS) to launch an investigation into Goldman Sachs (issuing bank) over potential sexism.</blockquote><p>In such financial services there is a rise in potential dilemma, that is with the increase in use of deep neural network based decision making a substantial trade-off in the models prediction’s interpretability is observed. This is known as the Black Box problem. This arises due to high stake services in fintech using deep learning patterns to predict credit approval, financial frauds and transaction blocking. Thus there is a growing demand for models that are as highly accurate as Black Box while providing White Box like explanations. Thus XAI model tools like SHAP(MA XAI), LIME(MA XAI), GRAD-CAM(not model agnostic) which are post-hoc and attention mechanisms which is intrinsic (built in) in nature are introduced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*8CqxL6r2ZpfzupoKNdDXag.png" /><figcaption>XAI classifications explained using a flowchart</figcaption></figure><p><strong>Methods of xAI implementation tools:</strong></p><h3><strong>The SHAP method</strong></h3><p>SHAP or SHapley Additive exPlanations is a Post Hoc interpretability method. This means that it does not change or affect how the model makes predictions, it is applied upon an existing accurately fitted model. The derivations of SHAP values come from game theory. Model-Agnostics: We can apply SHAPley to any model theoretically be it XGBoost or CNN.</p><p>Working of Shapley values: The method takes in input data sets and predictions of the respective black-box model and uses game theory to distribute weightage also called as “Blame” for a prediction upon different data features.</p><p>There are two types of SHAP values computed for each instance. The average absolute value is the typical impact over the entire dataset, while absolute value represents importance irrespective of direction which can either be positive or negative. Based on the values, feature selection is done in decreasing order. Higher the SHAP value the more influence the parameter has on the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*ZqLnjOmYyRESxK7-BJFCQg.png" /><figcaption>SHAP model process explained</figcaption></figure><p>Code block explaination of SHAP:</p><p>Now lets understand SHAP using an implementation on any tree models such as (XGBoost, LightGBM, random forest). For non- tree models</p><pre>shap.Explainer(model, background)</pre><p>handles the same functions.</p><pre>import shap<br><br>explainer = shap.TreeExplainer(model)       # exact TreeSHAP for tree models<br>shap_values = explainer(X_test)             # one value per feature, per applicant<br><br>shap.plots.beeswarm(shap_values)            # global features<br>shap.plots.waterfall(shap_values[0])        # local features</pre><p>Limitations of SHAP:</p><ul><li>Computational Complexity: As the number of features the model is trained on the complexity of the SHAP values calculation increases.</li><li>Assumption of feature independence: If variables of features are collinear in nature, the blame or weight distribution might be inaccurate.</li><li>SHAP is not scalable on data which is not in tabular or structured format.</li></ul><p>This is where LIME can help us.</p><h3><strong>The LIME Method</strong></h3><p>LIME stands for Local Interpretable Model-agnostic Explanations in machine learning and artificial intelligence. It provides an explanation regarding the local model linearity with the model outcome. LIME is model-agnostic: it can explain any classifier. But the explanation reflects the model being explained, so the same data and features can give different explanations from different models.</p><p>LIME gives us the analysis by reflecting the behavior of the classifier parameter “around” the instance being predicted. But the generated explanation is usually useless unless a human can interpret it and can make sense of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*Op82Zd4QBLEyETomJOIlYQ.png" /><figcaption>flowchart simplification of LIME XAI</figcaption></figure><p><strong>Code block explanation of LIME:</strong></p><p>What Lime does:</p><p>it takes a single applicant, generates many slightly altered copies of them, and asks the black-box model to score each one. It then fits a small linear model to those scores, weighting copies closer to the original more heavily. The weights of that simple model are the explanations.</p><pre>from lime.lime_tabular import LimeTabularExplainer<br><br>explainer = LimeTabularExplainer(X_train, feature_names=features, mode=&quot;classification&quot;)<br>exp = explainer.explain_instance(X_test[0], model.predict_proba)<br>exp.as_pyplot_figure()</pre><p><strong>Robustness of SHAP and LIME</strong></p><p>To put robustness of the models to test we go ahead and change the input so subtly as to not change the prediction or just a small change in the predicted outcome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*HhEPmqPMAU_p93vj8pTfAA.png" /><figcaption>LIME and SHAP explanations for two simple binary classifiers: a linear SVM (top row) and a two-layer neural network (bottom). <a href="https://arxiv.org/abs/1806.08049">Reference: On the Robustness of Interpretability Methods</a></figcaption></figure><p>Both the models were tested upon a two dimensional synthetic dataset on a linear support vector machine. The input value takes two features 𝓍 and <em>y. </em>Multiple random points are taken, the green bar shows the importance assigned to feature x while the purple horizontal bar represents the importance assigned to feature y.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*eHfQumhv5wZwz0d2A29Lug.png" /></figure><p>The second figure shows inputs which are taken in a non-linear format. This is also used on a complex model i.e a neural network classifier. The explanations vary and are inconsistent across the figures.</p><p>Thus when the ML model is linear and simple, post-hoc techniques are highly stable whereas when the model is complex and non-linear in nature, LIME and SHAP are not stable but also frequently contradictory in nature.</p><p><strong>The GRAD-CAM Method</strong></p><p>One of the major drawbacks of LIME and SHAP methods used in fintech problems arises from the fact that both the methods explain model decisions using tabular statistics and structured data. While real world applications often require visual detection, for such situations data is fed into deep-learning models particularly CNNs or 1-D CNNs.</p><p>GRAD-CAM allows analysts to visualise the particular reason behind the risk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*Z0TQf-Y5-1rOywwnA-pEvg.png" /><figcaption>Comparison of models across technique used, strengths and limitations.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*KZRSE7fWhYwEsexrfBsGQg.png" /><figcaption>simplification of stepwise breakdown of implementing Grad-Cam</figcaption></figure><p><strong>Credit Risk Assessment</strong></p><p>The evaluation of a company’s credit risk depends on its<a href="https://www.sciencedirect.com/topics/mathematics/probability-theory"> </a>probability of default (PD), the probability that a company will fail to repay its financial loans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*4OyC4o5UauEP02_hqwsF7A.png" /></figure><p>Here Pn is the probability of default, parameter α is the intercept and β<em>t</em> is the <em>t</em>-th regression coefficient while Xnt is the dimensional vector of the t-th parameter.</p><p>Here the derived Pn is a continuous function ∈{0,1} but we require prediction in either a high or a low. Thus we employ γ ∈{0,1} which is either 0 or 1. 0 being no possibility of defaultion and 1 stating sure default on financial credit. γ is decided by the specific threshold τ ∈{0,1} which is specified for a particular model. This gives us the following plot of TP,TN,FP,FN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/1*XbAV8D3demJh18zEn8DVLw.png" /></figure><p>From this we can say that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*UltdPK7p5EVAAVyhQuUFuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*R5siIFXIV89tkqItnNFEnA.png" /></figure><p>These TPR &amp; FPR are then plotted as a graph giving us the Receiver Operating Curve and the area under this curve gives us the value ∈{0,1} where 1.0 signifies the perfect model, 0.5 shows that the model has no prediction powers and anything above 0.8 is considered an excellent model(usually).</p><p>Lets use an example to understand and break down the ROC and threshold situation better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*uvxulsqDWW25ZcAfkV2U8w.png" /><figcaption>( graph generated using lending dataset of 4000 applications, synthetic data )</figcaption></figure><p>The left panel plots the ROC curve computed from a synthetic scored lending dataset of 4,000 applications. The curve is threshold-independent and the area under it is <strong>AUC = 0.762</strong>. The diagonal dashed line is the chance line at AUC = 0.50.</p><p>The operating point marked in red is the threshold that maximises= TPR − FPR</p><p>The right figure is: plotting the score distributions for non-defaulters (grey) and defaulters (blue) with the decision cut at τ = 0.404. Everything above the line is approved, everything below is declined. The errors that the threshold choice creates: false positives on the right, false negatives on the left. Moving the line trades one against the other.</p><p><strong>Real-time fintech application of XAI</strong></p><p>So which tool is used when? No single tool is the explanation. SHAP speaks to the customer and the regulator, LIME to the analyst, Grad-CAM is used by the reviewer who works with images and signals.</p><p><strong>SHAP</strong> is the one who produces a score card. Shapley values split a single prediction into per-feature credits that add back up exactly using:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/176/1*8X4zo0aIKUsviCtLvtJ0OA.png" /></figure><p>To see this outside a textbook, here is how TreeSHAP runs inside RingBreaker(git hub and live demo added at the end) , a fraud-ring detection system I built that scores every peer-to-peer payment before the money moves. The pair model is an XGBoost classifier, and XGBoost ships an exact, tree-specific implementation of SHAP (TreeSHAP), so no external library is needed.</p><pre>dm = self._matrix([feats])<br>prob = float(self.booster.predict(dm)[0])<br>contribs = self.booster.predict(dm, pred_contribs=True)[0]<br>return prob, {n: float(c) for n, c in zip(PAIR_FEATURE_NAMES, contribs[:-1])}</pre><p>The model also reasons out the top features that are affecting the predicted example: your top three drivers were utilisation, delinquency count, and tenure. It’s also why model risk can average them into a global ranking and ask and check the most basic but important constraint: does this match economic common sense?</p><p>The fine print is that the credits depend on your baseline, that is, two analysts running SHAP on the same model and the same applicant can get different attributions if they used different background data, and neither is wrong.</p><p><strong>LIME</strong> is basically for the case-review. The company might want to know what the model did near this person or this specific instance. LIME perturbs the instance, weights the samples by proximity, and fits a small linear surrogate to the neighbourhood. It’s quick and readable,but still quite unstable with the smallest variation in the data. Thus the prediction is checked more than once.</p><p><strong>Grad-CAM</strong> is built for the vision layer: CNN or 1-D CNN stacks scoring document forgery, cheque images, or transaction-sequence tensors. Here the “reason” isn’t a feature or a column within the dataset, it’s a part of the image.</p><p>It weights the last convolutional feature maps by their averaged gradients and the output is a heatmap over a region of the cheque or a window in time.</p><h3>A readers take aways:</h3><ol><li><strong>Accuracy isn’t enough.</strong> In high-stakes finance, a model that can’t explain its decisions is a liability. The Apple Card case shows what happens when it can’t.</li><li><strong>XAI doesn’t change the model.</strong> SHAP, LIME and Grad-CAM are post-hoc. They leave the ROC curve and accuracy untouched and only explain the decisions.</li><li><strong>SHAP gives the exact accounting.</strong> It splits one prediction into per-feature credits that sum to the output: f(x) = φ₀ + Σφᵢ.</li><li><strong>LIME gives a quick local sketch.</strong> It’s good for case review, but it’s an approximation and can be unstable, so run it more than once.</li><li><strong>Grad-CAM is for images and signals.</strong> It highlights the region that drove the decision, such as a smudged signature on a cheque.</li><li><strong>No single tool is the explanation.</strong> Pick by audience: SHAP for the customer and regulator, LIME for the analyst, Grad-CAM for the visual reviewer.</li><li><strong>Every method has limits.</strong> SHAP is costly and depends on its baseline, LIME is unstable on complex models, and Grad-CAM is limited by resolution.</li></ol><h3>References:</h3><p><strong>On the Robustness of Interpretability Methods:</strong> https://arxiv.org/abs/1806.08049</p><p><strong>Explainable AI in Fintech Risk Management:</strong> <a href="https://www.frontiersin.org/journals/artificial-intelligence/articles/10.3389/frai.2020.00026/full">https://www.frontiersin.org/journals/artificial-intelligence/articles/10.3389/frai.2020.00026/full</a></p><p><strong>A Perspective on Explainable Artificial Intelligence Methods: SHAP and LIME:</strong><a href="https://advanced.onlinelibrary.wiley.com/doi/full/10.1002/aisy.202400304">https://advanced.onlinelibrary.wiley.com/doi/full/10.1002/aisy.202400304</a></p><p><strong>Explainable Deep Learning Models for Detecting Sophisticated Cyber-Enabled Financial Fraud Across Multi-Layered FinTech Infrastructure:</strong> <a href="https://www.researchgate.net/publication/392694078_Explainable_Deep_Learning_Models_for_Detecting_Sophisticated_Cyber-Enabled_Financial_Fraud_Across_Multi-Layered_FinTech_Infrastructure">https://www.researchgate.net/publication/392694078_Explainable_Deep_Learning_Models_for_Detecting_Sophisticated_Cyber-Enabled_Financial_Fraud_Across_Multi-Layered_FinTech_Infrastructure</a></p><p><strong>LIME vs. SHAP</strong>: <a href="https://medium.com/@afanta/lime-vs-shap-a92623e95c4">https://medium.com/@afanta/lime-vs-shap-a92623e95c4</a></p><h3><strong>For the Curious, </strong>Down the Rabbit Hole</h3><p><strong>The mathematics behind Shapley Values: </strong><a href="https://www.youtube.com/watch?v=UJeu29wq7d0&amp;t=440s">https://www.youtube.com/watch?v=UJeu29wq7d0&amp;t=440s</a></p><p><strong>SHAP values for beginners | What they mean and their applications: </strong><a href="https://youtu.be/MQ6fFDwjuco?si=OUXnoWbtCNtj9Ow0">https://youtu.be/MQ6fFDwjuco?si=OUXnoWbtCNtj9Ow0</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f2e33e40ed3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>