<?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 Sanjana Garg on Medium]]></title>
        <description><![CDATA[Stories by Sanjana Garg on Medium]]></description>
        <link>https://medium.com/@sanjanabansal1994?source=rss-fde144ab5e9b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qDp2-4VBeeV6nj4tVkfhig.jpeg</url>
            <title>Stories by Sanjana Garg on Medium</title>
            <link>https://medium.com/@sanjanabansal1994?source=rss-fde144ab5e9b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:21:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanjanabansal1994/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[The 20% of Statistics That Does 80% of the Work]]></title>
            <link>https://medium.com/@sanjanabansal1994/the-20-of-statistics-that-does-80-of-the-work-dfeac99390f5?source=rss-fde144ab5e9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfeac99390f5</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science-interview]]></category>
            <dc:creator><![CDATA[Sanjana Garg]]></dc:creator>
            <pubDate>Tue, 14 Jul 2026 01:15:05 GMT</pubDate>
            <atom:updated>2026-07-14T01:15:05.035Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A practical refresher — hypothesis testing, distributions, and the handful of tests that show up again and again in real work and real interviews.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZokWBwmtom2Eo1nO180jZQ.png" /></figure><p>Every data science job description lists “strong statistics fundamentals” as a requirement, but in practice you don’t need a PhD-level grasp of measure theory to do the job well. You need a working fluency in maybe a dozen ideas, applied correctly, over and over. This post is my attempt to distill that core — the roughly 20% of statistics that covers 80% of what shows up in interviews and on the job: forming hypotheses, picking the right test, understanding the distributions your data actually follows, and reading a p-value without fooling yourself.</p><p>I put this together while refreshing my own stats knowledge, and I’m writing it up the way I wish someone had laid it out for me — as one connected story instead of scattered cheat-sheet entries.</p><h3>1. Hypothesis Testing: The Skeleton Everything Else Hangs On</h3><p>Almost every statistical test you’ll ever run follows the same five-step shape:</p><ol><li><strong>State a null hypothesis (H₀) and an alternative (H₁).</strong> H₀ is the boring default — “nothing changed, no difference, no relationship.” H₁ is what you’re actually trying to find evidence for.</li><li><strong>Pick a significance level (α)</strong>, usually 0.05. This is the risk you’re willing to accept of rejecting H₀ when it’s actually true (a false positive, or Type I error).</li><li><strong>Choose the right test statistic</strong> for your data and question — this is the part most people find confusing, and it’s really just a lookup problem once you know what to check (more on that below).</li><li><strong>Compute the p-value.</strong> It’s the probability of seeing data this extreme (or more extreme) <em>if H₀ were true.</em></li><li><strong>Compare p to α.</strong> If p &lt; α, reject H₀ in favor of H₁. If not, you simply fail to reject H₀ — you never “accept” it.</li></ol><p>A subtlety worth internalizing early: your alternative hypothesis can point in one of three directions, and this changes which test you run.</p><ul><li><strong>Two-sided</strong>: “the groups are different” (could go either way)</li><li><strong>Left-sided</strong>: “the population value is smaller than the sample value”</li><li><strong>Right-sided</strong>: “the population value is larger than the sample value”</li></ul><p>Picking the wrong sidedness is one of the most common ways people misuse hypothesis tests without realizing it — so it’s worth deciding your direction <em>before</em> you look at the data, not after.</p><h3>2. Choosing the Right Test: A Decision Framework, Not a Memorization Task</h3><p>This is where most “stats cheat sheets” turn into an overwhelming wall of formulas. It’s much easier if you think of it as answering three questions about your data:</p><p><strong>Is your variable continuous or categorical?</strong> Continuous → you’re usually comparing means (t-tests, ANOVA). Categorical → you’re usually comparing frequencies or associations (Chi-Square).</p><p><strong>How many groups are you comparing?</strong></p><ul><li>One sample vs. a known population value → <strong>one-sample t-test</strong> (or Z-test if you somehow know the true population standard deviation, which in practice you almost never do)</li><li>Two related measurements on the same subjects (before/after) → <strong>paired t-test</strong></li><li>Two independent groups → <strong>two-sample t-test</strong> (or Mann-Whitney U if the data isn’t normally distributed and your sample is small)</li><li>Three or more groups → <strong>ANOVA</strong></li></ul><p><strong>Do your data meet the test’s assumptions?</strong> Most of these tests assume your variable is roughly normally distributed, or that your sample is large enough that it doesn’t matter (thanks to the Central Limit Theorem, more below). If those assumptions break down — small sample, skewed distribution, unequal variances — there’s almost always a non-parametric or adjusted alternative: Welch’s t-test instead of Student’s t-test when variances are unequal, Mann-Whitney U instead of a t-test when normality fails entirely, Fisher’s Exact Test instead of Chi-Square when your sample sizes are small.</p><p>Here’s the condensed map I keep in my head:</p><p><strong>Does my sample mean differ from a known population mean?</strong> <em>(continuous)</em> → One-sample t-test</p><p><strong>Did a treatment change the same group’s before/after values?</strong> <em>(continuous)</em> → Paired t-test</p><p><strong>Do two independent groups differ in their average?</strong> <em>(continuous)</em> → Two-sample t-test (or Welch’s / Mann-Whitney if assumptions don’t hold)</p><p><strong>Do three or more groups differ in their average?</strong> <em>(continuous)</em> → ANOVA</p><p><strong>Does my sample’s category distribution match an expected one?</strong> <em>(categorical)</em> → Chi-Square Goodness-of-Fit</p><p><strong>Are two categorical variables associated?</strong> <em>(categorical)</em> → Chi-Square Independence Test</p><p><strong>How strongly are two continuous variables linearly related?</strong> <em>(continuous)</em> → Pearson Correlation</p><h3>3. A/B Testing Is Just Hypothesis Testing With a Business Name</h3><p>If you’ve internalized section 1, A/B testing isn’t a separate topic — it’s a two-sample hypothesis test wearing a product-management hat. You’re comparing a metric (conversion rate, click-through rate, average session length) across a control group and a treatment group, and asking whether the difference is real or just noise.</p><p>The test you pick still depends on your metric type:</p><ul><li><strong>Binary outcome</strong> (clicked or didn’t, converted or didn’t) with small samples → <strong>Fisher’s Exact Test</strong></li><li><strong>Binary outcome</strong> with large samples → <strong>Chi-Square test</strong></li><li><strong>Continuous outcome</strong> (revenue per user, time on page) → <strong>Student’s or Welch’s t-test</strong></li></ul><p>The part people skip, and shouldn’t: deciding your significance level, minimum detectable effect, and required sample size <em>before</em> running the experiment — not peeking at results daily until something looks significant. That’s how you accidentally inflate your false-positive rate without meaning to.</p><h3>4. The Distributions Worth Actually Knowing</h3><p>You don’t need to memorize every named distribution, but a handful cover almost every real scenario:</p><ul><li><strong>Binomial</strong> — number of successes in a fixed number of yes/no trials. <em>Example: out of 200 checkout attempts, how many succeed on the first try if each has an 85% success rate?</em></li><li><strong>Poisson</strong> — number of events in a fixed window of time or space, when events happen independently at a known average rate. <em>Example: a support inbox that averages 12 tickets per hour — what’s the chance it gets more than 20 in the next hour?</em></li><li><strong>Exponential</strong> — the <em>waiting time</em> until the next event in a Poisson process. It’s the continuous cousin of Poisson: Poisson counts events, exponential measures the gap between them.</li><li><strong>Normal (Gaussian)</strong> — the bell curve, and the backbone of most parametric tests. Defined entirely by its mean and standard deviation, and famous for the <strong>68–95–99.7 rule</strong>: about 68% of values fall within 1 standard deviation of the mean, 95% within 2, and 99.7% within 3.</li></ul><p>Two ideas tie all of these together and are worth knowing cold:</p><p><strong>The Central Limit Theorem (CLT)</strong>: no matter what distribution your underlying data follows, if you repeatedly take samples and compute their means, those sample means will approach a normal distribution as your sample size grows. This is <em>why</em> so many tests get to assume normality even when the raw data is messy — it’s not the data that needs to be normal, it’s the sampling distribution of the statistic you’re computing.</p><p><strong>Z-scores</strong>: standardizing any normal distribution to one with mean 0 and standard deviation 1. Once something is in z-score terms, you can compare wildly different scales (test scores vs. salaries vs. response times) on the same footing, and look up probabilities from a single standard table instead of a different one for every possible mean and variance.</p><h3>5. Correlation: The Test Everyone Half-Remembers From School</h3><p>Pearson correlation measures the strength and direction of a <em>linear</em> relationship between two continuous variables, producing a value between -1 and 1:</p><ul><li><strong>+1</strong>: perfect positive linear relationship</li><li><strong>0</strong>: no linear relationship</li><li><strong>-1</strong>: perfect negative linear relationship</li></ul><p>The formula itself is just a normalized version of covariance — how much two variables move together, scaled by how much each moves on its own:</p><pre>r = Σ(Xᵢ - X̄)(Yᵢ - Ȳ) / √[Σ(Xᵢ - X̄)² · Σ(Yᵢ - Ȳ)²]</pre><p>Two things trip people up here. First: correlation only captures <em>linear</em> relationships — two variables can be perfectly related in a curved, non-linear way and still show a Pearson correlation near zero. Second, and more famous: <strong>correlation is not causation.</strong> A strong correlation tells you two variables move together, not that one causes the other — there could be a third, unmeasured variable driving both.</p><pre>from scipy.stats import pearsonr</pre><pre>corr, p_value = pearsonr(x, y)</pre><h3>6. Bayes’ Theorem, in One Practical Frame</h3><p>Bayes’ theorem answers a very specific and very useful question: <em>given some new evidence, how should I update what I believed beforehand?</em></p><pre>P(A|B) = P(B|A) · P(A) / P(B)</pre><ul><li>P(A) is your <strong>prior</strong> — what you believed before seeing the evidence</li><li>P(B|A) is the <strong>likelihood</strong> — how probable the evidence is if A is true</li><li>P(A|B) is the <strong>posterior</strong> — your updated belief after seeing the evidence</li></ul><p>The classic example that makes this click: a medical test with a 5% false-positive rate sounds accurate, but if the underlying condition is rare (say 1% of the population), most positive results will still be false positives — because there are so many more healthy people than sick ones to begin with. Run the numbers and a positive test only means roughly a 15% chance of actually having the condition, not 95%. This “base rate” trap shows up constantly outside medicine too — fraud detection, spam filters, anomaly detection — anywhere you’re flagging a rare event using an imperfect signal.</p><h3>7. The Boring-but-Load-Bearing Basics</h3><p>A few concepts that don’t sound exciting but quietly underpin everything above:</p><ul><li><strong>Mean vs. median</strong>: the mean is pulled around by outliers; the median isn’t. When you see income, latency, or house-price data — anything with a long tail — reach for the median first.</li><li><strong>IQR and outliers</strong>: the interquartile range (the middle 50% of your data) gives you a robust way to flag outliers — anything more than 1.5× the IQR beyond the first or third quartile is typically flagged.</li><li><strong>Confidence intervals</strong>: instead of a single point estimate, a range that’s likely to contain the true population value. A 95% CI doesn’t mean “95% chance the true value is in this range” (a common misreading) — it means if you repeated the sampling process many times, about 95% of the intervals you’d construct would contain the true value.</li></ul><h3>Putting It Together</h3><p>None of this is exotic. The actual skill of “doing statistics” in a data science role is less about knowing more formulas and more about correctly answering three questions before you touch a library function: <em>what type of variable am I working with, how many groups am I comparing, and what assumptions am I allowed to make about the underlying distribution? </em>Get those three answers right, and the choice of test almost picks itself.</p><p>If you’re prepping for interviews or just refreshing rusty fundamentals, I’d rather revisit this decision framework once a month than re-memorize formulas I’ll forget again in a week.</p><p><em>This post grew out of my own notes while revisiting statistics fundamentals — shaped in part by a few excellent primers from StrataScratch’s blog on </em><a href="https://www.stratascratch.com/blog/basic-types-of-statistical-tests-in-data-science"><em>statistical tests</em></a><em>, </em><a href="https://www.stratascratch.com/blog/a-comprehensive-statistics-cheat-sheet-for-data-science-interviews"><em>the statistics interview cheat sheet</em></a><em>, </em><a href="https://www.stratascratch.com/blog/random-variables-and-probability-distributions"><em>probability distributions</em></a><em>, and </em><a href="https://www.stratascratch.com/blog/commonly-used-statistical-tests-in-data-science"><em>commonly used tests</em></a><em> — worth a read if you want to go deeper on any one section.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfeac99390f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Tree-Based Models: A Comprehensive Guide]]></title>
            <link>https://medium.com/@sanjanabansal1994/understanding-tree-based-models-a-comprehensive-guide-deb6c6d983d6?source=rss-fde144ab5e9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/deb6c6d983d6</guid>
            <category><![CDATA[decision-tree-classifier]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[decision-tree-regression]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[random-forest]]></category>
            <dc:creator><![CDATA[Sanjana Garg]]></dc:creator>
            <pubDate>Fri, 19 Jul 2024 02:53:59 GMT</pubDate>
            <atom:updated>2024-07-19T02:56:46.748Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IHXSq9juiTn2DmmPLnJfdw.png" /></figure><p>Tree-based models are powerful tools in the machine learning arsenal, capable of handling complex datasets and delivering interpretable results. This guide explores the nuances of tree-based models, focusing on key techniques and algorithms such as recursive binary splitting, tree pruning, cost complexity pruning, classification trees, and ensemble methods like bagging, random forests, boosting, and Bayesian Additive Regression Trees (BART).</p><h4><strong>Recursive Binary Splitting: The Foundation of Tree Models:</strong></h4><p>Tree-based models start with a top-down, greedy approach known as recursive binary splitting. At each step of the tree-building process, the best split is made based on the current dataset without considering future splits. This approach involves evaluating all predictors and possible cut points to minimize the Residual Sum of Squares (RSS). While effective, this method can lead to overfitting as it focuses solely on the immediate best split.</p><p><strong>Tree Pruning : Preventing Overfitting: </strong>To address overfitting, tree pruning is employed. The basic idea is to stop growing the tree when the decrease in RSS from a split is below a certain threshold. This method ensures that the tree remains generalizable and not overly complex.</p><p><strong><em>Cost Complexity Pruning</em></strong>: Cost complexity pruning, also known as weakest link pruning, refines the tree further. It introduces a nonnegative tuning parameter, α, to balance the trade-off between the tree’s complexity and its fit to the training data. As α increases, the penalty for additional terminal nodes grows, resulting in a smaller, more optimal subtree</p><h4><strong>Algorithm for Building a Regression Tree</strong></h4><ol><li><strong><em>Grow a Large Tree</em></strong>: Use recursive binary splitting to grow a large tree, stopping when each terminal node has fewer than a minimum number of observations.</li><li><strong><em>Prune the Tree</em></strong>: Apply cost complexity pruning to obtain a sequence of best subtrees based on α.</li><li><strong><em>Select Optimal Subtree Using Cross-Validation</em></strong>: Use K-fold cross-validation to choose the best α. Repeat the tree-growing and pruning process on all but the kth fold and evaluate the mean squared prediction error on the left-out fold.</li><li><strong><em>Return Optimal Subtree</em></strong>: Select the subtree corresponding to the optimal α.</li></ol><h4>Classification Trees: Predicting Categories</h4><p>For classification tasks, tree models predict the most commonly occurring class in a terminal node. Instead of RSS, classification trees use the classification error rate, Gini index, or entropy as criteria for splits.</p><p><strong><em>Gini Index: </em></strong>It measures the total variance across classes, with a lower value indicating a purer node. It is calculated as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*4lqd_MWeXQa0xVwmE_jR-Q.png" /></figure><p><strong><em>Entropy: </em></strong>It quantifies the uncertainty in a node, with lower values indicating purer nodes. It is calculated as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*NeWOiclNcSlyfx2vAqCqmQ.png" /></figure><h4><strong>Pros and Cons of Decision Trees</strong></h4><p><strong><em>Pros</em></strong></p><ol><li><strong><em>Interpretability</em></strong>: Trees are easy to explain and interpret, even for non-experts.</li><li><strong><em>Human-Like Decision Making</em></strong>: They mirror human decision-making processes.</li><li><strong><em>Graphical Representation</em></strong>: Trees can be visually represented for better understanding.</li><li><strong><em>Handling Qualitative Predictors</em></strong>: Trees handle categorical variables without needing dummy variables.</li></ol><p><strong><em>Cons</em></strong></p><ol><li><strong><em>Lower Predictive Accuracy</em></strong>: Trees often have lower predictive accuracy compared to other models.</li><li><strong><em>Non-Robustness</em></strong>: Small data changes can significantly alter the tree structure, leading to overfitting.</li></ol><h4>Ensemble Methods: Enhancing Tree Performance</h4><p><strong>Bagging<em>: </em></strong>It involves growing multiple trees on random samples of the data and averaging the predictions. While effective, trees in bagging can be highly correlated.</p><p><strong>Random Forests:</strong> It address this by using random subsets of features for each split, decorrelating the trees and improving reliability. The parameter mm controls the number of features considered, with m=p being a common choice.</p><p><strong>Boosting: </strong>It builds trees sequentially, each correcting errors from the previous one. The algorithm involves:</p><ol><li><strong><em>Initialize</em></strong> predictions and residuals.</li><li><strong><em>Iteratively Fit Trees</em></strong>: Fit a tree to the residuals, update the predictions, and calculate new residuals.</li><li><strong><em>Output</em></strong> the final model as the weighted sum of all trees.</li></ol><p>Boosting has three tuning parameters: the number of trees ‘B’, the shrinkage parameter ‘λ’, and the number of splits ‘d’ in each tree.</p><p><strong>Bayesian Additive Regression Trees (BART): </strong>BART combines Bayesian methods with tree ensembles. It iteratively fits trees by perturbing previous trees to avoid local minima, enhancing model space exploration. The algorithm involves:</p><ol><li><strong><em>Initialize</em></strong> trees and compute predictions.</li><li><strong><em>Iteratively Fit and Perturb Trees</em></strong>: Update partial residuals, fit new trees, and perturb existing trees.</li><li><strong><em>Compute Final Predictions</em></strong> after burn-in iterations.</li></ol><h3>Summary</h3><p>Tree-based models, from simple decision trees to advanced ensemble methods like random forests, boosting, and BART, offer versatile tools for regression and classification tasks. While individual trees are interpretable and handle qualitative predictors well, ensemble methods improve predictive accuracy and robustness, making tree-based models a crucial component of modern machine learning.</p><p><em>Resources: Introduction to Statistical Learning Python</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=deb6c6d983d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Extensions of Linear Models]]></title>
            <link>https://medium.com/@sanjanabansal1994/simple-extensions-of-linear-models-9ba831d4c7db?source=rss-fde144ab5e9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ba831d4c7db</guid>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sanjana Garg]]></dc:creator>
            <pubDate>Fri, 12 Jul 2024 03:14:35 GMT</pubDate>
            <atom:updated>2024-07-20T05:29:10.869Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*ZUSxyxT4tn49eyMrrsiIow.png" /></figure><p>I was recently going through the book ISLP and author discussed about how a standard linear regression can have significant limitations in terms of predictive power. If we relax the linearity assumption while still attempting to maintain as much interpretability as possible. We can adopt one of the following extensions:</p><ul><li><strong><em>Polynomial regression</em></strong><em> </em>extends the linear model by adding extra predictors, obtained by raising each of the original predictors to a power.For example, a cubic regression uses three variables, X, X2, and X3, as predictors. This approach provides a simple way to provide a nonlinear fit to data.</li><li><strong><em>Step functions</em></strong><em> </em>cut the range of a variable into K distinct regions in order to produce a qualitative variable. This has the effect of fitting a piecewise constant function.</li><li><strong><em>Regression splines</em></strong><em> </em>are more flexible than polynomials and step functions, and in fact are an extension of the two. They involve dividing the range of X into K distinct regions. Within each region, a polynomial function is fit to the data. However, these polynomials are constrained so that they join smoothly at the region boundaries or knots. Provided that the interval is divided into enough regions, this can produce an extremely flexible fit.</li><li><strong><em>Smoothing splines </em></strong>are similar to regression splines, but arise in a slightly different situation. Smoothing splines result from minimizing a residual sum of squares criterion subject to a smoothness penalty.</li><li><strong><em>Local Regression</em></strong> is similar to splines, but differs in an important way. The regions are allowed to overlap, and indeed they do so in a very smooth way.</li><li><strong><em>Generalized Additive Models</em></strong> allow us to extend the methods above to deal with multiple predictors.</li></ul><p><em>Source: Introduction to Statistical Learning using Python</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ba831d4c7db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparing the Performance of Logistic Regression, LDA, QDA, Naive Bayes, and KNN]]></title>
            <link>https://medium.com/@sanjanabansal1994/comparing-the-performance-of-logistic-regression-lda-qda-naive-bayes-and-knn-e3e7877b6a97?source=rss-fde144ab5e9b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3e7877b6a97</guid>
            <category><![CDATA[binary-classification]]></category>
            <category><![CDATA[classification-models]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sanjana Garg]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 05:27:26 GMT</pubDate>
            <atom:updated>2024-07-05T05:27:26.917Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I would like to share some thoughts on the empirical performance of several classification methods: logistic regression, Linear Discriminant Analysis (LDA), Quadratic Discriminant Analysis (QDA), naive Bayes, and k-Nearest Neighbours (KNN). These methods are examined across six different scenarios involving binary (two-class) classification problems. In three scenarios, the Bayes decision boundary is linear, while in the remaining three, it is non-linear. For each scenario, consider 100 random training data sets and compute the test error rate on a large test set. The results for linear scenarios are shown in Figure 1, and the results for non-linear scenarios are in Figure 2.</p><figure><img alt="Fig 1: Boxplots of the test error rates for each of the linear scenarios" src="https://cdn-images-1.medium.com/max/1024/1*V_X-hxvnVx4GctJx_GiZvg.png" /><figcaption>Figure 1:<em>Boxplots of the test error rates for each of the linear scenarios</em></figcaption></figure><h3>Scenarios and Results</h3><h4>Linear Scenarios</h4><ul><li><strong>Scenario 1</strong>: 20 observations per class, uncorrelated random normal variables with different means.</li><li><strong>Results</strong>: LDA and logistic regression performed well. KNN performed poorly due to high variance. QDA also underperformed, as it fits a more flexible model than needed. Naive Bayes performed slightly better than QDA, benefiting from the correct independence assumption.</li><li><strong>Scenario 2</strong>: Same as Scenario 1, but with a correlation of -0.5 between predictors. <strong>Results</strong>: Performance was similar to Scenario 1, except naive Bayes performed poorly due to violated independence assumption.</li><li><strong>Scenario 3</strong>: Substantial negative correlation, predictors from the t-distribution, 50 observations per class. <strong>Results</strong>: Logistic regression outperformed LDA, both superior to other methods. QDA performed poorly due to non-normality, and naive Bayes was affected by the independence assumption violation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LxVyGU7F-eBSpW9GzL0xlg.png" /><figcaption>Figure 2: <em>Box plots of the test error rates for each of the non-linear scenarios</em></figcaption></figure><h4>Non-Linear Scenarios</h4><ul><li><strong>Scenario 4</strong>: Normal distribution, correlation of 0.5 in one class and -0.5 in the other, quadratic decision boundaries. <strong>Results</strong>: QDA outperformed other methods. Naive Bayes performed poorly due to violated independence assumption.</li><li><strong>Scenario 5</strong>: Normal distribution, uncorrelated predictors, responses sampled from a non-linear logistic function. <strong>Results</strong>: QDA and naive Bayes gave better results than linear methods, but KNN-CV performed best. KNN with K=1K=1 performed worst, highlighting the need for correct smoothness level in non-parametric methods.</li><li><strong>Scenario 6</strong>: Normal distribution with different diagonal covariance matrices, small sample size (n=6 per class). <strong>Results</strong>: Naive Bayes performed well due to met assumptions. LDA and logistic regression performed poorly due to non-linear decision boundary. QDA and KNN suffered from high variance due to small sample size.</li></ul><h3>Conclusion</h3><p>These scenarios illustrate that no single method outperforms others in all situations. Linear methods like LDA and logistic regression excel when decision boundaries are linear. For moderately non-linear boundaries, QDA or naive Bayes may perform better. For complex decision boundaries, non-parametric approaches like KNN can be superior, provided the smoothness level is chosen correctly.</p><p><em>Source: An Introduction to Statistical Learning with Python</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3e7877b6a97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>