<?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 ML and DL Explained on Medium]]></title>
        <description><![CDATA[Stories by ML and DL Explained on Medium]]></description>
        <link>https://medium.com/@ml_dl_explained?source=rss-1f24a83d4eaf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Pl7l416ZkF9MCE1ZqICuWg.png</url>
            <title>Stories by ML and DL Explained on Medium</title>
            <link>https://medium.com/@ml_dl_explained?source=rss-1f24a83d4eaf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:42:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ml_dl_explained/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[Some of the Most Interesting Papers to Watch from ICLR 2025]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@ml_dl_explained/some-of-the-most-interesting-papers-to-watch-from-iclr-2025-eb3b187b1c71?source=rss-1f24a83d4eaf------2"><img src="https://cdn-images-1.medium.com/max/814/1*C3FI9OV02ut5P5SbcSbXqQ.png" width="814"></a></p><p class="medium-feed-snippet">ICLR stands among the top-tier conferences like NeurIPS, ICML, ICCV, and CVPR. It will showcase many new and exciting papers across vision&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@ml_dl_explained/some-of-the-most-interesting-papers-to-watch-from-iclr-2025-eb3b187b1c71?source=rss-1f24a83d4eaf------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@ml_dl_explained/some-of-the-most-interesting-papers-to-watch-from-iclr-2025-eb3b187b1c71?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb3b187b1c71</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[iclr]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Sun, 20 Apr 2025 10:33:19 GMT</pubDate>
            <atom:updated>2025-04-20T10:33:19.965Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Understanding the Precision-Recall Curve (and Why It Matters)]]></title>
            <link>https://medium.com/@ml_dl_explained/understanding-the-precision-recall-curve-and-why-it-matters-72297cbdbd2b?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/72297cbdbd2b</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[precision]]></category>
            <category><![CDATA[class-imbalance]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[recall]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 14:07:17 GMT</pubDate>
            <atom:updated>2025-04-08T14:07:17.792Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*vhaAHJ_CmKgyrspIQUe1bA.png" /></figure><p>If you’ve ever found yourself confused about ROC curves, AUC, and how they compare to Precision-Recall curves — especially in imbalanced datasets — this post is for you.</p><p>In this guide, I’ll walk you through what ROC and Precision-Recall (PR) curves are, where each shines, and when one is better than the other. If you’re a visual learner, I also cover this in my <a href="https://www.youtube.com/watch?v=6s35p6lni-Y&amp;ab_channel=ML%26DLExplained">YouTube video</a>.</p><p>We’ll Cover</p><ol><li>Quick Recap: ROC Curve &amp; AUC</li><li>Limitations of ROC (Especially with Imbalanced Data)</li><li>The Precision-Recall Curve Explained</li><li>When and Why to Use PR Curves</li><li>Tools to Plot and Measure PR Curves in Python</li></ol><h3><strong>A Quick Refresher: ROC Curve &amp; AUC</strong></h3><p>The <strong>ROC curve</strong> (Receiver Operating Characteristic) is a graphical plot used to evaluate the performance of a classification model across different thresholds.</p><ul><li><strong>True Positive Rate</strong> (TPR), a.k.a. Recall, is on the Y-axis.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*g_EpgXq6foY7xv7pDOQ6vg.png" /></figure><ul><li><strong>False Positive Rate</strong> (FPR) is on the X-axis.</li></ul><p>Each point on the ROC curve corresponds to a different threshold applied to your model’s predicted probabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*hHgbQjNh0_Iq0oK51XFNcA.png" /></figure><p>We use <strong>AUC</strong> (Area Under the Curve) to summarize model performance:</p><ul><li>A model with higher AUC is generally better.</li><li>AUC allows you to compare models without committing to a specific threshold.</li></ul><h3>ROC Curve Limitations in Imbalanced Datasets</h3><p>ROC curves work well <strong>only</strong> when the dataset is relatively balanced. In real-world scenarios — especially in medical diagnosis — you often deal with <strong>class imbalance</strong>.</p><p>For example:<br>- A disease is present in 1 out of every 100 people.<br>- The negative class (healthy patients) dominates.</p><p>In such cases, FPR can be misleading, because: A small number of false positives over a <strong>very large</strong> negative class still yields a low FPR — even if the actual number of false alarms is high.</p><p>&gt; 📌 **Insert Snippet Here:** _Your verbal explanation about chemotherapy being a risky false positive — helpful for real-world context._</p><h3>Enter: Precision-Recall Curve</h3><p>To address this limitation, we switch to the <strong>Precision-Recall (PR) curve</strong>.</p><ul><li>Recall stays the same: TP / (TP + FN)</li><li>Precision is: TP / (TP + FP)</li></ul><p>In simpler terms: <br>Precision tells you how many of your <strong>predicted positives were actually correct</strong>.</p><p>This metric is <strong>not biased</strong> by the size of the negative class, which makes it more reliable for imbalanced datasets.</p><h3>Things to Keep in Mind with PR Curves</h3><ol><li>Precision drops as Recall increases — there’s usually a trade-off.</li><li>The baseline precision in a balanced dataset is 0.5. In an imbalanced dataset, it’s often much lower.</li><li>Axis switch:</li></ol><ul><li>ROC has Recall (TPR) on the Y-axis.</li><li>PR has Recall on the X-axis.</li></ul><p>How to Plot PR Curves in Python</p><p>Luckily, Python’s `sklearn` makes this easy:</p><pre>from sklearn.metrics import precision_recall_curve, average_precision_score<br><br>precision, recall, thresholds = precision_recall_curve(y_true, y_scores)<br>ap_score = average_precision_score(y_true, y_scores)</pre><h3>Final Thoughts</h3><ul><li>Use <strong>ROC</strong> curves when classes are balanced and <strong>you care about both FP and FN</strong>.</li><li>Use <strong>Precision-Recall</strong> curves when <strong>the positive class is rare</strong> and <strong>false positives are costly</strong>.</li></ul><p>Thanks for reading! If you found this helpful, <a href="#">check out the full video on YouTube</a>, like &amp; subscribe, and feel free to drop any questions in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72297cbdbd2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Evidence Lower Bound (ELBO) Loss in Variational Autoencoders]]></title>
            <link>https://medium.com/@ml_dl_explained/understanding-the-evidence-lower-bound-elbo-loss-in-variational-autoencoders-423fcf19d318?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/423fcf19d318</guid>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[variational-autoencoder]]></category>
            <category><![CDATA[evidence-lower-bound]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 12:54:20 GMT</pubDate>
            <atom:updated>2025-02-19T12:54:20.292Z</atom:updated>
            <content:encoded><![CDATA[<p>Variational Autoencoders (VAEs) are generative models that leverage probabilistic graphical models and deep learning to generate new data instances similar to a given dataset. A key component of training VAEs is the Evidence Lower Bound (ELBO) loss function, which enables efficient learning of the latent space. This article will explain the ELBO loss, its mathematical derivation, and why it plays a crucial role in VAEs.</p><p>This discussion follows a previous exploration of the <strong>reparameterization trick (</strong><a href="https://medium.com/@ml_dl_explained/understanding-the-reparameterization-trick-be349756b91b"><strong>post link</strong></a><strong>, </strong><a href="https://youtu.be/vy8q-WnHa9A"><strong>video link</strong></a><strong>)</strong>, which is necessary for efficient gradient-based optimization in VAEs. Here, we will focus on understanding the ELBO loss function — what it is, why we use it, and how it is derived.</p><h3>What is the ELBO Loss?</h3><p>The ELBO loss function is a critical part of training VAEs. It ensures that the latent space follows a structured distribution, enabling effective data reconstruction. The two main components of ELBO loss are:</p><ol><li><strong>Reconstruction Term</strong> — Ensures the decoded output is similar to the original input.</li><li><strong>Regularization Term (KL Divergence)</strong> — Encourages the latent distribution to be close to a prior distribution, usually a Gaussian.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7LQm5h5ZqY2RclIUKWVcSA.png" /></figure><h3>The Encoder-Decoder Architecture</h3><p>A VAE consists of two networks:</p><ul><li><strong>Encoder:</strong> Maps input data (e.g., an image) to a latent representation (denoted as ).</li><li><strong>Decoder:</strong> Maps the latent representation back to the original data space.</li></ul><p>Unlike standard autoencoders, VAEs introduce a probabilistic framework where is sampled from a Gaussian distribution rather than directly learned. This requires optimizing the ELBO loss function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NzVF0H3EqUJSMEcbwDbFIg.png" /></figure><h3>The Mathematical Perspective</h3><p>Given a dataset D, our goal is to maximize the likelihood of generating observed data X. This corresponds to maximizing the marginal likelihood (also called <strong>evidence</strong>) p(X). For numerical stability, we optimize its logarithm:</p><p>However, directly optimizing p(X) is intractable because it requires integrating over all possible latent variables :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*urzki43hRsQYK7fIFbmfNQ.png" /></figure><p>To address this, we introduce an <strong>approximate posterior distribution</strong> denoted as q(Z|X), leading to the derivation of the ELBO loss.</p><p>Below is a derivation of ELBO:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WX4w30h8Fz-_jYKNTMtDWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BYAkNeE2V9Ojjc5-zKdtVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C1k1gWUvCY2Rnpari1gxhw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cUgvYVk7XIQ5mjm656GLLg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPzDtTaa3svy_vUV5TjZww.png" /></figure><p>, leading to the derivation of the ELBO loss.</p><h3>The Two Components of ELBO</h3><h3>1. The Reconstruction Term</h3><p>This term measures how well the decoder reconstructs the input:</p><p>This expectation ensures that given a sampled latent variable , the likelihood of reconstructing is maximized.</p><h3>2. The KL Divergence Term</h3><p>The second component ensures that the approximate posterior stays close to a predefined prior , usually a standard normal distribution:</p><p>KL divergence measures the difference between two probability distributions. Since the true posterior is intractable, we use variational inference to approximate it.</p><h3>The Final ELBO Loss Function</h3><p>Combining these terms, the ELBO loss function is:</p><p>Maximizing ELBO corresponds to minimizing a combination of reconstruction error and divergence from the prior. This balance allows VAEs to generate meaningful latent representations.</p><h3>Conclusion</h3><p>The ELBO loss is at the heart of VAEs, ensuring both effective data reconstruction and structured latent space representation. By approximating the intractable posterior with a simpler distribution, VAEs enable practical training of generative models. Understanding the derivation and components of ELBO helps in designing and improving variational models.</p><p>For those interested in diving deeper, studying <strong>KL divergence</strong> and <strong>variational inference</strong> will provide additional insights into why ELBO works so effectively.</p><p>Also, please see my corresponding video on this topic</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FuvaLLN4e2Xg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DuvaLLN4e2Xg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FuvaLLN4e2Xg%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c154476172cc0ce86b1eac42ebfaa4f3/href">https://medium.com/media/c154476172cc0ce86b1eac42ebfaa4f3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=423fcf19d318" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singular Value Decomposition (SVD) vs. Eigen Decomposition: A Deep Dive]]></title>
            <link>https://medium.com/@ml_dl_explained/singular-value-decomposition-svd-vs-eigen-decomposition-a-deep-dive-6cc99463b45d?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cc99463b45d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Sun, 16 Feb 2025 15:53:00 GMT</pubDate>
            <atom:updated>2025-02-16T15:54:17.757Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Singular Value Decomposition (SVD) and Eigen Decomposition are two fundamental matrix factorization techniques used in linear algebra, data science, and machine learning. In this post, we will explore these methods, why they are important, and how they compare. This article serves as a deeper dive following my previous video on <a href="https://www.youtube.com/watch?v=zeXr5E8uMqo">Principal Component Analysis (PCA)</a>. If you haven’t watched it yet, I highly recommend checking it out first.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_AcfZh4Q2pw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_AcfZh4Q2pw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_AcfZh4Q2pw%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2416cfe0215eb0a4be6b172d9bec757/href">https://medium.com/media/e2416cfe0215eb0a4be6b172d9bec757/href</a></iframe><h3>What Are SVD and Eigen Decomposition?</h3><p>To understand these decomposition methods, let’s consider a data matrix A with n rows and m columns. Decomposition involves breaking down this matrix into several component matrices, revealing essential structure within the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s5BJgq8Lc0ckrNudKtkGCQ.png" /></figure><p>The main reason for decomposing a matrix is to identify its key building blocks, which help determine which components are more important. One practical example is image compression: by applying SVD, we can extract the most critical features of an image while discarding less significant ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zaO7ND-KZzTtTkOlfo6XJA.png" /></figure><p>In the example above, we remove low-ranked components from an image. The leftmost image is the original, while the subsequent images show reconstructions with progressively fewer components. This process demonstrates how SVD can capture essential structures within data.</p><h3>Eigen Decomposition and Eigenvalues</h3><p>Now, let’s focus on Eigen Decomposition. Consider a matrix A and a vector v. When we multiply A by v, the resulting vector is usually transformed in both magnitude and direction. However, for special vectors known as <strong>eigenvectors</strong>, the transformation only scales the vector without changing its direction. The scaling factor is called an <strong>eigenvalue</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BnbHPyozhKPsFNiq0QCkcw.png" /></figure><p>Mathematically, this relationship is expressed as: Av=λv where v is the eigenvector and λ is the corresponding eigenvalue. These eigenvectors are fundamental in understanding the intrinsic properties of a matrix.</p><h3>Mathematical Formulations</h3><p>The standard representations of these decomposition methods are as follows:</p><ul><li><strong>SVD</strong>: A= U Σ V^T</li><li><strong>Eigen Decomposition</strong>: A=QΛQ^−1</li></ul><p>where:</p><ul><li>U and V contain singular vectors,</li><li>Σ is a diagonal matrix of singular values,</li><li>Q contains eigenvectors,</li><li>Λ is a diagonal matrix of eigenvalues.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FF9lEL3TlBCLfQzJbXXDqQ.png" /></figure><p>One key distinction is that SVD can be applied to any rectangular matrix, while Eigen Decomposition is limited to square matrices.</p><h3>Key Differences Between SVD and Eigen Decomposition</h3><ol><li><strong>Applicability</strong>:</li></ol><ul><li>Eigen Decomposition applies only to <strong>square matrices</strong>.</li><li>SVD can be applied to <strong>any matrix</strong> (square or rectangular).</li></ul><ol><li><strong>Orthogonality</strong>:</li></ol><ul><li>Eigenvectors are not necessarily orthogonal.</li><li>Singular vectors from SVD are always <strong>orthogonal</strong>, making SVD preferable for data transformations.</li></ul><ol><li><strong>Value Range</strong>:</li></ol><ul><li>Eigenvalues can be <strong>negative</strong>.</li><li>Singular values are always <strong>non-negative</strong>.</li></ul><h3>When Do They Coincide?</h3><p>Under specific conditions, SVD and Eigen Decomposition yield identical results. If a matrix is <strong>square, symmetric, and positive semi-definite</strong>, then:</p><ul><li>The right singular vectors from SVD are the same as the eigenvectors of AA^T .</li><li>The squared singular values correspond to the eigenvalues of AA^T.</li></ul><p>This condition is particularly relevant in <strong>Principal Component Analysis (PCA)</strong>, where we use SVD to decompose the covariance matrix.</p><h3>Practical Considerations: When to Use Each Method</h3><ul><li><strong>SVD</strong> is generally preferred due to its <strong>numerical stability</strong> and broader applicability to non-square matrices.</li><li><strong>Eigen Decomposition</strong> is useful for <strong>faster computation</strong> in cases where a matrix is already square and symmetric.</li><li>For large exponentiation operations (e.g., computing AQA^Q), Eigen Decomposition is computationally efficient.</li></ul><p>Conclusion</p><p>Both SVD and Eigen Decomposition are powerful tools for understanding and manipulating data. SVD is more general and widely used, while Eigen Decomposition is efficient for specific cases. Understanding their differences and similarities helps in choosing the right method for various applications, including PCA, image compression, and machine learning.</p><p>Thank you for reading! If you found this post helpful, feel free to share it and check out my YouTube channel for more deep dives into machine learning concepts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cc99463b45d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Min-Max Loss Function in GANs]]></title>
            <link>https://medium.com/@ml_dl_explained/understanding-the-min-max-loss-function-in-gans-66203c989fc6?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/66203c989fc6</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Mon, 10 Feb 2025 04:44:34 GMT</pubDate>
            <atom:updated>2025-02-10T04:44:34.640Z</atom:updated>
            <content:encoded><![CDATA[<p>Generative Adversarial Networks (GANs) have revolutionized the field of deep learning by enabling models to generate highly realistic data. One key element that makes GANs work effectively is the <strong>Min-Max Loss Function</strong>. This post explains how this function operates and why it’s crucial for training GANs.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-UDvuBpcCXw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-UDvuBpcCXw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-UDvuBpcCXw%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/24453eca34754fb6d7d6a3951ae77f32/href">https://medium.com/media/24453eca34754fb6d7d6a3951ae77f32/href</a></iframe><h3>What Are GANs?</h3><p>GANs are composed of two competing neural networks:</p><ul><li><strong>Generator</strong>: Takes random noise as input and generates fake samples.</li><li><strong>Discriminator</strong>: Takes real and fake samples and determines whether each isreal or fake.</li></ul><p>These two components work against each other in a game-like competition, with the generator trying to fool the discriminator and the discriminator trying to classify real vs. fake data correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VrNULVBmQPNo8xKI2_roQA.png" /><figcaption>The Generator and Discriminator in a GAN, working in opposition to improve the quality of generated samples.</figcaption></figure><p>The Role of the Discriminator</p><p>The discriminator’s objective function is defined as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TGLiV2lnCVmBDLAMfR7hEg.png" /></figure><p>Here:</p><ul><li>D(x) is the probability that a real instance x is classified as real.</li><li>G(z) is the fake data generated from noise z.</li><li>The first term maximizes the probability of correctly classifying real data.</li><li>The second term minimizes the probability of classifying fake data as real.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*ZzgzqmnpmL4w1EJ3t8LP1Q.png" /><figcaption>The log function ensures that maximizing D(x) for real samples pushes its value towards 1.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*h7yKKblVqV-4_6-_tAG3_g.png" /><figcaption>The log function of (1−D(G(z))) ensures that the discriminator learns to classify fake data correctly.</figcaption></figure><h3>The Role of the Generator</h3><p>Unlike the discriminator, the generator aims to <strong>minimize</strong> the same function. The generator’s objective is to create samples that make D(G(z)) close to 1, meaning the discriminator gets fooled.</p><p>Thus, the generator tries to minimize:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*wVR1fDUhZL_hUaYdUVyDoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*-lAJPGsgpOy2sUQUjQyP2Q.png" /><figcaption>The generator learns to make the log 1 — D(G(z)) approach 1, ensuring fake samples appear real.</figcaption></figure><h3>The Min-Max Loss Function</h3><p>Ultimately, the adversarial nature of GANs creates a <strong>Min-Max Game</strong>, leading to the final loss function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y75k6SGObNDtNs5ssu0GyA.png" /></figure><p><strong>The discriminator tries to maximize</strong> this function by correctly classifying real and fake data.</p><ul><li><strong>The generator tries to minimize</strong> it by generating realistic samples that fool the discriminator.</li></ul><p>This dynamic results in a powerful system where the generator continually improves, producing increasingly realistic outputs.</p><h3>Conclusion</h3><p>The min-max loss function is the foundation of GAN training. It establishes a competitive framework that pushes the generator to create high-quality data while ensuring the discriminator remains sharp. Mastering this loss function is crucial for developing effective GAN models.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66203c989fc6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding 2D Convolutions in PyTorch]]></title>
            <link>https://medium.com/@ml_dl_explained/understanding-2d-convolutions-in-pytorch-b35841149f5f?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/b35841149f5f</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Sun, 09 Feb 2025 15:10:50 GMT</pubDate>
            <atom:updated>2025-02-09T15:10:50.880Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Convolutional Neural Networks (CNNs) have dramatically changed deep learning, particularly in computer vision. One of the fundamental building blocks of CNNs is the 2D convolution operation. This post will break down 2D convolutions and understand them through the torch.nn.Conv2d module in PyTorch. We will start with a simple example and progressively build our understanding by exploring different parameters controlling convolution operations.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fn8Mey4o8gLc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dn8Mey4o8gLc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fn8Mey4o8gLc%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3acd7b8bd60f47fb6338765928e8f24c/href">https://medium.com/media/3acd7b8bd60f47fb6338765928e8f24c/href</a></iframe><h3>What is a 2D Convolution?</h3><p>A 2D convolution is a mathematical operation where a small matrix (called a kernel or filter) slides over an input matrix (such as an image) to extract features. The operation consists of:</p><ol><li>Placing the kernel at a position on the input matrix.</li><li>Multiplying the corresponding elements of the kernel and the input.</li><li>Summing up the products to compute the output pixel value.</li><li>Sliding the kernel to the next position and repeating.</li></ol><p>This process results in a transformed output matrix, capturing patterns like edges, textures, and shapes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZW3eBaMrXminAKsGopogSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n61PdXmccEfhoSKPpkOKmw.png" /></figure><h3>Implementing 2D Convolution in PyTorch</h3><p>PyTorch provides the torch.nn.Conv2d module for performing 2D convolutions efficiently. Let&#39;s walk through its key parameters and see how they affect the convolution operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aWjxR7z-_3bJZwpMRYS6jw.png" /></figure><h3>1. Input and Output Channels</h3><p>CNNs often deal with multi-channel inputs (e.g., RGB images have 3 channels). When defining a convolution layer:</p><ul><li>in_channels: Number of input channels (e.g., 3 for RGB images).</li><li>out_channels: Number of output channels (filters applied to the input).</li></ul><p>Example:</p><pre>import torch<br>import torch.nn as nn</pre><pre>conv_layer = nn.Conv2d(in_channels=3, out_channels=2, kernel_size=3)</pre><p>This creates a convolution layer that takes a 3-channel input and produces 2 output feature maps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ktop8_Wr6EnDP3VQ_YdTpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aTXoLVLUJNBnfJXlhm6dZQ.png" /></figure><h3>2. Kernel Size</h3><p>The kernel_size parameter defines the size of the filter. A common choice is 3x3, but it can be any valid size like 5x5 or 7x7. A larger kernel captures more spatial features but reduces the output dimensions.</p><h3>3. Stride</h3><p>The stride parameter determines how far the kernel moves across the input. If stride=1, the kernel moves one pixel at a time. If stride=2, it moves two pixels at a time, reducing the output size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BBAdlm2iQF9Fo31nkpk3eg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0S-l0xmyI17f9Mu5M7p_gg.png" /></figure><p>Example:</p><pre>conv_layer = nn.Conv2d(in_channels=3, out_channels=2, kernel_size=3, stride=2)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oavnoZ8NdAnG_RGvHgi3Dw.png" /></figure><h3>4. Padding</h3><p>Padding is used to maintain the spatial dimensions of the output. If padding=1, an extra layer of zeros is added around the input, allowing the kernel to cover edge pixels.</p><p>Example:</p><pre>conv_layer = nn.Conv2d(in_channels=3, out_channels=2, kernel_size=3, padding=1)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KEsjr4yH6icqt9qDt86A1Q.png" /></figure><h3>5. Dilation</h3><p>Dilation controls the spacing between kernel elements. A dilation of 2 introduces gaps between kernel elements, increasing the receptive field.</p><p>Example:</p><pre>conv_layer = nn.Conv2d(in_channels=3, out_channels=2, kernel_size=3, dilation=2)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*56_uKjSiRhjwx6Pl-giyag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LFijS6W1V7-RVLsks9JrHQ.png" /></figure><h3>6. Groups</h3><p>The groups parameter determines how the input and output channels are divided. Setting groups=1 means a standard convolution where each input channel is connected to every output channel. Increasing groups reduces these connections and is used in depthwise and grouped convolutions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OuUwVC-aHYcFq39CKH1xig.png" /></figure><h3>7. Bias</h3><p>The bias parameter determines whether a learnable bias term is added to each output channel. By default, it is set to True.</p><h3>Computing Output Shape</h3><p>The formula to compute the output height and width is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pjwFMFGk4TiVunQEJQXe2A.png" /></figure><p>Example Calculation:</p><pre>import torch</pre><pre>input_tensor = torch.rand(1, 3, 32, 32)  # Batch size of 1, 3 channels, 32x32 image<br>conv_layer = nn.Conv2d(in_channels=3, out_channels=2, kernel_size=3, stride=1, padding=1)<br>output_tensor = conv_layer(input_tensor)<br>print(output_tensor.shape)  # Expected: torch.Size([1, 16, 32, 32])</pre><h3>Visualizing 2D Convolutions</h3><p>To better understand how convolution works, we can visualize the effect of applying a kernel to an image. The following code applies an edge-detection filter:</p><pre>import matplotlib.pyplot as plt<br>import torchvision.transforms as transforms<br>import torchvision.datasets as datasets</pre><pre># Load a sample image<br>data = datasets.MNIST(root=&quot;./data&quot;, train=False, download=True, transform=transforms.ToTensor())<br>image, _ = data[0]</pre><pre># Define an edge-detection kernel<br>edge_kernel = torch.tensor([[[[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]]], dtype=torch.float32)<br>conv_layer = nn.Conv2d(1, 1, kernel_size=3, padding=1, bias=False)<br>conv_layer.weight = torch.nn.Parameter(edge_kernel)</pre><pre>image = image.unsqueeze(0)  # Add batch dimension<br>output = conv_layer(image)</pre><pre>fig, ax = plt.subplots(1, 2)<br>ax[0].imshow(image.squeeze(), cmap=&#39;gray&#39;)<br>ax[0].set_title(&quot;Original Image&quot;)<br>ax[1].imshow(output.detach().squeeze(), cmap=&#39;gray&#39;)<br>ax[1].set_title(&quot;Edge Detection Output&quot;)<br>plt.show()</pre><h3>Conclusion</h3><p>This post covered the fundamentals of 2D convolutions and how to use PyTorch’s torch.nn.Conv2d module effectively. Understanding these concepts is essential for building CNNs for image processing tasks. Let me know in the comments if you have any questions or if you’d like me to cover another topic!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b35841149f5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Canonical Correlation Analysis (CCA): A Dimensionality Reduction Technique for…]]></title>
            <link>https://medium.com/@ml_dl_explained/understanding-canonical-correlation-analysis-cca-a-dimensionality-reduction-technique-for-9b46b731c8b9?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b46b731c8b9</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[multiview]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 05:16:08 GMT</pubDate>
            <atom:updated>2025-02-04T05:16:08.354Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Canonical Correlation Analysis (CCA): A Dimensionality Reduction Technique for Multiview Data</h3><p>In this post, I’ll walk you through the concepts behind Canonical Correlation Analysis (CCA) and demonstrate its application with Python code. If you enjoyed my YouTube video on CCA, this blog post will provide a deeper dive into the theory, math, and practical implementation.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXQzKG511fNc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXQzKG511fNc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXQzKG511fNc%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4286b0d2040e426974e243d63580c90f/href">https://medium.com/media/4286b0d2040e426974e243d63580c90f/href</a></iframe><p>Note: Before diving in, I suggest watching my earlier videos on <a href="https://www.youtube.com/watch?v=zeXr5E8uMqo&amp;ab_channel=ML%26DLExplained">Principal Component Analysis (PCA)</a> and <a href="https://www.youtube.com/watch?v=_AcfZh4Q2pw&amp;ab_channel=ML%26DLExplained">Singular Value Decomposition (SVD)</a>, which lay a solid foundation for grasping CCA.</p><h3>What Is Multiview Data?</h3><p>Multiview data arises when a phenomenon is sampled from different sources or modalities. Consider these examples:</p><ul><li><strong>Soccer Game:</strong> Two cameras capturing different angles of the same player.</li><li><strong>Image and Caption:</strong> An image paired with a descriptive text.</li><li><strong>Medical Tests:</strong> Different diagnostic tests performed on the same patient.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*Iyoijzx3WOnhTCSeB8L8iw.png" /></figure><p>This multi-perspective approach provides richer information for tasks like decision-making, as each view can compensate for potential noise or biases in the other.</p><h3>Why Do We Need CCA?</h3><p>Using multiple data views offers benefits but also introduces challenges:</p><ul><li><strong>Noise:</strong> One view might be noisier than the other.</li><li><strong>Different Dimensions:</strong> Different views may have varying dimensionalities, leading to issues like overfitting or bias toward one view.</li></ul><p>CCA addresses these problems by:</p><ul><li><strong>Reducing dimensions:</strong> It projects data into a lower-dimensional space.</li><li><strong>Maximizing correlation:</strong> It finds the best linear combinations (projections) so that the transformed data from each view is maximally correlated.</li></ul><p>This makes CCA especially useful for downstream tasks like clustering or classification, where combining multiple views improves performance.</p><h3>The Mathematics of CCA</h3><p>Let’s dive into the theory a bit. Assume you have two data views, <strong>X</strong> and <strong>Y</strong>, with nnn samples, where:</p><ul><li><strong>X</strong> has <em>p</em> features.</li><li><strong>Y</strong> has <em>q</em> features.</li></ul><p>CCA finds two projection vectors, <strong>a</strong> and <strong>b</strong>, such that:</p><ul><li>The linear combinations of <strong>X </strong>and <strong>Y</strong> are maximally correlated.</li><li>The correlation is measured by the Greek letter <em>ρ</em>.</li></ul><p>The process involves:</p><ul><li>Calculating the <strong>cross-covariance matrix</strong> between <strong>X</strong> and <strong>Y</strong>.</li><li>Solving an optimization problem with normalization constraints (forcing the projections to be unit vectors).</li><li>Using eigen (or singular value) decomposition to extract the projection vectors that maximize correlation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j_0-HgmvnItud1deCIH-2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8soRQWmOCVV81weO3aC1kQ.png" /></figure><p>This formulation is analogous to PCA, where we seek to maximize variance; however, in CCA, the goal is to maximize the correlation between two data sets.</p><h3>CCA in Python: A Code Demonstration</h3><p>Now let’s see how to apply CCA using Python. In the following sections, I’ll use the California Housing dataset as an example. (Note that the dataset is originally single-view, so we will create synthetic views by splitting the features.)</p><pre>import numpy as np<br>import pandas as pd<br>import matplotlib.pyplot as plt<br>from sklearn.datasets import fetch_california_housing<br>from sklearn.cross_decomposition import CCA<br>from sklearn.preprocessing import StandardScaler<br><br>data = fetch_california_housing(as_frame=True)<br>df = data.frame<br><br>print(df.shape)</pre><p>(20640, 9)</p><h3>Step 2: Exploratory Data Analysis (EDA)</h3><pre>print(df.describe())<br><br>corr_matrix = df.corr()<br>plt.figure(figsize=(8,6))<br>plt.imshow(corr_matrix, cmap=&#39;coolwarm&#39;, interpolation=&#39;none&#39;)<br>plt.colorbar()<br>plt.title(&quot;Feature Correlation Matrix&quot;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*K6MsYJ3Yx__SreKtynVt6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*VCb4Ri3Z1zY8D8KOfhu-9Q.png" /></figure><h3>Step 3: Creating Synthetic Views</h3><p>Since the California Housing dataset is single-view, we split the features into two groups to simulate two different views.</p><pre>view1 = df.iloc[:, :5]<br>view2 = df.iloc[:, 5:]<br><br>scaler1 = StandardScaler()<br>scaler2 = StandardScaler()<br><br>view1_scaled = scaler1.fit_transform(view1)<br>view2_scaled = scaler2.fit_transform(view2)</pre><h3>Step 4: Applying CCA</h3><p>Now we apply CCA from scikit-learn. We’ll work on a sample of the data (say, the first 500 samples) to reduce computation time.</p><pre>n_samples = 500<br>view1_sample = view1_scaled[:n_samples]<br>view2_sample = view2_scaled[:n_samples]<br><br>n_components = 2  <br>cca = CCA(n_components=n_components)<br>view1_c, view2_c = cca.fit_transform(view1_sample, view2_sample)<br><br>correlation = np.corrcoef(view1_c[:, 0], view2_c[:, 0])[0, 1]<br>print(f&quot;Correlation between first canonical variables: {correlation:.2f}&quot;)</pre><p>Correlation between first canonical variables: 0.82</p><h3>Step 5: Visualizing the Canonical Components</h3><pre>plt.figure(figsize=(8,6))<br>plt.scatter(view1_c[:, 0], view2_c[:, 0], alpha=0.7)<br>plt.xlabel(&quot;Canonical Variable 1 (View 1)&quot;)<br>plt.ylabel(&quot;Canonical Variable 1 (View 2)&quot;)<br>plt.title(&quot;Scatter Plot of the First Canonical Variables&quot;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*9QusG_tq1wAAsCP0QZeF_Q.png" /></figure><h3>Wrapping Up and Next Steps</h3><p>CCA not only provides a way to reduce the dimensionality of multiview data but also helps to fuse different data sources by maximizing their shared information. After obtaining the canonical variables, you can further:</p><ul><li><strong>Concatenate the projected views:</strong> This can be used for downstream tasks such as clustering or classification.</li><li><strong>Explore additional canonical pairs:</strong> Beyond the first canonical variables, additional pairs can be analyzed for deeper insights.</li></ul><p>I hope this post helped demystify CCA and demonstrated its practical utility with a hands-on Python example. If you found this content useful, please consider liking, commenting, and sharing this post.</p><p>Happy coding and data exploring!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b46b731c8b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Label-Free Concept Bottleneck Models (ICLR 2023): A New Paradigm for Explainable AI]]></title>
            <link>https://medium.com/@ml_dl_explained/label-free-concept-bottleneck-models-iclr-2023-a-new-paradigm-for-explainable-ai-222336762fc7?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/222336762fc7</guid>
            <category><![CDATA[iclr]]></category>
            <category><![CDATA[explainable-ai]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Fri, 31 Jan 2025 07:39:07 GMT</pubDate>
            <atom:updated>2025-01-31T07:39:07.341Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YOPg8sK0ZdfDCK8z" /></figure><p>As machine learning systems become increasingly complex, understanding their decision-making processes remains a significant challenge. While powerful, the black-box model lacks interpretability, making diagnosing errors difficult, ensuring fairness, and building trust with end users. Concept Bottleneck Models (CBMs) have emerged as a promising solution by introducing human-understandable concepts as intermediaries between input data and predictions. However, existing CBMs require labeled concept annotations, which can be expensive and impractical to obtain at scale.</p><p>A recent paper introduces <a href="https://arxiv.org/abs/2304.06129"><strong>Label-Free Concept Bottleneck Models (LF-CBMs)</strong></a>, eliminating the need for manually labeled concepts. Instead, these models automatically discover and utilize meaningful concepts from the data itself, improving interpretability without requiring additional annotation costs.</p><h3>Why do Concepts Matter?</h3><p>Concepts serve as structured, interpretable units that bridge the gap between raw data and model predictions. For example, in medical diagnosis, concepts such as “irregular heartbeat” or “lesion size” provide understandable insights into why a model classifies an X-ray as indicative of disease. By incorporating concepts, models become more transparent and allow human experts to intervene, debug, and refine decision-making processes.</p><p>CBMs traditionally rely on human-labeled concepts, but this approach is often infeasible for large-scale datasets where labeling is expensive, ambiguous, or domain-specific. LF-CBMs address this limitation by learning concepts directly from data, making concept-based reasoning more accessible and scalable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*6T2XcdZS8KApkZTlZ0k-Yw.png" /></figure><h3>The Contribution of LF-CBMs</h3><p>The key contribution of the <strong>Label-Free Concept Bottleneck Model</strong> is its ability to learn concepts without requiring labeled annotations. This is achieved by leveraging unsupervised or self-supervised techniques to extract meaningful features that serve as proxy concepts. These concepts then act as interpretable variables in the model’s decision-making pipeline, maintaining the transparency benefits of CBMs while eliminating costly manual annotation efforts.</p><p>This approach offers several advantages:</p><ol><li><strong>Scalability</strong>: No need for large-scale concept annotations.</li><li><strong>Adaptability</strong>: Works across different domains without predefined concepts.</li><li><strong>Interpretability</strong>: Still provides human-understandable reasoning behind decisions.</li><li><strong>Robustness</strong>: Can reduce reliance on spurious correlations in datasets.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*XgPwrFNJz72AbdUJXudsbw.png" /></figure><h3>How are Concepts Generated?</h3><p>While other methods rely on domain experts to decide which concepts best describe the sample images, the LF-CBM paper automates the entire process of generating CBM to reduce reliance on domain experts.</p><p>For each of the image dataset’s <em>class </em>they ask GPT3 (OpenAI) the following:</p><ul><li>List the most important features for recognizing something as a {<em>class</em>}:</li><li>List the things most commonly seen around a {<em>class</em>}: •</li><li>Give superclasses for the word {<em>class</em>}:</li></ul><p>They also note that, surprisingly, GPT3 has a good amount of domain knowledge, which means that it gives a good set of concepts that are important for detecting each <em>class </em>when prompted correctly.</p><h3>Concept Set Filtering</h3><p>Next, they apply the following filters to refine the concept set and improve both quality and efficiency:</p><ol><li><strong>Concept Length:</strong> Remove concepts exceeding 30 characters to keep them concise and interpretable.</li><li><strong>Similarity to Output Classes:</strong> To prevent redundancy, concepts too similar to target class names are eliminated. The similarityis measured using an ensemble of CLIP ViT-B/16 and all-mpnet-base-v2 text encoders, removing concepts with similarity &gt; 0.85.</li><li><strong>Similarity to Other Concepts:</strong> To avoid redundancy, concepts with &gt; 0.9 cosine similarity to any other concept in the set are eliminated.</li><li><strong>Relevance in Training Data:</strong> Concepts that do not activate highly in CLIP are removed using a dataset-specific threshold based on average top-5 activation.</li><li><strong>Uninterpretable Projections:</strong> Neurons that do not produce interpretable activations in the Concept Bottleneck Layer (CBL) are filtered out.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*Ro4RWZWCzhkuPxECrghg5Q.png" /><figcaption><strong>CLIP (Contrastive Language-Image Pretraining)</strong></figcaption></figure><h3>Learning the Concept Bottleneck Layer (CBL)</h3><p>Once the concept set is finalized, they learn a projection from the backbone model’s (like Resnet50) feature space into a space where axes correspond to interpretable concepts. This is achieved using CLIP-Dissect without labeled concept data. The backbone model is denoted as <em>f</em>,</p><h4>Projection Learning:</h4><ul><li>Given a concept set <em>C</em> and training dataset <em>D:</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*NJSQ7hi1_fICR_XSf0puVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/205/1*Syh2WaCRPiptiVjxU-Dwbg.png" /></figure><ul><li>CLIP computes the activation matrix <em>P</em>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*dHA6czL3lPc-i3v12sCvzA.png" /></figure><ul><li>Where:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/127/1*-IIefNUD0rw_YWwo2fasPw.png" /></figure><ul><li>Being CLIP’s image and text encoders, respectively.</li><li>The projection weights:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/46/1*-xXn5cOmZlfl24gCcPLNxQ.png" /></figure><ul><li>Are initialized as a random matrix of shape:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/93/1*t5kemkQ7rPsCnfVtduU5ww.png" /></figure><ul><li>Where:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/37/1*TcqOvjUx8qv8mZMl6PydXQ.png" /></figure><ul><li>Is the backbone feature dimension</li><li>The concept activation function is defined as:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*EBrOtojdW3zTIzDWJRtRjQ.png" /></figure><ul><li>where each neuron <em>k</em> in the projection layer has an activation pattern:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*S03pw0N_z4AFBuqmIkB04w.png" /></figure><ul><li>With:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*O4p-Oy4cJBFG8Z9rLcz-sQ.png" /></figure><h4>Optimization:</h4><p>The projected neurons are enforced to activate in correlation with target concepts by optimizing the projection weights to maximize CLIP-Dissect similarity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*7wcGkX8MGEuQyJKTtsmxHA.png" /></figure><p>Where is the mean-normalized activation vector, and <strong>cos cubed similarity</strong> (raising each element to the third power) enhances sensitivity to highly activating inputs. They optimize using Adam with early stopping. Post-training, discard concepts with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*0bwMhLwaaZ2Y_DhtE3oUHA.png" /></figure><p>Updating the projection weights accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*ThGkTNoc6hRHYlNHQNYRwQ.png" /></figure><h3>Learning the Sparse Final Layer</h3><p>With the CBL trained, they learn the final predictor using a sparse, fully connected layer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*PmslYmpHTSewvqTspXfWGQ.png" /></figure><p>where</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/1*7WCB2zYKvQ3s2aIOYK8Ueg.png" /></figure><p>is the number of output classes. Sparse layers improve interpretability, so they optimize using an elastic net objective:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*nxNDJXbM_BE0-ZH6d4QNhA.png" /></figure><p>Where</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*35TB8SPpQf6m_LW4fvbcgQ.png" /></figure><p>balances Frobenius and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/34/1*iUeCDW_uVID47U2WfzhK6Q.png" /></figure><p>norms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/37/1*uqAz1BsVNV4X4obcPeAIxQ.png" /></figure><p>is the bias,</p><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/46/1*v3nolos0nQK5SBWjmRP_SQ.png" /></figure><p>is cross-entropy loss.</p><h3>The LF-CBM Workflow: From Image to Prediction</h3><p>Let’s walk through the pipeline of an LF-CBM using an example:</p><ol><li><strong>Input Image</strong>: Suppose we have an image of a bird, and we want to classify its species.</li><li><strong>Concept Extraction</strong>: Instead of manually labeling concepts (e.g., “beak shape,” “feather color”), the model automatically learns these meaningful attributes from data using self-supervised learning.</li><li><strong>Concept Bottleneck Layer</strong>: The extracted concepts are passed through an intermediate layer where they act as structured inputs for the final prediction model.</li><li><strong>Prediction</strong>: Using the learned concepts, the model classifies the bird species.</li><li><strong>Interpretability</strong>: The model can explain its decision by referencing concepts (e.g., “The bird is classified as a finch because it has a small, conical beak and a round body”).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*zGIxrsw3i__wHRMuitv75A.png" /></figure><h3>Real-World Applications</h3><p>LF-CBMs are particularly useful in scenarios where interpretability and scalability are critical:</p><ul><li><strong>Healthcare</strong>: Automating disease diagnosis while providing explanations (e.g., “This X-ray suggests pneumonia due to patterns in lung opacity”).</li><li><strong>Autonomous Vehicles</strong>: Understanding why a self-driving car makes certain decisions (e.g., “The vehicle slowed down due to recognizing a pedestrian crossing”).</li><li><strong>Fairness &amp; Bias Detection</strong>: Identifying whether a model relies on undesirable attributes (e.g., “The hiring model gives undue weight to age-related features”).</li><li><strong>Scientific Discovery</strong>: Helping researchers analyze large datasets by surfacing interpretable patterns.</li></ul><h3>Conclusion</h3><p>Label-free concept Bottleneck Models (LF-CBMs) mark a significant step toward making AI systems more interpretable and accessible without the burden of concept annotation. By learning concepts directly from data, LF-CBMs maintain the benefits of CBMs while removing a significant scalability bottleneck. This paves the way for broader adoption of concept-based AI, bringing us closer to models that are not only accurate but also understandable and trustworthy.</p><p>Integrating LF-CBMs into real-world applications will be key to ensuring AI systems align with human values and decision-making needs as we move forward. The future of interpretable AI is here — label-free, concept-driven, and scalable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=222336762fc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Prepare for Data Science and Machine Learning Interviews]]></title>
            <link>https://medium.com/@ml_dl_explained/how-to-prepare-for-data-science-and-machine-learning-interviews-c211ea81ddde?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/c211ea81ddde</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Thu, 30 Jan 2025 13:42:46 GMT</pubDate>
            <atom:updated>2025-01-30T13:42:46.912Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Landing a job in data science or machine learning requires more than just technical knowledge. The interview process is rigorous, covering everything from algorithmic coding to deep theoretical concepts, and even behavioral skills. In this post, we’ll cover essential guidelines to help you prepare effectively and improve your chances of success.</blockquote><h3>1. Master Algorithmic Coding (Even If It’s Not the Core Work)</h3><p>While data science is not primarily about solving LeetCode-style problems, many companies still include these in their interview process. Practicing coding questions on platforms like LeetCode, CodeSignal, and HackerRank can give you a competitive edge.</p><h3>2. Apply Through Referrals, Not Just Online Applications</h3><p>Many applications submitted online get automatically filtered out by Applicant Tracking Systems (ATS). A much better approach is to connect with someone working at the company via LinkedIn and request a referral. This can significantly increase your chances of getting an interview.</p><h3>3. Research Each Company’s Interview Process</h3><p>Different companies have different hiring processes. Some emphasize theoretical questions, while others focus on practical case studies. Before your interview:</p><ul><li>Search for previous interview experiences on platforms like Glassdoor or Blind.</li><li>Understand what topics the company typically tests (e.g., statistics, machine learning, coding, or business case studies).</li><li>Look at the job description carefully and tailor your preparation accordingly.</li></ul><h3>4. Confidence Is Key — But Don’t Overdo It</h3><p>Confidence can make a big difference in interviews. Speak clearly, explain your thought process, and don’t be afraid to ask clarifying questions. However, overconfidence can be a red flag — stay humble and acknowledge areas where you may need improvement.</p><h3>5. Build a Strong Portfolio</h3><p>Having a portfolio of projects can set you apart from other candidates. A well-documented GitHub repository and a Medium blog showcasing your work demonstrate hands-on experience. Your portfolio should include:</p><ul><li>End-to-end machine learning projects</li><li>Data visualization dashboards</li><li>Contributions to open-source projects</li><li>Blog posts explaining complex concepts in simple terms</li></ul><h3>6. Stay Updated on the Latest Advancements</h3><p>Data science and machine learning evolve rapidly. Keep up with:</p><ul><li>The latest state-of-the-art models (e.g., generative AI, transformers, diffusion models)</li><li>Breakthrough research papers (Google Scholar, arXiv, Twitter, or newsletters)</li><li>Trending tools and frameworks (e.g., PyTorch, TensorFlow, LangChain, etc.)</li></ul><h3>7. Know the Basic Formulas</h3><p>Even if you don’t have to derive formulas from scratch, understanding fundamental evaluation metrics is crucial. Be comfortable explaining:</p><ul><li>Accuracy = (TP + TN) / (TP + TN + FP + FN)</li><li>Precision = TP / (TP + FP)</li><li>Recall = TP / (TP + FN)</li><li>F1 Score = 2 * (Precision * Recall) / (Precision + Recall)</li></ul><p>See my video on this topic for more:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F4i4C3ejTdgs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D4i4C3ejTdgs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F4i4C3ejTdgs%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e69c7f102f3bdc4a4e14b50f508cb3f/href">https://medium.com/media/2e69c7f102f3bdc4a4e14b50f508cb3f/href</a></iframe><h3>8. Warm Up with Smaller Companies Before Applying to Big Tech</h3><p>If your goal is to land a job at a big tech company (Google, Meta, Amazon, etc.), consider applying to smaller companies first. This allows you to gain interview experience, refine your answers, and build confidence before tackling more competitive interviews.</p><h3>9. Be Pleasant and Joyful</h3><p>Interviews aren’t just about technical skills; interviewers assess whether they’d enjoy working with you. Show enthusiasm, maintain positive energy, and engage in friendly conversation. However, avoid excessive smiling — it should feel natural, not forced.</p><h3>10. Take Care of Basic Hygiene</h3><p>First impressions matter. Ensure you are well-groomed, dress appropriately for the interview, and pay attention to small details like clean fingernails and fresh breath. These minor aspects contribute to an overall professional image.</p><h3>11. Don’t Fear Failure — It’s Part of Growth</h3><p>Not every interview will go perfectly, and that’s okay. Learn from each experience and keep improving. As Thomas Edison said:</p><blockquote>“I have not failed. I’ve just found 10,000 ways that won’t work.”</blockquote><p>Every rejection brings you closer to success.</p><h3>Conclusion</h3><p>Preparing for data science and machine learning interviews is a marathon, not a sprint. By mastering coding, building a strong portfolio, staying updated, and approaching interviews with confidence and professionalism, you can maximize your chances of success. Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c211ea81ddde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning Interview Question: Model Performance on a New Dataset]]></title>
            <link>https://medium.com/@ml_dl_explained/machine-learning-interview-question-model-performance-on-a-new-dataset-29f861af0128?source=rss-1f24a83d4eaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/29f861af0128</guid>
            <category><![CDATA[class-imbalance]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[ML and DL Explained]]></dc:creator>
            <pubDate>Thu, 30 Jan 2025 13:25:09 GMT</pubDate>
            <atom:updated>2025-01-30T13:25:09.379Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This post will explore a thought-provoking machine learning interview question related to model performance metrics such as accuracy, precision, and recall. This question is particularly relevant for those preparing for interviews in machine learning, deep learning, and data science.</blockquote><h3>The Question</h3><p>Imagine you are studying a newly discovered bird species on an island. As part of your research, you develop a machine learning model (the specific type does not matter) to distinguish between male and female birds. The model identifies females as the positive class (labeled as 1). After training, your model achieves high accuracy, precision, and recall on test datasets.</p><p>One day, your supervisor asks you to study a neighboring island inhabited by the same bird species. However, a disease on this second island has wiped out approximately 90% of the female bird population.</p><p>Given this scenario, how would you expect your model to perform in terms of accuracy, precision, and recall on the new island?</p><h3>Key Considerations for Solving the Problem</h3><p>Before diving into the solution, consider these tips:</p><ol><li><strong>Understand the Definitions</strong>: Familiarize yourself with the formulas for accuracy, precision, and recall. If you need a refresher, check out my previous post on classification models and evaluation metrics.</li><li><strong>Visualize the Data Distribution</strong>: Think about how the bird population changes between the two islands and how this affects the model’s predictions.</li><li><strong>Attempt to Solve It First</strong>: Pause and try to answer the question yourself before reading further. Interview questions like these are rare, and working through them independently will enhance your problem-solving skills.</li></ol><h3>Understanding Accuracy, Precision, and Recall</h3><p>Let’s review these metrics using a simple classification framework:</p><ul><li><strong>Accuracy</strong>: Measures the proportion of correct predictions.</li><li><strong>Precision</strong>: Measures the proportion of correctly predicted positive samples among all predicted positives.</li><li><strong>Recall</strong>: Measures the proportion of actual positives that were correctly identified.</li></ul><p>Where:</p><ul><li>TP = True Positives</li><li>FP = False Positives</li><li>TN = True Negatives</li><li>FN = False Negatives</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqf-VYarQfkrOE2WofnrYw.png" /></figure><h3>Performance on the First Island</h3><ul><li>The dataset has a roughly equal distribution of male and female birds.</li><li>The model achieves high accuracy, precision, and recall due to balanced classes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N04N2u5ycuym4Nb25_Upng.png" /></figure><h3>Performance on the Second Island</h3><p>With a 90% reduction in female birds:</p><ul><li><strong>Accuracy</strong>: Remains relatively unchanged since the majority of the dataset consists of male birds, and the model will still classify most samples correctly.</li><li><strong>Precision</strong>: Drops significantly because the number of true positives (correctly identified females) is much lower. The false positives (misclassified males) remain high, making the precision score lower.</li><li><strong>Recall</strong>: Remains roughly the same because the proportion of correctly predicted females among the remaining female population does not change significantly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ddOUkIcxJLTHt0OMziyu9w.png" /></figure><h3>Real-World Implications: Fraud Detection</h3><p>This phenomenon is common in imbalanced datasets, such as fraud detection. Consider a credit card fraud detection system:</p><ul><li>Most transactions are legitimate (negative class), while fraudulent transactions (positive class) are rare.</li><li>Precision tends to be low because the number of false positives is high.</li><li>Recall is crucial in this context because failing to detect fraudulent transactions has severe consequences.</li></ul><h3>Follow-up Question: Handling Class Imbalance</h3><p>In an interview, you might be asked how to handle class imbalance. Here are three common techniques:</p><ol><li><strong>Oversampling and Undersampling</strong>:</li></ol><ul><li>Reduce the number of majority class samples (undersampling).</li><li>Duplicate or generate new minority class samples (oversampling).</li></ul><ol><li><strong>Class Weight Adjustment</strong>: Assign higher weights to the minority class during training.</li><li><strong>Synthetic Data Generation: </strong>Use methods like Synthetic Minority Oversampling Technique (SMOTE) to generate synthetic samples.</li></ol><h3>Conclusion</h3><p>In summary:</p><ul><li>Accuracy remains stable in the second island scenario.</li><li>Precision drops due to increased false positives.</li><li>Recall remains roughly the same.</li><li>Class imbalance is a common challenge in real-world datasets, and there are several techniques to mitigate its effects.</li></ul><p>Understanding these concepts will significantly improve your ability to answer similar interview questions and apply them in real-world scenarios.</p><p>If you found this helpful, please like and subscribe! Let me know in the comments if you’d like a post on another topic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29f861af0128" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>