<?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 Sanghavi harsh on Medium]]></title>
        <description><![CDATA[Stories by Sanghavi harsh on Medium]]></description>
        <link>https://medium.com/@sanghaviharsh666?source=rss-8f5dc2a298b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6ko80uM5RNTHEgmb</url>
            <title>Stories by Sanghavi harsh on Medium</title>
            <link>https://medium.com/@sanghaviharsh666?source=rss-8f5dc2a298b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 10:02:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanghaviharsh666/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[Mastering Multimodal RAG with the Colpali Architecture]]></title>
            <link>https://medium.com/@sanghaviharsh666/mastering-multimodal-rag-with-the-colpali-architecture-d50bdca02000?source=rss-8f5dc2a298b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d50bdca02000</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[multimodal-ai]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[hugging-face-tutorials]]></category>
            <dc:creator><![CDATA[Sanghavi harsh]]></dc:creator>
            <pubDate>Wed, 11 Dec 2024 16:36:38 GMT</pubDate>
            <atom:updated>2024-12-11T16:36:38.663Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*gMQ-dCCgFfumMvIoQ5fbag.png" /></figure><blockquote>Introduction</blockquote><p>In current times, LLM-based applications are widely used. However, one of the major challenges with LLMs is their tendency to <strong>hallucinate</strong> — generating information that sounds plausible but is factually incorrect or unsupported. This limitation arises because LLMs rely solely on the data they were trained on, which may be outdated or incomplete. As a result, these models often struggle to provide accurate, contextually grounded answers, especially for niche or rapidly evolving domains.</p><p>This is where <strong>Retrieval-Augmented Generation (RAG)</strong> comes into the picture. RAG combines the generative capabilities of LLMs with external knowledge retrieval systems, such as document databases or search engines. Instead of relying entirely on pre-trained knowledge, a RAG system retrieves relevant information from external sources in real-time and incorporates it into its responses. This ensures more accurate, up-to-date, and reliable outputs, effectively addressing the hallucination problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*L2KVvOZSmu935H5_z7vxXw.png" /></figure><p><strong>traditional RAG has primarily focused on textual data,</strong> limiting its applicability in scenarios requiring multiple forms of input, such as images, videos, or audio.</p><p>To meet this demand, <strong>Multimodal RAG</strong> was introduced. By enabling AI systems to retrieve and generate insights from text, images, and other data sources, multimodal RAG opens the door to a vast array of applications, from multimodal virtual assistants to cross-domain research tools.</p><blockquote>Traditional Multimodal RAG:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*IMp1LxEcbNSIKvuJsPMpuA.png" /></figure><p><strong>Offline Processing (Preprocessing Stage):</strong></p><ul><li><strong>OCR (Optical Character Recognition):</strong><br>The model begins by extracting text from multimodal documents (e.g., PDFs or scanned images) using OCR.</li><li><strong>Layout Detection:</strong><br>The system identifies the structural layout of the document (e.g., headings, tables, paragraphs, etc.).</li></ul><p><strong>Captioning and Chunking:</strong></p><ul><li><strong>Captioning</strong>: Visual elements (e.g., figures, images) are assigned textual descriptions.</li><li><strong>Chunking</strong>: Large blocks of text are divided into smaller, manageable chunks for processing.</li><li>The processed text chunks are passed through a <strong>Text Embedding Model</strong> to generate vector embeddings.</li></ul><p><strong>Similarity Scoring (Online Retrieval):</strong></p><ul><li>At query time, the user’s query is transformed into a vector embedding using the same <strong>Text Embedding Model</strong>.</li></ul><p><strong>Query Matching:</strong></p><ul><li>The retrieved chunks are ranked and returned, forming the foundation for generating responses using downstream language models.</li></ul><h4>problems with traditional approach:</h4><ul><li>The <strong>OCR</strong> and <strong>layout detection</strong> stages are time-consuming and computationally expensive, requiring significant preprocessing time (7.22 seconds per page).</li><li>Visual information is reduced to textual captions, leading to <strong>loss of rich visual context.</strong></li><li><strong>Poor layout detection</strong> can lead to incorrectly chunked data, disrupting document semantics.</li></ul><blockquote>Colpali Approach</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i-Ao2H8vA9t5r_f1RFcm7Q.png" /></figure><ul><li>Uses a <strong>Vision-Language Model (Vision LLM)</strong> to process both text and visual data directly, without relying on separate OCR or layout detection.</li><li>Generates unified embeddings for both modalities in a shared space, enabling seamless integration.</li><li>Processes documents much faster (<strong>0.39 seconds per page</strong>) than traditional approaches.</li><li>User queries are embedded using the Vision LLM and matched against precomputed embeddings using <strong>MaxSim</strong> for both text and visuals.</li><li>Combines similarity scores for accurate multimodal retrieval.</li></ul><blockquote>Colpali Architecture</blockquote><p>ColPali is a combination of <strong>ColBERT</strong> and <strong>PaLI-GEMMA</strong> approaches. Let’s understand both in detail:</p><h4>1. Pali-Gemma:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzb99_zlZEjPp98NAYLWOA.png" /></figure><p><strong>PaLI-GEMMA (Pathways Language and Image Model — General Multimodal Model Architecture)</strong> is a vision-language model designed for multimodal understanding and generation.</p><p>It is combination of<strong> SigLIP-400M</strong> vision encoder and <strong>Gemma-2B</strong> LLM model. Let’s see the process:</p><ul><li><strong>Input:</strong> Receive a combination of instruction text and image data.</li><li><strong>Image Processing:</strong> Extract patch embeddings from the image using SigLIP-So400m/14.</li><li><strong>Embedding Projection:</strong> Project the image patch embeddings into the Gemma-2B text vector space for unified representation.</li><li><strong>Text Processing:</strong> Process the instruction text using Gemma-2B’s text model.</li><li><strong>Multimodal Fusion:</strong> Combine the projected image embeddings and processed text embeddings within a shared embedding space.</li></ul><p>Let’s dig a little bit deeper and understand the <strong>SigLIP-400M ViT</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*e4-0kDRClNnmdiV7sQBjJQ.png" /></figure><p><strong>SigLIP</strong> takes a<strong> 378x378</strong> pixel image as input and breaks it into patches, each of size 14x14. For each image, it generates <strong>27x27 patches</strong>, resulting in a total of 729 image embedding inputs. Each patch, with dimensions of <strong>14x14x3 (for RGB channels)</strong>, provides 588 input values. These inputs are then passed through a <strong>27-layer attention block</strong>, producing the output embeddings.</p><p>The output embeddings might have different dimensions, so they pass through a <strong>linear projection</strong> to be converted into the same dimension required by <strong>Gemma-2B</strong>.</p><h4>2. ColBERT:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XHZMwyogl_7y3GReUgg8Mw.png" /></figure><ul><li>Instead of computing dense representations for entire documents, <strong>ColBERT</strong> generates <strong>embeddings for individual tokens in a document.</strong></li><li>it computes similarity scores for query and document tokens and uses a <strong>MaxSim</strong> operation to compute relevance between the token embeddings of the query and the document.</li></ul><blockquote>Advanced Versions of the Colpali Method</blockquote><p>Let’s analyze the <strong>ViDoRe (Visual Document Retrieval Benchmark)</strong> and review the results. Currently, several versions of <strong>ColPali</strong> are at the top, including <strong>ColQwen</strong>’s different versions, as well as <strong>ColSmolVLM-Alpha</strong>, which has outperformed the original ColPali.</p><p>also Data is the same as the <strong>ColPali data</strong> described in the paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ELIuhA9T3MJMKosVnVRAA.png" /></figure><p>Now, let’s examine the improvements that contribute to this enhanced performance.</p><h4>1. ColQwen</h4><p>The improvements in <strong>ColQwen</strong> stem from its integration with the <strong>Qwen model</strong>, which has significantly enhanced its ability to understand complex multimodal data. This model takes <strong>dynamic image resolutions</strong> in input and does not resize them, <strong>changing their aspect ratio as in ColPali</strong>. Maximal resolution is set so that <strong>768 image patches</strong> are created at most. <strong>Experiments show clear improvements with larger amounts of image patches, at the cost of memory requirements.</strong></p><h4>2. ColSmolVLM-alpha</h4><p>This method uses <strong>ColSmolVLM-1.7B</strong> is a model based on a novel model architecture and training strategy based on Vision Language Models (VLMs) to efficiently index documents from their visual features.</p><blockquote>Conclusion</blockquote><p>The future of <strong>Multimodal RAG</strong> lies in enhancing the integration of diverse data types (text, images, audio, etc.) for more<strong> comprehensive and accurate retrieval.</strong></p><p><strong>ColPali</strong> is a major step forward in bridging the gap between <strong>vision and language</strong> models, combining the strengths of <strong>efficient retrieval</strong> and <strong>generative capabilities</strong></p><p><strong>ColPali</strong> demonstrates how <strong>cross-modal reasoning</strong> is beneficial by enhancing the integration of visual and textual data, allowing for more accurate and contextually grounded outputs. It provides an opportunity to improve <strong>cross-modal reasoning</strong> and <strong>contextual understanding</strong>, enabling more sophisticated query processing and content generation.</p><p>To explore the detailed implementation, feel free to check out this insightful blog post: <a href="https://medium.com/@gneyapandya1234/colpali-new-era-of-document-retrieval-7fcae3cd9848">Colpali: A New Era in Document Retrieval</a></p><h4>References</h4><ul><li><a href="https://arxiv.org/pdf/2407.01449">ColPali: Research Paper</a></li><li><a href="https://www.youtube.com/watch?v=nzcBvba7mzI">LlamaIndex Webinar: ColPali — Efficient Document Retrieval with Vision Language Models</a></li><li><a href="https://huggingface.co/spaces/vidore/vidore-leaderboard">Vidore Leaderboard — a Hugging Face Space by vidore</a></li><li><a href="https://huggingface.co/vidore/colqwen2-v1.0">vidore/colqwen2-v1.0 · Hugging Face</a></li><li><a href="https://huggingface.co/vidore/colsmolvlm-alpha">vidore/colsmolvlm-alpha · Hugging Face</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d50bdca02000" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigating the Evolution of Reinforcement Learning: A Historical Perspective]]></title>
            <link>https://medium.com/@sanghaviharsh666/navigating-the-evolution-of-reinforcement-learning-a-historical-perspective-6fbbaa010351?source=rss-8f5dc2a298b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fbbaa010351</guid>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[q-learning]]></category>
            <category><![CDATA[actor-critic]]></category>
            <category><![CDATA[ppo]]></category>
            <category><![CDATA[deep-q-learning]]></category>
            <dc:creator><![CDATA[Sanghavi harsh]]></dc:creator>
            <pubDate>Sat, 11 May 2024 17:22:11 GMT</pubDate>
            <atom:updated>2024-05-11T17:22:11.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*vRrSKU07XYZh8rBsLCOUBg.png" /><figcaption>time line of Reinforcement Learning</figcaption></figure><h3>Table of Contents:</h3><ul><li><a href="#97a3">Introduction to Reinforcement Learning</a></li><li><a href="#3aac">Dynamic Programming: The Roots of RL<br></a>- Bellman Equation</li><li><a href="#37d7">Birth of Reinforcement Learning</a><br>- Markov Decision Processes (MDPs)<br>- Problems with MDPs</li><li><a href="#7e54">Value and Policy: Fundamentals of RL</a><br>- What is Value and Policy?<br>- Value-based methods<br>- Policy-based methods</li><li><a href="#7ee1">Q-Learning and the Q-table</a><br>- Need of Q-Learning<br>- Q-Learning and Q-Table <br>- Problems with Q-Learning</li><li><a href="#3db9">birth of Actor-Critic Architecture</a><br>- What is Actor-Critic Architecture <br>- Why initial Actor-Critic architecture has less impact</li><li><a href="#dcad">Deep Q-Networks (DQN)</a><br>- What is Need of DQN<br>- What is DQN<br>- Problems with DQN</li><li><a href="#dffa">Evolution of Advanced RL Algorithms<br></a>- Trust Region Policy Optimization (TRPO)<br>- Deep Deterministic Policy Gradient (DDPG)<br>- Proximal Policy Optimization (PPO)</li><li><a href="#0910">Conclusion </a><br>- Summary <br>- Role of RL in Modern AI and Exciting Opportunities Ahead</li></ul><blockquote><strong>Introduction</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/0*yhYPVGZhA2jQTTFW" /></figure><p>what is Reinforcement Learning?</p><ul><li>Reinforcement learning is a type of <strong>machine learning</strong> process that focuses on decision making by autonomous <strong>agents</strong>.</li><li>An autonomous <strong>agent</strong> is any system that can make decisions and act in response to its <strong>environment</strong> independent of direct instruction by a human user.</li></ul><p>There are many definitions and interpretation of Reinforcement Learning let’s understand by simple Example:</p><ul><li>Reinforcement learning is like teaching a dog new trick. Just as a dog learns to perform certain actions when it receives praise (reward) and avoids certain actions to prevent negative reactions, it wants to earn praise so it tries actions that result in praise. Reinforcement learning is about learning to take specific actions in an environment to maximize rewards and minimize penalties.</li></ul><blockquote>Dynamic Programming</blockquote><p>Dynamic programming (DP) originated in the <strong>1950</strong>s through the work of Richard Bellman, who is credited with its development.</p><p>what is dynamic Programming?</p><ul><li>Dynamic programming is method for solving complex problems by breaking them down into simpler subproblems and solving each subproblem only once, storing the solutions to subproblems in a table or memorization array.</li><li>It is based on principle of optimality which says that optimal solution of problem can be constructed using optimal solutions of subproblems.</li></ul><p>how dynamic programming relate to RL?</p><ul><li>Dynamic programming (DP) serves as one of the foundational pillars upon which RL is built.</li><li>Dynamic programming originally emerged as a method to solve the problem of optimal control, where the goal is to find the best sequence of <strong>actions</strong> to <strong>maximize a cumulative reward</strong> over time. This aligns closely with the fundamental objective of RL,</li><li>Dynamic programming introduces the <strong>Bellman equation,</strong> which express the optimal value of a decision problem in terms of the optimal value of its subproblems. These equations provide a recursive relationship between the value of a <strong>state</strong> or <strong>action</strong> and the values of subsequent <strong>states</strong> or <strong>actions</strong>.</li></ul><h4>Bellman Equation</h4><p>The Bellman equation was formulated by Richard Bellman in the 1950s as part of his pioneering work in dynamic programming.</p><p>In reinforcement learning, the Bellman equation serves as a key theoretical foundation for designing and analyzing RL algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/0*uiTuKWDqVFm1FVoB" /><figcaption>bellman optimality equation</figcaption></figure><p>Where,</p><ul><li>a = action , S = State , r = reward, <em>π</em> = policy</li><li>V<em>π</em>(S’) = expected return of the following policy from state S’.</li><li><em>π</em>(a|s) = probability to take action a from state s under policy(<em>π</em>).</li><li><em>R</em>(<em>s</em>,<em>a</em>) = imidiate reward at state s using action a.</li><li><em>γ</em> = discount factor</li></ul><p>The Bellman equation expresses the value of a decision problem in terms of the values of its subproblems. It can be written in various forms depending on the context, but the most common forms are the Bellman Expectation Equation for state-value functions (<strong>V-functions</strong>) and the Bellman Optimality Equation for action-value functions <strong>(Q-functions)</strong>.</p><p>The application of <strong>the Bellman equation in RL</strong> gained prominence in the <strong>late 20th century </strong>and has since become a central concept in the field.</p><blockquote>Birth of Reinforcement Learning</blockquote><p>after knowing about dynamic programming, and bellman equation we need one method or framework which utilize these methods. This framework is Markov Decision Process (MDP).</p><p>The concept of Markov Decision Processes (MDPs) was introduced in the <strong>late 1940s and early 1950s </strong>by researchers such as Richard Bellman and Howard Raiffa.</p><h4>What is Markov Decision Process (MDP)?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*f2s7O2TRwKJ8Iq0sSryVvQ.png" /></figure><p>MDP is a mathematical framework used in the field of reinforcement learning to model sequential decision-making problems in uncertain environments.</p><p>MDPs provide a formal framework for modeling sequential decision-making problems, while dynamic programming techniques, such as policy iteration and value iteration, are used to solve these problems efficiently by leveraging the recursive structure of the Bellman equation.</p><h4>Problems with MDP</h4><ul><li>Curse of Dimensionality</li><li>Model Uncertainty</li><li>Continuous State or Action Spaces not possible</li><li>Delayed or Sparse Rewards</li><li>Exploration- Exploitation Tradeoff</li></ul><blockquote>Value and Policy: Fundamentals of RL</blockquote><p>In reinforcement learning (RL), “value” and “policy” are two fundamental concepts that play key roles in learning and decision-making.</p><h4>What is Value and Policy?</h4><ul><li>In Reinforcement Learning, “value” refers to the expected cumulative reward and “Policy” is set of rules which is used by agent to get maximum reward.</li><li>Agent always tries different state an action pairs and select in which value is maximum.</li><li>to get optimal solution for our problem we have two ways, first if we <strong>select state and action pair in which we get maximum value</strong> or second <strong>if we find optimal policy for selecting action</strong>.</li><li>in summary, policy is used to determine which action should we choose from current state and value is cumulative reward.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ji7ruI7ZhBN_ZvfN.png" /></figure><h4>Value-based methods</h4><ul><li>There are two main types of value functions:</li><li><strong>State-Value Function 𝑉(𝑠)</strong>: This function estimates the expected cumulative reward when starting from a particular state 𝑠<em>s</em> and following a specific policy thereafter.</li><li><strong>Action-Value Function 𝑄(𝑠,𝑎)</strong>: This function estimates the expected cumulative reward when starting from state 𝑠<em>s</em>, taking action 𝑎<em>a</em>, and then following a specific policy thereafter.</li><li>in value-based methods, main part is to find suitable value function which gives near to real world cumulative reward.</li><li>First Value based method is created in <strong>1988</strong> paper titled “Learning to Predict by the Methods of Temporal Differences.” TD learning combined ideas from <strong>dynamic programming</strong> and Monte Carlo methods to <strong>estimate value functions</strong> by bootstrapping from incomplete episodes.</li><li>After those breakthroughs, several methods were developed for estimating or approximating value functions, with Q-Learning created in 1989 and DQN created 2015 being among the next to be discussed in this blog.</li></ul><h4>Policy-based methods</h4><ul><li><strong>Stochastic Policy</strong>: A stochastic policy selects actions probabilistically, meaning it outputs a probability distribution over actions for each state.</li><li><strong>Deterministic Policy</strong>: A deterministic policy directly outputs a single action for each state without considering probabilities.</li><li>Policy-based methods directly optimize the policy. Instead of estimating value functions (such as state-values or action-values), policy-based methods focus on finding the optimal policy that maximizes cumulative rewards over time.</li><li>First Policy-based method “<strong>REINFORCE</strong>” was created in <strong>1992</strong>, Introduced by Ronald J. Williams. It directly optimizes the policy parameters using the gradient of the expected return with respect to the policy parameters.</li><li>After that second most important policy-based method was “<strong>Policy Iteration</strong>”. It is a classic dynamic programming approach for finding the optimal policy. Its development dates back to the mid-20th century, particularly in the work of Howard and Bellman.</li><li>There are two more most famous methods “<strong>TRPO</strong>” and “<strong>PPO</strong>” but first we need to understand DQN and actor-critic methods.</li></ul><blockquote>Q-Learning and Q-Table</blockquote><p>Q-learning and the concept of Q-tables were introduced by Christopher J. C. H. Watkins in his <strong>1989</strong> PhD thesis, titled “<strong>Learning from Delayed Rewards.</strong>”</p><p>It is most famous Value based method.</p><h4>What is need of Q-Learning Method?</h4><ul><li>before Q-Learning method, Dynamic Programming is used to find optimal solution in MDP.</li><li>There are some problems with dynamic Programming approach,</li><li>Dynamic Programming traves whole search space to find optimal result, when states space is two large it is not feasible to traves whole state space.</li><li>To remove limitations of Dynamic Programming Q-Learning is used in MDPs.</li></ul><h4>What is Q-Learning and Q-Table?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*f39G0QnnrehKggjNMyyq_g.png" /></figure><ul><li>Q-learning is a fundamental reinforcement learning algorithm that learns to make decisions in an environment in order to maximize cumulative rewards over time.</li><li>At the core of Q-learning is the concept of the action-value function 𝑄(𝑠,𝑎), which represents the expected cumulative reward of taking action 𝑎 in state <em>s</em>. The goal of Q-learning is to learn this action-value function, enabling the agent to select actions that maximize long-term rewards.</li><li>A Q-table, also known as a Q-function table, stores action-values for each state-action pair, representing the expected cumulative reward of taking a specific action in a given state.</li><li>The Q-table serves as a central component of Q-learning, allowing the agent to keep track of learned action-values and make decisions that maximize cumulative rewards over time.</li></ul><h4>Problems with Q-Learning and Q-Table approach</h4><ul><li>High-Dimensional State Spaces can’t handle</li><li>suffer from overfitting as if unknown state is given which is not store in Q-Table it can’t give right answer.</li><li><strong>Tabular Representation</strong> is biggest problem because it requires large memory to store.</li><li>Not work for continues states or actions space.</li><li>Exploration- Exploitation Tradeoff</li></ul><blockquote>Birth of Actor-Critic Architecture</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/0*i5S-f0KCSi-tzVe-.png" /></figure><p>we learn about value-based and policy-based methods, we know how they work. Each method has its own advantages and disadvantages, If we use both methods to find optimal solution then we get better results.</p><p>The Actor-Critic architecture,<strong> which combines elements of both value-based and policy-based methods, </strong>was first introduced in the <strong>1989</strong> paper titled “A Continuous Actor-Critic Learning Automaton” by Sutton et al. Where the “<strong>actor</strong>” is responsible for <strong>selecting actions</strong> based on the current policy, while the “<strong>critic</strong>” evaluates the chosen actions by <strong>estimating value functions.</strong></p><h4>What is Actor-Critic Architecture?</h4><ul><li>The Actor-Critic architecture is a hybrid reinforcement learning framework that combines elements of both value-based and policy-based methods.</li><li><strong>Actor</strong>: he actor is responsible for selecting actions based on the current policy. It learns a parameterized policy function that maps states to actions directly or probabilistically.</li><li><strong>Critic</strong>: The critic evaluates the chosen actions by estimating value functions. It learns to approximate the value of being in a particular state or taking a particular action in a given state.</li></ul><h4>Why initial Actor-Critic architecture has less impact?</h4><p>as its combination of both methods it inherits Both’s benefits as well as Both’s flows.</p><ul><li><strong>Function Approximation</strong>: Initial Actor-Critic methods often used simplistic function approximation techniques. These approaches had limited expressiveness and struggled to handle high-dimensional state and action spaces effectively.</li><li><strong>Policy Representation</strong>: Traditional Actor-Critic methods often used shallow architectures or limited parameterizations for policy representation, constraining their capacity to learn complex policies.</li><li>Required more data to learn</li><li>It has unstable training and struggles to generalize the model.</li></ul><blockquote>Deep Q Networks (DQN)</blockquote><p>Reinforcement Learning was implemented using the Q-learning method for a long period until new breakthrough in RL occurred which is DQN.</p><p>Deep Q-Networks (DQN) were introduced in a landmark paper titled <strong>“Playing Atari with Deep Reinforcement Learning,</strong>” published by researchers Volodymyr Mnih et al. from DeepMind in <strong>2015</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*hFXlVJ8dWnHnMQ6rf_4Y7g.png" /><figcaption>deep Q Learning vs Q-Learning</figcaption></figure><h4>What is need of Deep Q Networks?</h4><ul><li>The need for Deep Q-Networks (DQN) arises from the limitations of traditional <strong>Q-learning method</strong>,</li><li>As we discussed above Q-Learning method can’t handle high dimensional states space or continues state space also it requires to store action and state in Q-Table.</li><li>To solve that problem Deep Q Networks is Created.</li></ul><h4>What is Deep Q-Network or Deep Q-Learning method?</h4><ul><li>Q Learning uses Q function which is used to find commutative reward from given state-action pair.</li><li>if we approximate this Q function the limitations Q learning is solved as no need for Q table.</li><li>DQN is Simple <strong>Artificial Neural Network which is used to approximate Q function.</strong></li><li>The method of using Neural Network is called Deep Q learning.</li></ul><h4>Problems with DQN</h4><ul><li>Sample Efficiency as it is neural network so it requires more samples to learn.</li><li>DQN learns action-values indirectly and then derives the policy from these values, which can lead to suboptimal policies, especially in complex environments</li></ul><blockquote>Evolution of Advanced RL Algorithms</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*6Mq9uYSAp15UgYw8cvj8Jw.png" /></figure><p>After breakthrough of DQN, RL Algorithm’s advancement began.</p><p>After DQN, People using <strong>deep neural networks as function approximation</strong> for both value-based method and policy-based method.</p><p>As we discussed earlier about the Actor-Critic architecture, after this breakthrough, significant problems of Actor-Critic were solved, marking the beginning of a new era of advanced RL algorithms.</p><p>We can’t discuss all algorithms in this blog and also can’t discuss in detail so let’s take brief introduction of 3 algorithms.</p><h4>Trust Region Policy Optimization (TRPO)</h4><ul><li>DQN is first algorithm which uses deep neural network for value function estimation. After success of DQN Policy-based methods also starts using deep neural network for finding best policy. In this, most successful only policy-based algorithm is <strong>TRPO</strong> which is introduced by Schulman et al. in <strong>2015</strong>.</li><li>TRPO aims to improve the stability and performance of policy optimization by constraining the size of policy updates during training.</li></ul><p><strong>Key features of TRPO:</strong></p><ol><li><strong>Trust Region Constraints</strong>: TRPO constrains the size of policy updates to ensure stability during training.</li><li><strong>Stable Policy Updates</strong>: It maintains stable policy updates by limiting the KL-divergence between old and new policies.</li><li><strong>Natural Policy Gradient</strong>: TRPO employs a natural policy gradient formulation, ensuring that policy updates are aligned with the true gradient direction for more efficient learning.</li></ol><p><strong>Problems with TRPO:</strong></p><ul><li>the biggest problem with TRPO is complex optimization function.</li><li>The optimization function contains two functions, surrogate loss function to update policy neural network weights and Kullback-Leibler (KL) divergence function. as it has two functions, it requires more time, and it requires complex computation.</li><li>here, optimization function store previous gradients to backtrack previous policy so it also requires more memories also.</li></ul><h4>Deep Deterministic Policy Gradient (DDPG)</h4><ul><li>DDPG is <strong>first successful attempt to use actor-critic architecture with deep neural network</strong> was introduced in the paper “Continuous control with deep reinforcement learning” by Timothy P. Lillicrap et al., published in<strong> December 2015</strong>.</li><li>Deep Deterministic Policy Gradient (DDPG) is a reinforcement learning algorithm designed for environments with <strong>continuous action spaces.</strong></li></ul><p><strong>key features of DDPG:</strong></p><ol><li><strong>Actor-Critic Architecture</strong>: DDPG is based on the Actor-Critic architecture, consisting of two neural networks: an actor network and a critic network.</li><li><strong>Deterministic Policy</strong>: Unlike traditional policy gradient methods that learn stochastic policies, DDPG learns a deterministic policy.</li><li><strong>more stable</strong>: The deterministic policy allows for more stable and efficient learning in continuous action spaces.</li></ol><h4>Proximal Policy Optimization (PPO)</h4><p>PPO is originated from TRPO algorithm. it is created to remove limitation of TRPO algorithm introduced in the paper “Proximal Policy Optimization Algorithms” by Schulman et al., published in <strong>July 2017</strong>.</p><p>PPO has two versions, first version of PPO included several key components such as <strong>clipped surrogate objective</strong>, <strong>trust region optimization</strong>. and second version of PPO also known as <strong>PPO-Clip,</strong> was introduced as an improvement to the original PPO algorithm. It was described in the paper “PPO-Clip: Efficient Optimization of Trust Region Objectives” by P. Srinivas et al., published in <strong>October 2017</strong>. <strong>PPO-Clip simplified the optimization procedure of PPO by directly clipping the ratio of the new and old policies, instead of using a complicated trust region constraint.</strong> This modification made the algorithm easier to implement and more computationally efficient while maintaining similar performance to the original PPO.</p><p><strong>key features of PPO:</strong></p><ol><li><strong>Trust Region Optimization:</strong> PPO employs a trust region optimization approach to ensure stable and conservative policy updates.</li><li><strong>Clipped Surrogate Objective</strong>: Instead of directly optimizing the policy parameters using the expected reward, PPO maximizes a clipped surrogate objective function. <strong>This objective function approximates the policy improvement while ensuring that policy updates do not deviate too far from the previous policy.</strong></li><li><strong>Actor-Critic Architecture:</strong> PPO can be implemented using an Actor-Critic architecture. The actor and critic networks are typically parameterized using deep neural networks.</li></ol><blockquote>Conclusion</blockquote><h4>Summary</h4><p>let&#39;s summarize whole timeline of RL evolution:</p><ul><li>1950: Dynamic Programming, Bellman Equations and MDP is introduced.</li><li>1988: First value-based method is introduced Temporal Differences.</li><li>1989: Q-Learning and Q-Table method is introduced also first actor-critic architecture is introduced.</li><li>1992: First policy-based method is introduced RENFORCE.</li><li>2015: new Era of RL, introduction of DQN after that TRPO is introduced.</li><li>2016: DDPG algorithm is introduced.</li><li>2017: PPO algorithm is introduced.</li><li>2018: advanced actor-critic architectures are introduced A3C, SAC etc.</li></ul><h4>Role of RL in Modern AI and Exciting Opportunities Ahead</h4><ul><li>Reinforcement learning (RL) plays a crucial role in modern AI by enabling<strong> autonomous agents</strong> to learn and adapt in complex environments.</li><li>RL has led to breakthroughs in various domains, including robotics, gaming, finance, healthcare, and more.</li><li>For example, <strong>OpenAI’s ChatGPT</strong>, which utilizes <strong>Proximal Policy Optimization (PPO),</strong> demonstrates how RL algorithms can be applied to natural language processing tasks. By interacting with users and receiving feedback, ChatGPT continuously learns and improves its conversational abilities using RL.</li><li>As research in RL continues to evolve, we can expect further innovations that push the boundaries of AI and unlock new possibilities for solving complex real-world problems.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fbbaa010351" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering SVM Kernel Tricks: A Comprehensive Guide to Dual Problems and Kernel Functions]]></title>
            <link>https://medium.com/@sanghaviharsh666/mastering-svm-kernel-tricks-a-comprehensive-guide-to-dual-problems-and-kernel-functions-612bfff2061e?source=rss-8f5dc2a298b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/612bfff2061e</guid>
            <category><![CDATA[dual-problem]]></category>
            <category><![CDATA[svm-classifier]]></category>
            <category><![CDATA[svm-algorithm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[kernel-trick]]></category>
            <dc:creator><![CDATA[Sanghavi harsh]]></dc:creator>
            <pubDate>Sat, 09 Mar 2024 14:00:35 GMT</pubDate>
            <atom:updated>2024-03-10T10:04:12.288Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*P3HTPDAn8zFL-W0mvQgn2A.png" /></figure><h3><strong>Table of contents:</strong></h3><ul><li><a href="#3943">Introduction</a></li><li><a href="#9d59">Understanding the Dual Problem</a><br>- what is dual problem<br>- Conversion to the dual problem<br>- Why dual problem ?</li><li><a href="#e538">Kernel Functions</a><br>- Definition of kernel and kernel tricks<br>- Importance of kernel functions and kernel tricks<br>- Types of kernel functions</li><li><a href="#b76e">Comparison of kernel types</a></li><li><a href="#d0b2">Conclusion</a></li></ul><blockquote><strong>Introduction</strong></blockquote><ul><li><strong>What is SVM ?</strong></li></ul><p>Support Vector Machine (SVM) is a powerful supervised machine learning algorithm used for classification and regression tasks. It aims to find the optimal hyperplane that separates data points into different classes with the maximum margin, thereby improving generalization performance.</p><p>SVM constructs a hyperplane defined by the equation: <strong><em>wT x </em>+ <em>b </em>= 0</strong></p><p>where <em>w</em> is the weight vector perpendicular to the hyperplane, <em>x</em> is the input feature vector, and <em>b</em> is the bias term.</p><p><strong>Support Vectors</strong>: Support vectors are the data points that lie closest to the decision boundary (the hyperplane) and influence the position and orientation of the hyperplane. These are the critical data points that determine the optimal margin.</p><ul><li><strong>Hard Margin and Soft Margin SVM:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*Q2JhDDEPBzv1FuV2gWIyjQ.png" /></figure><p>In SVM, there are two margin types: <strong>hard margin and soft margin</strong>. In hard margin SVM, the algorithm aims to find a hyperplane that perfectly separates the data points of different classes without allowing any misclassifications. However, hard margin SVM can be sensitive to outliers and noise. Soft margin SVM introduces a penalty <strong>parameter C</strong> that allows for some misclassifications, balancing between maximizing the margin and minimizing the classification error. Soft margin SVM is more robust to outliers and noise.</p><ul><li><strong>Maximum Margin Function</strong>:</li></ul><p>The objective of SVM is to maximize the margin between the support vectors of different classes. Mathematically, it can be formulated as an optimization problem: <strong>Maximize ∥<em>w</em>∥²​ .</strong></p><p>which must follow this constraint: <strong><em>yi </em>​(<em>wT xi </em>​+ <em>b</em>) ≥1 for <em>i</em>=1,2,…,<em>N</em></strong></p><p>Where (<em>xi</em>​,<em>yi</em>​) are the training samples , <em>xi</em>​ is the feature vector, <em>yi</em>​ is the class label, <em>w</em> is the weight vector, and <em>b</em> is the bias term.</p><p>Hinge Loss Function: In SVM, the hinge loss function is used to penalize misclassifications. It is defined as: <strong>max(0,1−<em>yi</em>​ ( <em>wT xi </em>​+ <em>b</em>))</strong></p><p>Where <em>yi</em>​ is the true class label of sample <em>xi</em>​.</p><blockquote><strong>Understanding the dual problem</strong></blockquote><p>In SVM algorithm maximum marginal function not used instead of it uses dual problem in algorithm.</p><p>The dual problem in Support Vector Machines (SVM) is an alternative optimization problem derived from <strong>the primal problem</strong>, aiming to find the <strong>Lagrange multipliers</strong> corresponding to the support vectors while maximizing the margin.</p><ul><li><strong>why it is called “dual” problem? — </strong>The solutions of the primal and dual problems are related through the <strong>duality theory, </strong>and finding the solution to one problem often implies finding the solution to the other problem as well.</li></ul><h4><strong>Conversation to Dual Problem</strong></h4><p>1. <strong>Original Problem (Primal Problem)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/0*veSK-fdwhAX3I0MT.png" /></figure><p>2. <strong>Introduce Lagrange Multipliers</strong></p><ul><li>when optimizing a function (the objective function) subject to certain constraints, Lagrange multipliers are introduced to incorporate these constraints into the optimization process. They help in finding the values of the variables that satisfy both the objective function and the constraints simultaneously.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*1twd4VVB6JbIOqtD.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/0*Mps53AMFmIBPIco5.png" /></figure><p>3.<strong> Differentiate Lagrange Formula</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/0*MeWqLsgtaezEjJ2W.png" /></figure><ul><li>Substitute the expressions for the primal variables back into the Lagrangian to obtain the dual Lagrangian, which is now a function of only the Lagrange multipliers.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*y4cETORWlhu_DSQT.png" /></figure><p>4.<strong> Final Dual Problem Formula :-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*HhS1OjybQnlgaz7F.png" /></figure><h4><strong>Why Dual Problem</strong></h4><ul><li>Computational Efficiency:</li><li>Kernel Trick Integration:</li><li>Insights and Analysis:</li><li>Margin Maximization:</li><li>Flexibility in Constraints:</li></ul><p>Thus, we utilize the inner products of features, rather than the direct features themselves, to solve our SVM Maximization problem.</p><blockquote><strong>Kernel Functions</strong></blockquote><ul><li>A <strong>kernel</strong> in the context of machine learning, particularly in algorithms like Support Vector Machines (SVM), is a function that calculates the similarity between two data points in a high-dimensional space.</li><li>It allows SVMs to implicitly<strong> map input data into a higher-dimensional feature space,</strong> making it easier to find a linear separation between classes that might not be linearly separable in the original space.</li></ul><p><strong>Definition of Kernel</strong>: A kernel function <em>K</em> takes two input vectors <em>x</em> and <em>y</em> and computes their similarity or inner product in a higher-dimensional space. Mathematically, for two vectors <em>x</em> and <em>y</em>, the kernel function is defined as: <em>K</em>(<em>x</em>,<em>y</em>)=⟨<em>ϕ</em>(<em>x</em>),<em>ϕ</em>(<em>y</em>)⟩</p><p>Where:</p><ul><li><em>ϕ</em> is a mapping function that implicitly maps the input vectors <em>x</em> and <em>y</em> into a higher-dimensional feature space.</li></ul><h4><strong>Kernel Tricks</strong>:</h4><ul><li>Kernel tricks, also known as the kernel trick or kernel method, are techniques used in machine learning, particularly in algorithms like Support Vector Machines (SVM), to implicitly map input data into a higher-dimensional feature space without explicitly calculating the transformation.</li><li>The main idea behind kernel tricks is to utilize kernel functions to compute the dot product or similarity between data points in the higher-dimensional space efficiently. This allows algorithms like SVM to operate in a high-dimensional space while avoiding the computational cost associated with explicitly transforming the data.</li></ul><h4><strong>Importance of Kernel Functions </strong>:-</h4><p>to understand importance of kernel functions let’s take one example,</p><ul><li>suppose we have one dataset which have 2 features and non linear relationship between them.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/0*koy1G0j0IkHyUou0.png" /></figure><ul><li>If we apply linear regression on it. it does not classify accurately.<br>We need to transform the data into a<strong> Two-degree polynomial</strong> to capture this nonlinear relationship.</li></ul><p>Now our data has 5 features and our model can correctly classify this data.</p><p>[x0, x1] → [x0, x1, x0², x0 x1 , x1²]</p><p>Due to this transformation,<strong> the dimensions of the data have increased</strong>, and now our model requires more time to classify the data. If our data requires more dimensions to capture non-linearity and it already has many dimensions, then <strong>it is not a feasible solution.</strong></p><p>We need a method or function that directly converts our feature inner products into transformed feature inner products to save time and maintain the same level of accuracy.</p><p>This problem is solved by the <strong>kernel function</strong>, which converts the inner products of features into the inner products of transformed features without actually transforming the data and this method is known as <strong>Kernel Tricks.</strong></p><p>For this example, we can use poly kernel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/151/0*UjkkjexFpFmVijiZ" /><figcaption>Formula of poly kernel function</figcaption></figure><p>where, d is degree of kernel .</p><p>If we expand this equation for degree 2 , we get</p><p>[x0, x1] → [x0, x1, x0², x0 x1 , x1²] which is equivalent to transformed data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*KlB-d1VNh1sXCRE8lgfxtw.png" /><figcaption>Use of Kernel function</figcaption></figure><p>with this example we can understand that kernel functions and kernel tricks ‘s importance.</p><p>To summarize,</p><ul><li>kernel functions offer efficiency, flexibility, and cost-effectiveness.</li><li>They can efficiently handle the curse of dimensionality and operate in infinite dimensions.</li><li>Finally, they can also capture non-linearity.</li></ul><h4><strong>Types of Kernel Functions</strong></h4><ol><li><strong>Linear Kernel</strong> : — It is most basic type of kernel which is one dimension in nature.</li></ol><p>Formula of Linear Kernel: — K<strong>(xi, xj) = Transpose (xi) . xj</strong></p><p>When to use it :</p><ul><li>When data is linearly separable.</li><li>It is more computationally efficient than other functions so when we have dataset with high more input features then it can work well with this. for example, text classfication problems where input features are more it can work better.</li></ul><p>2. <strong>Polynomial Kernel</strong>: — It maps input data into higher dimensions space using polynomial functions. it is more generilize form of linear kernel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/151/0*UjkkjexFpFmVijiZ" /><figcaption>Formula of poly kernel function</figcaption></figure><p>When to use it:</p><ul><li>when data contains non linearity and it can’t separate by linear boundary.</li></ul><p>When input dimensions are high it is not preferable to use this .</p><p>3. <strong>Radial Basis Function (RBF) Kernel:</strong> — It is also called Gaussian Kernel. It is most commonly and most widely used kernel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/0*Ipb_5Kzib-F-jgSO.png" /><figcaption>Formula of RBF Kernel Function</figcaption></figure><ul><li>As we discussed earlier, kernel functions are used to directly map the inner products of the original data to the inner products of the transformed data. Similarly, the RBF kernel does the same; <strong>it maps the inner products of the original data to the expansion of features into infinite-dimensional transformed data’s inner products.</strong></li><li>if we expand this function it transforms into <strong>Taylor series</strong> which has infinite expansion which shows infinite dimensions of data.</li><li>thus, RBF Function maps data with infinite dimension space.</li></ul><p>When to use it:</p><ul><li>when data’s relationship is unknown or complex, we can use this function to find decision boundaries.</li><li>when there is more complex non linearity we can use this function.</li></ul><p>4. <strong>Sigmoid Kernel:</strong> — it maps data into a higher dimensions using hyperbolic tangent function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/0*7WcQAFX3LUNzs6nf.png" /><figcaption>formula of sigmoid Kernel function</figcaption></figure><p>When to use it:</p><ul><li>when data shows sigmoid patterns .</li><li>It is more preferred in neural networks.</li></ul><blockquote><strong>Comparision of kernel types</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*ro0GqW9HUn4-gebnywmLCQ.png" /><figcaption>Comparison Table of kernels</figcaption></figure><blockquote><strong>Conclusion</strong></blockquote><p>In Conclusion , SVM stands out an dimension-independent machine learning model which capable of capturing non linear relationship of the data utilizing of kernels. by selecting appropriate kernel we can achieve greater accuracy and efficiency.</p><p>I hope it helped!!!</p><h4>References</h4><ul><li><a href="https://www.kaggle.com/code/prabhat12/svm-from-scratch?scriptVersionId=53565816&amp;cellId=23">https://www.kaggle.com/code/prabhat12/svm-from-scratch?scriptVersionId=53565816&amp;cellId=23</a></li><li><a href="https://www.youtube.com/watch?v=OKFMZQyDROI">https://www.youtube.com/watch?v=OKFMZQyDROI</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=612bfff2061e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comprehensive Guide to Regression Models]]></title>
            <link>https://medium.com/@sanghaviharsh666/comprehensive-guide-to-regression-models-fef3c2ba557f?source=rss-8f5dc2a298b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/fef3c2ba557f</guid>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[logistic-regression]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[types-of-regression]]></category>
            <dc:creator><![CDATA[Sanghavi harsh]]></dc:creator>
            <pubDate>Tue, 27 Feb 2024 17:09:19 GMT</pubDate>
            <atom:updated>2024-02-27T17:09:19.801Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eJ8kWkKZnEk4aMW7jNpgmQ.png" /></figure><h3><strong>Table of content:</strong></h3><ul><li><a href="#2caf">Introduction</a></li><li><a href="#7163">Types of Regression Models</a><br>- Definition and Concept of Regression Models<br>- Functionality and Working Principles<br>- When to use this Regression and use cases</li><li><a href="#a671">Linear Regression</a></li><li><a href="#79ef">Logistic Regression</a></li><li><a href="#4788">Stepwise Linear Regression</a></li><li><a href="#05f0">Ridge Regression</a></li><li><a href="#f155">Lasso Regression</a></li><li><a href="#5ac8">Elastic Net Regression</a></li><li><a href="#16d0">Polynomial Regression</a></li><li><a href="#38e5">Poisson Regression</a></li></ul><blockquote><strong>Introduction</strong></blockquote><p>Regression Analysis is a statistical process for estimating the relationships between the dependent variables or criterion variables and one or more independent variables or predictors. Its purpose is to model the pattern of the dependent variable as a function of the independent variables, facilitating the understanding of how changes in one or more variables correlate with changes in another.</p><p>The primary aim of regression analysis is prediction and forecasting. By analyzing historical data, regression models can forecast future outcomes or trends, offering valuable predictive insights across various fields such as finance, economics, marketing, healthcare, and social sciences.</p><p>Furthermore, regression analysis aids in uncovering the strength and direction of relationships between variables. It assists researchers and analysts in identifying significant factors influencing a particular phenomenon, quantifying their impact, and making data-driven decisions.</p><blockquote><strong>Types of Regression Models</strong></blockquote><h3><strong>1. Linear Regression:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*QUrrOGS0Ts16UKCXMGewuA.png" /><figcaption>Linear Regression Model</figcaption></figure><p><strong>Definition</strong>: Linear regression is a statistical method used to model the relationship between a dependent variable and one or more independent variables by fitting a linear equation to the observed data. It assumes that there is a linear relationship between the independent and dependent variables, which can be represented by a straight line on a graph.</p><p><strong>How it Works (in brief)</strong>: Linear regression works by estimating the coefficients of the linear equation that best fits the observed data points. The equation for a simple linear regression with one independent variable is:</p><p>Y = β0 + β1*X + ε</p><p>Where:</p><ul><li>Y is the dependent variable</li><li>X is the independent variable</li><li>β0 is the intercept (the value of Y when X is 0)</li><li>β1 is the slope (the change in Y for a one-unit change in X)</li><li>ε is the error term</li></ul><p>The goal is to find the values of β0 and β1 that minimize the sum of the squared differences between the observed and predicted values of Y. This is typically done using the method of least squares.</p><p><strong>When to Use Linear regression</strong>:</p><ol><li>There is a linear relationship between the independent and dependent variables.</li><li>Predicting the value of the dependent variable based on the values of one or more independent variables is desired.</li><li>There is a need to understand the strength and direction of the relationship between variables.</li><li>If data follows all linear regression Assumptions.</li></ol><p><strong>use cases:</strong></p><ul><li>Linear regression is widely applied in fields such as economics, finance, social sciences, engineering, and many more for modeling and predicting various phenomena.</li></ul><h3><strong>2. Logistic Regression:</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/0*RwzL99_QeeIKFW-j.png" /></figure><p><strong>Definition</strong>: Logistic regression is a statistical method used for modeling the probability of a binary outcome (i.e., a categorical variable with two possible outcomes) based on one or more independent variables. Unlike linear regression, which predicts continuous outcomes, logistic regression predicts the probability that a given observation belongs to a particular category.</p><p><strong>How it Works (in brief)</strong>: In logistic regression, the dependent variable is categorical and takes on binary values (e.g., 0 or 1, Yes or No). The logistic regression model uses the logistic function (also known as the sigmoid function) to model the relationship between the independent variables and the log-odds of the outcome being in a particular category. The equation for logistic regression is typically expressed as:</p><p><em>P</em>(<em>Y</em>=1∣<em>X</em>) = 1/1+<em>e</em>−(<em>β</em>0​+<em>β</em>1​<em>X</em>)​</p><ul><li><em>P</em>(<em>Y</em>=1∣<em>X</em>) is the probability of the dependent variable being 1 (or belonging to the “success” category) given the values of the independent variables.</li><li>X is the independent variable.</li><li><em>β</em>0​ is the intercept.</li><li><em>β</em>1​ is the coefficient associated with the independent variable.</li><li>e is the base of the natural logarithm.</li></ul><p><strong>When to Use Logistic regression:</strong></p><ol><li>The dependent variable is binary or dichotomous.</li><li>The relationship between the independent variables and the probability of the outcome needs to be modeled.</li><li>There is a need to predict the probability of an event occurring.</li><li>The assumption of linearity between the independent variables and the log-odds of the outcome holds true.</li></ol><p><strong>Use cases:</strong></p><ul><li>Logistic regression finds applications in various fields, including healthcare (predicting disease risk), marketing (predicting customer churn), finance (predicting credit default), and more, where binary classification tasks are prevalent.</li></ul><h3><strong>3. Stepwise Linear Regression</strong></h3><p><strong>Definition</strong>: Stepwise linear regression is a method used to select the most relevant independent variables for inclusion in a linear regression model. It involves iteratively adding or removing independent variables based on statistical criteria until the model’s performance is optimized or a stopping criterion is met.</p><p><strong>How it Works</strong>: The process of stepwise linear regression typically involves two main techniques: forward selection and backward elimination.</p><ol><li>Forward Selection:</li></ol><ul><li>Start with an empty model and iteratively add independent variables one by one.</li><li>At each step, select the variable that contributes the most to the model’s predictive power based on a predefined criterion (e.g., p-value, Akaike Information Criterion (AIC), Bayesian Information Criterion (BIC)).</li><li>Continue adding variables until no additional variables meet the inclusion criteria.</li></ul><ol><li>Backward Elimination:</li></ol><ul><li>Start with a model that includes all independent variables.</li><li>At each step, remove the variable that contributes the least to the model’s predictive power based on a predefined criterion.</li><li>Continue removing variables until no variables meet the exclusion criteria.</li></ul><p>The process of stepwise regression stops when there are no more variables to add or remove, or when the model’s performance no longer improves.</p><p><strong>When to Use Stepwise linear regression:</strong></p><ol><li>There are a large number of independent variables, and it is necessary to identify the subset of variables that have the most significant impact on the dependent variable.</li><li>There is a need to simplify the model by removing irrelevant or redundant variables.</li><li>The goal is to achieve a balance between model complexity and predictive accuracy.</li><li>Exploratory data analysis suggests that only a subset of independent variables may be relevant predictors of the dependent variable.</li></ol><p>However, it’s important to note that stepwise regression can sometimes lead to <strong>overfitting or selection bias if not implemented carefully.</strong> Therefore, it should be used judiciously, and the selected model should be validated using appropriate techniques such as cross-validation.</p><h3><strong>4. Ridge Regression</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YB5j-yhInuSQLQer.jpg" /></figure><p><strong>Definition</strong>: Ridge regression, also known as Tikhonov regularization, is a regression technique used to mitigate multicollinearity and overfitting in linear regression models. It adds a penalty term to the ordinary least squares (OLS) method, aiming to shrink the coefficients towards zero while still maintaining their predictive power.</p><p><strong>How it Works:</strong> In ridge regression, the standard least squares objective function is augmented with a penalty term, often represented as the L2 norm of the coefficients: minimize</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/0*ay6VulAiZoQWWIpH.png" /></figure><p>Where:</p><ul><li><em>yi</em>​ represents the observed values of the dependent variable.</li><li>Xi​ represents the values of the independent variables.</li><li><em>λ</em> is the regularization parameter (also known as the shrinkage parameter) that controls the strength of the penalty term.</li><li><em>βj</em>​ are the coefficients of the independent variables.</li></ul><p>The penalty term, penalizes large coefficients, effectively shrinking them towards zero. This helps to reduce the variance of the estimates, thereby improving the model’s generalization performance.</p><p><strong>When to Use Ridge regression :</strong></p><ol><li>There is multicollinearity among the independent variables, leading to unstable estimates in ordinary least squares regression.</li><li>The number of predictors is large relative to the number of observations, increasing the risk of overfitting.</li><li>The goal is to prevent extreme parameter values and ensure a more stable and interpretable model.</li><li>It is important to prioritize bias reduction over variance reduction.</li></ol><p><strong>Use cases:</strong></p><ul><li>Ridge regression finds applications in various fields such as finance, economics, engineering, and healthcare, where linear regression models are commonly used and multicollinearity or overfitting issues may arise.</li></ul><h3><strong>5. Lasso Regression</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P3BxAuvQJlnX9uHO.png" /></figure><p><strong>Definition</strong>: Lasso regression, short for <strong>Least Absolute Shrinkage and Selection Operator,</strong> is a regression technique used for variable selection and regularization. Similar to ridge regression, lasso regression adds a penalty term to the ordinary least squares (OLS) method, but it utilizes the L1 norm of the coefficients instead of the L2 norm.</p><p><strong>How it Works:</strong> In lasso regression, the objective function to be minimized is: minimize</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/0*-yNJA_EUrlVAOIG_.png" /></figure><p>Where:</p><ul><li><em>yi</em>​ represents the observed values of the dependent variable.</li><li><em>y</em>^​<em>i</em>​ represents the predicted values of the dependent variable.</li><li><em>λ</em> is the regularization parameter (shrinkage parameter) that controls the strength of the penalty term.</li><li><em>βj</em>​ are the coefficients of the independent variables.</li></ul><p>The penalty term <em>λ</em>∑<em>j</em>=1<em>p</em>​∣<em>βj</em>​∣, promotes sparsity in the coefficient estimates by encouraging some coefficients to be exactly zero. This property of lasso regression makes it effective for feature selection, as it automatically selects the most relevant predictors while shrinking others towards zero.</p><p><strong>When to use Lasso regression:</strong></p><ol><li>There is a large number of predictors, and feature selection or dimensionality reduction is desired.</li><li>Some of the predictors are irrelevant or redundant, and their coefficients can be effectively shrunk to zero.</li><li>A more interpretable model with a subset of relevant predictors is preferred.</li><li>The goal is to balance bias and variance, particularly in high-dimensional datasets.</li></ol><p><strong>Use cases:</strong></p><ul><li>Lasso regression is widely applied in fields such as genetics, economics, finance, and machine learning, where predictive modeling with high-dimensional data and feature selection are common challenges.</li></ul><h3><strong>6. Elastic Net Regression</strong></h3><figure><img alt="Getting started with Regression – Savan Nahar – Medium" src="https://cdn-images-1.medium.com/proxy/0*kuuC8_3Q2YjoLoqt.png" /><figcaption>comparison between ridge, lasso and elastic net</figcaption></figure><p><strong>Definition</strong>: Elastic Net regression is a hybrid regression technique that combines the penalties of both ridge regression and lasso regression. It is used to address multicollinearity and perform variable selection in linear regression models. Elastic Net adds both L1 and L2 regularization terms to the ordinary least squares (OLS) objective function.</p><p><strong>How it Works</strong>: In Elastic Net regression, the objective function to be minimized is a combination of the L1 and L2 penalty terms, weighted by the regularization parameters <em>λ</em>1​ and <em>λ</em>2​, respectively. The regularization ratio (<em>α</em>) determines the balance between the L1 and L2 penalties:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/0*Cqx505jihYq_j8wU.png" /></figure><p>Where:</p><ul><li><em>yi</em>​ represents the observed values of the dependent variable.</li><li>X<em>β </em>represents the predicted values of the dependent variable.</li><li><em>λ</em>1​ and <em>λ</em>2​ are the regularization parameters that control the strength of the L1 and L2 penalty terms, respectively.</li><li><em>β </em>are the coefficients of the independent variables.</li></ul><p>The L1 penalty term encourages sparsity in the coefficient estimates, similar to lasso regression, while the L2 penalty term promotes shrinkage of the coefficient estimates towards zero, akin to ridge regression. Elastic Net strikes a balance between the strengths of ridge and lasso regression, offering better performance in scenarios where both types of regularization are beneficial.</p><p><strong>When to Use Elastic Net regression:</strong></p><ol><li>There is multicollinearity among the independent variables, and feature selection or variable regularization is required.</li><li>The dataset contains a large number of predictors, and a balance between sparsity and coefficient shrinkage is desired.</li><li>Both ridge and lasso regression alone are insufficient to address the modeling challenges effectively.</li><li>It is important to achieve a compromise between bias reduction and variance reduction.</li></ol><p><strong>Use Cases:</strong></p><ul><li>Elastic Net regression is commonly employed in fields such as genetics, bioinformatics, finance, and ecology, where datasets are often high-dimensional, and multicollinearity is prevalent.</li></ul><h3><strong>7. Polynomial Regression</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*tALjaGNmc-d5d2mm.png" /></figure><p><strong>Definition</strong>: Polynomial regression is a type of regression analysis used to model the relationship between a dependent variable and one or more independent variables by fitting a polynomial function to the data. Unlike linear regression, which assumes a linear relationship between the variables, polynomial regression allows for more complex, nonlinear relationships to be captured.</p><p><strong>How it Works</strong>: In polynomial regression, the relationship between the independent variable <em>X</em> and the dependent variable <em>Y</em> is modeled as a polynomial function of degree <em>n</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*XgTr_TbVQQe72VdR2cJBAQ.png" /></figure><p>Where:</p><ul><li><em>Y</em> is the dependent variable.</li><li><em>X</em> is the independent variable.</li><li>ℎ<em>β</em>0​,<em>β</em>1​,…,<em>βh</em>​ are the coefficients of the polynomial terms.</li><li><em>ε</em> represents the error term.</li></ul><p>The polynomial function is fitted to the data using least squares regression, where the goal is to minimize the sum of the squared differences between the observed and predicted values of the dependent variable.</p><p><strong>When to Use Polynomial regression:</strong></p><ol><li>The relationship between the independent and dependent variables is nonlinear and cannot be adequately captured by linear regression.</li><li>There is a need to model complex patterns or curvature in the data.</li><li>The data exhibit a polynomial trend, such as quadratic (degree 2) or cubic (degree 3) relationships.</li><li>Extrapolation beyond the range of observed data is necessary, as polynomial regression can be used to predict values outside the range of the original data.</li><li>Overfitting is a concern, and regularization techniques such as ridge regression or Lasso regression are not suitable.</li></ol><p><strong>Use Cases:</strong></p><ul><li>Polynomial regression finds applications in various fields such as physics, engineering, finance, biology, environmental science, and geology, where nonlinear relationships between variables are common, and accurate modeling of data is essential.</li></ul><h3><strong>8. Poisson Regression</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RLYdhyLs2v4NEROx068NJg.png" /></figure><p><strong>Definition</strong>: Poisson regression is a type of regression analysis used when the dependent variable represents counts and follows a Poisson distribution. It models the relationship between the dependent variable (counts) and one or more independent variables by fitting a Poisson regression model to the data.</p><p><strong>How it Works</strong>: In Poisson regression, the dependent variable represents counts of events or occurrences, such as the number of accidents, number of purchases, or number of phone calls. The Poisson regression model assumes that the counts follow a Poisson distribution, which is characterized by a single parameter (λ) representing the average rate of occurrence.</p><p>The Poisson regression model is typically expressed as:</p><p>ln(<em>μ</em>)=<em>β</em>0​+<em>β</em>1​<em>X</em>1​+<em>β</em>2​<em>X</em>2​+…+<em>βk</em>​<em>Xk</em></p><p>Where:</p><ul><li>ln(<em>μ</em>) is the natural logarithm of the mean of the dependent variable (counts).</li><li><em>β</em>0​,<em>β</em>1​,…,<em>βk</em>​ are the coefficients of the independent variables.</li><li><em>X</em>1​,<em>X</em>2​,…,<em>Xk</em>​ are the independent variables.</li><li><em>k</em> is the number of independent variables.</li></ul><p>The model is fitted to the data using maximum likelihood estimation, where the parameters (coefficients) are estimated to maximize the likelihood of observing the actual counts given the model.</p><p><strong>When to Use Poisson regression:</strong></p><ol><li>The dependent variable represents counts of events or occurrences, such as the number of accidents, number of purchases, or number of phone calls.</li><li>The counts are non-negative integers and follow a Poisson distribution.</li><li>There is overdispersion in the data, meaning that the variance of the counts is greater than the mean.</li><li>The goal is to model the rate or intensity of occurrence of events while accounting for the effects of one or more independent variables.</li></ol><p><strong>Use Cases:</strong></p><ul><li>Poisson regression finds applications in various fields such as epidemiology, public health, criminology, ecology, and finance, where count data are prevalent, and understanding the factors influencing the frequency of events is important.​</li></ul><p>I hope it helped!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fef3c2ba557f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>