<?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 Yash vasudeva on Medium]]></title>
        <description><![CDATA[Stories by Yash vasudeva on Medium]]></description>
        <link>https://medium.com/@vasudevyash?source=rss-4faa79d6331a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_CdjQsqpdu4umm01</url>
            <title>Stories by Yash vasudeva on Medium</title>
            <link>https://medium.com/@vasudevyash?source=rss-4faa79d6331a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 22:12:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vasudevyash/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[Why Accuracy is the Most Misleading Metric in Machine Learning?]]></title>
            <link>https://medium.com/@vasudevyash/why-accuracy-is-the-most-misleading-metric-in-machine-learning-e2cbebbd7237?source=rss-4faa79d6331a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2cbebbd7237</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[experimentation]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Yash vasudeva]]></dc:creator>
            <pubDate>Thu, 10 Sep 2026 05:55:10 GMT</pubDate>
            <atom:updated>2026-09-10T05:55:10.237Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of Machine Learning, “Accuracy” is the celebrity metric. It is the first number beginners look at, the first number stakeholders ask for, and, almost always, the first number that lies straight to your face. Every person who starts working with ML algorithms assumes that a model is well-trained and well-generalized if its accuracy is high.</p><p>But here is the truth, and it is uncomfortable: <strong>Accuracy tells you how often a model is correct — not how it is correct.</strong></p><p>This is not a theoretical concern. It is a practical trap that has sent real-world ML projects in entirely the wrong direction — from fraud detection systems that miss fraudulent transactions, to medical models that never actually learn to identify disease. This blog walks through a structured experiment designed to expose exactly how far accuracy can mislead you, using real datasets, real models, and the kind of hard numerical evidence that makes the case impossible to ignore.</p><h3>1. The Basics: What Accuracy Actually Measures</h3><p>Accuracy is deceptively simple. It is just the ratio of correct predictions to total predictions.</p><p><strong>Accuracy = Correct Predictions / Total Predictions</strong></p><p>Simple. Clean. And in many situations, it is dangerous.</p><p>Here is the critical flaw: <strong>Accuracy treats every mistake as equally important.</strong> A wrong prediction on a healthy patient and a wrong prediction on a critically ill patient are counted exactly the same. A flagged spam email and a missed phishing attack — counted the same.</p><p>In a perfectly balanced world where both classes appear equally, accuracy is a perfectly reasonable metric. But the real world is never perfectly balanced. Consider:</p><p>● <strong>Fraud Detection</strong> — Only 0.1% of transactions may be fraudulent. A model that predicts “not fraud” for everything achieves 99.9% accuracy and catches zero fraudsters.</p><p>● <strong>Medical Diagnosis</strong> — If 95% of patients are healthy, a model predicting “healthy” every time scores 95% accuracy and has never once diagnosed a disease.</p><p>● <strong>Spam Filtering</strong> — A permissive model that lets everything through has excellent accuracy on legitimate email but fails completely at its actual job.</p><p>In each of these cases, a model can sit comfortably at high accuracy while completely failing to detect the minority class. The number looks impressive. The behavior is catastrophic.</p><h3>2. The Experiment: Building a Proper Test</h3><p>To move beyond theory, a structured benchmarking experiment was conducted across two fundamentally different problem types — classification and regression — using real, publicly available datasets.</p><p><strong>Datasets Used:</strong></p><p>● <strong>Adult Census Income Dataset (OpenML)</strong> — A classification task predicting whether an individual earns more than $50K per year, based on demographic and employment features.</p><p>● <strong>California Housing Dataset</strong> — A regression task predicting median house prices based on geographic and socioeconomic features.</p><p><strong>Why these datasets?</strong> Because both are realistic, widely studied, and structurally interesting. The Census dataset is naturally imbalanced — the majority of individuals in the dataset earn below $50K, making the high-earner class the minority. The Housing dataset introduces continuous prediction, where the failure modes are different but equally deceptive.</p><p><strong>Technical Setup:</strong></p><p>A clean, production-style pipeline was built using scikit-learn’s Pipeline and ColumnTransformer. This is important for two reasons. First, it prevents data leakage — preprocessing steps like scaling are fit only on training data and applied to test data, not the other way around. Second, it ensures that every model is evaluated on identically preprocessed data, making comparisons genuinely fair.</p><p>For mixed data types, the preprocessing pipeline handled:</p><p>● <strong>Numerical Features</strong> — Standardized using StandardScaler</p><p>● <strong>Categorical Features</strong> — Encoded using OneHotEncoder with handle_unknown=’ignore’ to manage unseen categories gracefully</p><p>A <strong>Stratified Train-Test Split</strong> (70/30) was used throughout, ensuring that class proportions in the training set and test set mirror the original dataset. This is a non-negotiable step when dealing with imbalanced data — a random split can accidentally concentrate the minority class in one split and completely distort your evaluation.</p><h3>3. Classification Results: The Accuracy Trap in Action</h3><p>Six classifiers were benchmarked on the Census Income dataset:</p><p>● Logistic Regression</p><p>● Decision Tree Classifier</p><p>● Random Forest Classifier</p><p>● K-Nearest Neighbours</p><p>● Support Vector Classifier (SVC)</p><p>● AdaBoost Classifier</p><p>Each model was evaluated on four metrics: <strong>Accuracy, Precision, Recall, and F1-Score</strong>.</p><p><strong>What the numbers showed:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*dDQV3VGlAtgERnAe9TMRRA.png" /></figure><p>On the surface, the results looked remarkable. Models like SVC and Random Forest reported accuracy scores hovering around <strong>86%</strong>. In a boardroom presentation, this is a success story — high accuracy, high precision, everything looks great.</p><p>But then you look at Recall. And the story falls apart.</p><p>Recall for SVC and Random Forest sat around <strong>59%–61%</strong>. That means these models, despite their impressive accuracy, were <strong>failing to identify nearly 40% of high earners</strong> — the exact class the problem was built to detect.</p><p>This is the Accuracy Trap in its purest form. The models learned to be very good at identifying the majority class (people who earn below $50K). They were mediocre, at best, at identifying the minority class (people who earn above $50K). Accuracy masked this completely because the majority class dominated the score.</p><p><strong>Why does this happen?</strong></p><p>Because predicting the majority class is the easiest path to high accuracy. The model does not need to learn anything subtle or complex — it just needs to learn the dominant pattern. And when the dataset is imbalanced, that dominant pattern is simply “predict the majority class.” The model exploits the imbalance rather than solving the problem.</p><p>The F1-Score confirmed this. F1, being the harmonic mean of Precision and Recall, was pulled down sharply by the low Recall, exposing the gap that accuracy concealed.</p><p><strong>Visualizing the Evidence:</strong></p><p>A grouped bar chart was generated using Seaborn and Matplotlib, comparing all four metrics across all six models. The results DataFrame was melted into long-form format with hue=”Metric” to allow side-by-side metric comparison per model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q1zj3rZcKyTuz9zGfILdKA.png" /></figure><p>The visual was telling. Accuracy sat consistently at the top — stable, optimistic, almost reassuring. Recall and F1-Score, meanwhile, fluctuated significantly across models, sometimes dropping 25–30 percentage points below accuracy for the same model. This is not noise. This is systematic deception, and the bar chart made it undeniable.</p><p>Different models showed nearly identical accuracy scores, yet their ability to detect the minority class varied drastically. If you were choosing a model based on accuracy alone, you would have made the wrong choice.</p><h3>4. Regression Results: A Different Kind of Deception</h3><p>The second half of the experiment shifted to the California Housing dataset, where the problem is no longer classification but price prediction — a continuous regression task.</p><p><strong>Feature Engineering:</strong></p><p>Before modelling, a custom categorical feature called IncomeLevel was engineered by binning MedInc (Median Income) into five ordinal categories using pd.cut:</p><p>● Very Low</p><p>● Low</p><p>● Medium</p><p>● High</p><p>● Very High</p><p>This enriched the dataset with a domain-relevant categorical signal and allowed the pipeline’s ColumnTransformer to demonstrate handling mixed feature types simultaneously — numerical scaling and categorical encoding happening in a single, leak-free step.</p><p><strong>Seven regressors were benchmarked:</strong></p><p>● Linear Regression</p><p>● Decision Tree Regressor</p><p>● Random Forest Regressor</p><p>● Gradient Boosting Regressor</p><p>● AdaBoost Regressor</p><p>● K-Nearest Neighbours Regressor</p><p>● Support Vector Regressor (SVR)</p><p><strong>Evaluation Metrics:</strong></p><p>● <strong>MSE</strong> (Mean Squared Error)</p><p>● <strong>MAE</strong> (Mean Absolute Error)</p><p>● <strong>R² Score</strong></p><p><strong>What the numbers showed:</strong></p><p>In regression, the failure mode was different — but just as important. Some models produced high R² scores that looked reassuring at first glance. But when error metrics were examined side by side, a more complicated picture emerged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*z8O237_2qbr7mrBOdKhcuQ.png" /></figure><p>Models with similar R² values produced <strong>very different MAE and RMSE values</strong>. This is significant. R² measures how much variance in the target your model explains — it is a relative measure of fit. But it tells you nothing about the magnitude of your errors in practical terms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b34DVt5L0oAWR080EmYBeg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*uDgXmQgWSzt-Z7EUDUzPzw.png" /></figure><p>RMSE, on the other hand, penalises large errors disproportionately. A model with a respectable R² could still produce dramatically large RMSE values if it was making occasional massive errors on high-value or outlier properties. In housing price prediction, that kind of error is not a statistical footnote — it is a real financial miscalculation.</p><p>The experiment clearly demonstrated that <strong>R² alone gave a false sense of safety</strong>. Two models could show nearly identical R² scores while one had an RMSE twice as large as the other. If you stopped at R², you would never know.</p><p>In regression, the danger is not metric disagreement. It is <strong>metric comfort</strong> — the feeling that because one number looks good, everything must be fine.</p><h3>5. What Does “Good Evaluation” Actually Mean?</h3><p>Many beginners think evaluating a model just means checking accuracy or R². Real evaluation power comes from using the right set of metrics for the right problem — and knowing what each one is actually telling you.</p><p><strong>For Classification:</strong></p><p>● <strong>Precision</strong> — Of all the samples your model flagged as positive, how many were actually positive? High precision means low false alarm rate.</p><p>● <strong>Recall</strong> — Of all the actual positive cases, how many did your model correctly catch? High recall means low miss rate. This is the metric that matters most in medical diagnosis, fraud detection, and safety-critical applications.</p><p>● <strong>F1-Score</strong> — The harmonic mean of Precision and Recall. It forces a balance between the two. A model cannot game F1 by sacrificing one for the other.</p><p>● <strong>Confusion Matrix</strong> — The complete breakdown of True Positives, True Negatives, False Positives, and False Negatives. It does not aggregate — it shows you exactly where and how the model is failing.</p><p><strong>For Regression:</strong></p><p>● <strong>MAE (Mean Absolute Error)</strong> — The average magnitude of errors, in the same units as the target. Interpretable, robust to outliers.</p><p>● <strong>RMSE (Root Mean Squared Error)</strong> — Penalises large errors more heavily. Critical when big mistakes are disproportionately costly.</p><p>● <strong>R² Score</strong> — Useful as a relative measure of fit, but never sufficient on its own. Always pair with error magnitude metrics.</p><p><strong>The rule of thumb:</strong> Let the problem define the metric. Do not let the metric define what you consider success.</p><h3>6. The Real Takeaway</h3><p>This experiment reinforces a fundamental law of ML evaluation: <strong>The metric is the lens. Choosing the wrong lens blinds you.</strong></p><p>You can spend weeks building a sophisticated pipeline, tune your hyperparameters carefully, achieve state-of-the-art accuracy — and still walk away with completely the wrong conclusion, simply because you only looked at one number.</p><p>The algorithm is the engine. The data is the fuel. But the metric is the <strong>dashboard</strong>. If your dashboard only shows you speed and ignores engine temperature, oil pressure, and fuel level, you will drive confidently straight into a breakdown.</p><p>Here is what this experiment proved, concretely:</p><p>● Models with 86% accuracy were missing <strong>4 in 10</strong> high-income individuals.</p><p>● Models with similar R² scores had <strong>wildly different real-world error magnitudes</strong>.</p><p>● Accuracy remained stable and optimistic while Recall and F1-Score exposed systematic failure.</p><p>● A simple algorithm evaluated well will always outperform a complex algorithm evaluated poorly.</p><p>The model is not the problem. The evaluation is.</p><h3>7. Solutions: Metrics That Keep You Honest</h3><p>Here are the most effective practices for avoiding the accuracy trap entirely:</p><ol><li><strong>Always report a full metric suite.</strong> For classification, report Accuracy, Precision, Recall, F1-Score, and the Confusion Matrix together. A single metric in isolation is always suspect.</li><li><strong>Define your critical metric before training.</strong> If missing a positive case is more costly than a false alarm, Recall is your primary metric. Define this upfront, before you see any results, so the metric guides your decisions rather than being chosen post-hoc to justify them.</li><li><strong>Use Stratified Splits.</strong> Always use stratified train-test splitting on imbalanced datasets. This ensures both splits reflect real-world class proportions and prevents accidental imbalance in your evaluation set.</li><li><strong>Use RMSE alongside R² in regression.</strong> R² tells you about fit. RMSE tells you about error magnitude. Both are necessary. Neither is sufficient alone.</li><li><strong>Plot your metrics, don’t just tabulate them.</strong> A grouped bar chart comparing metrics across models reveals patterns — like accuracy being consistently optimistic while Recall fluctuates — that a results table alone makes easy to miss.</li><li><strong>Use Pipelines with ColumnTransformer.</strong> Beyond methodology, this is also an evaluation best practice. When preprocessing steps are built into the pipeline, you eliminate the risk of data leakage contaminating your evaluation, which is one of the most common and most invisible sources of falsely optimistic metrics.</li><li><strong>Examine the Confusion Matrix before drawing any conclusions.</strong> The confusion matrix does not lie. It shows you exactly how many times the model said “yes” when it should have said “no,” and how many times it said “no” when it should have said “yes.” These four numbers tell a story that no aggregate metric can fully capture.</li></ol><p>Even if accuracy remains a useful first-pass sanity check, it should never be the final word. In the real world, the cases your model gets wrong matter far more than the cases it gets right — and the only way to know which cases those are is to look beyond the single number that feels the most comfortable.</p><p>Which metric shift had the most impact on how you evaluated your own models? Try re-running your existing classifiers using Precision, Recall, F1, and a Confusion Matrix — and see what accuracy was hiding all along.</p><p><a href="https://github.com/yashvasudeva1/metric_trap">https://github.com/yashvasudeva1/metric_trap</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2cbebbd7237" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Data, is the Real Power Behind ML & AI]]></title>
            <link>https://medium.com/@vasudevyash/why-data-is-the-real-power-behind-ml-ai-49c20bae4682?source=rss-4faa79d6331a------2</link>
            <guid isPermaLink="false">https://medium.com/p/49c20bae4682</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Yash vasudeva]]></dc:creator>
            <pubDate>Mon, 07 Sep 2026 03:27:18 GMT</pubDate>
            <atom:updated>2026-09-07T03:27:18.061Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of Artificial Intelligence, the &quot;model&quot; is the celebrity. We celebrate the release of new neural architectures, larger parameter counts, and complex layers. But behind every high-performing AI is a quiet, hardworking foundation: the data.The truth is often overlooked: Better data beats better algorithms-almost every time.</p><h3>1. The Basics: Data as a &quot;Version&quot; of Reality</h3><blockquote>At its core, data is a recorded representation of real-world observations. Whether it is measurements, categories, language, or signals, data is simply our world translated into numbers, labels, and symbols.<br>Here is the critical distinction: Models don’t learn the world; they learn your data’s version of the world.<br>If your data is a distorted mirror, the model’s &quot;intelligence&quot; will be equally distorted. If the data is messy, statistically unstable, or contains impossible values, the model will not pause to ask for clarification. It will simply process that &quot;garbage&quot; and confidently output a wrong answer.</blockquote><h3>2. The Experiment: Testing the &quot;Data vs. Model&quot; Theory</h3><p>To prove that data quality dictates performance more than model complexity, consider a practical experiment using two distinct datasets:<br>Dataset A (The &quot;Noisy&quot; Set): Highly imbalanced.<br>Dataset B (The &quot;Clean&quot; Set): Balanced.<br>The Methodology<br>We train 5 major classifiers on both sets:</p><ol><li>Logistic Regression</li><li>K Nearest Neighbours</li><li>Support Vector Classifier</li><li>Decision Tree Classifier</li><li>Random Forest Classifier</li></ol><p>For each model we compare the 4 metrics: Accuracy, Precision, Recall &amp; F1-Score<br>The Result on Dataset A (Imbalanced)<br>On the surface, the results look amazing. Both the simple and complex models report 90%+ Accuracy and high Precision. In a boardroom, these numbers look like a success.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*Pa2TnAJ1R5fM1s7divw1FA.jpeg" /></figure><p>However, looking deeper at the other metrics, the truth emerges:</p><ul><li>Recall is abysmal.</li><li>F1-Score is dropping sharply.</li><li>The Reality: Because the data was imbalanced, the model &quot;cheated.&quot; It learned to predict the majority class every time. It didn’t learn the features; it learned the bias.</li></ul><h3>3. The Turning Point: Clean Data, Better Behavior</h3><p>When the exact same models-without a single change to their code-are trained on Dataset B (Balanced), the transformation is immediate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*rOVy2sGFu6ow_hIexRVZ0g.jpeg" /></figure><ul><li>Recall and F1-score improve significantly.</li><li>Generalization becomes possible; the model actually identifies the minority class correctly.</li><li>Stability: The performance gap between the simple model and the complex model often narrows, proving that a simple algorithm with great data often outperforms a complex algorithm with poor data.</li></ul><h3>4. What Does &quot;Clean Data&quot; Actually Mean?</h3><p>Many beginners think cleaning data just means removing NULL values or deleting duplicates. Real data power comes from three deeper pillars:<br>Statistical Stability: Ensuring that the variance and mean of your features aren’t skewed by &quot;impossible&quot; outliers or sensor errors.<br>Realistic Distributions: Does the data actually represent the frequency of events in the real world?<br>Balanced Representation: If you are building a medical AI but 99% of your data is from healthy patients, your model will never &quot;see&quot; the disease clearly enough to identify it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DdoYBjk7y_3IZTc7S9r61A.jpeg" /></figure><p>In the above experiment we just considered imbalances and even with that we were able to see such drastic performance differences. Balancing the dataset increased the overall robustness by an average of 34.68%.</p><h3>5. The Real Takeaway</h3><p>The experiment reinforces a fundamental law of AI: The algorithm is the engine, but data is the fuel. You can put a Ferrari engine in a car, but if you fill the tank with swamp water, it won’t move.<br>When data quality improves, models don’t just score better on paper-they behave better in practice. They become reliable, ethical, and functional</p><h3>6. Solutions</h3><p>Some of the most effective techniques that can be used to tackle the problem of imbalance in datasets are:</p><h4>Random Oversampling (duplicating minority samples)</h4><p>Random Oversampling balances an imbalanced dataset by duplicating samples from the minority class until both classes have similar representation. This helps the model learn patterns from the minority class more effectively. However, excessive duplication can sometimes lead to overfitting.</p><h4>Random Undersampling (reducing majority samples)</h4><p>Random Undersampling balances the dataset by removing samples from the majority class. This reduces the dominance of the majority class and forces the model to pay more attention to minority samples. The drawback is that potentially useful information may be lost during removal.</p><h4>SMOTE (Synthetic Minority Oversampling Technique)</h4><p>SMOTE generates synthetic samples of the minority class by interpolating between existing minority data points. Instead of duplicating data, it creates new realistic samples, which helps improve model generalization. It is one of the most widely used techniques for handling class imbalance.</p><h4>Class Weight Adjustment (e.g., class_weight=’balanced’)</h4><p>Class Weight Adjustment modifies the importance of each class during model training. Misclassification of minority class samples is penalized more heavily, encouraging the model to focus on them. Many algorithms support this through parameters like class_weight=’balanced’.</p><h4>Stratified Sampling during train-test split</h4><p>Stratified sampling ensures that both training and testing datasets maintain the same class distribution as the original dataset. This prevents scenarios where one split becomes heavily imbalanced. It provides more reliable and consistent evaluation of model performance.</p><h4>Ensemble methods designed for imbalance (e.g., Balanced Random Forest)</h4><p>Balanced Random Forest is an ensemble technique designed specifically for imbalanced datasets. Each decision tree is trained on a balanced bootstrap sample created through undersampling of the majority class. This allows the model to better learn minority class patterns while maintaining ensemble robustness.</p><p>Even if these techniques may not help in creating the best generalized model which a balanced dataset can create, but in real world scenarios where data can be scarce, they are the way to go!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49c20bae4682" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>