<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vedant Narayan</title>
    <description>The latest articles on DEV Community by Vedant Narayan (@vedantnarayan).</description>
    <link>https://dev.to/vedantnarayan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4009256%2F6757089c-5227-4a97-b35c-36f1b6042f13.png</url>
      <title>DEV Community: Vedant Narayan</title>
      <link>https://dev.to/vedantnarayan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vedantnarayan"/>
    <language>en</language>
    <item>
      <title>The Loss Function Is a Business Decision, Not a Math Default</title>
      <dc:creator>Vedant Narayan</dc:creator>
      <pubDate>Fri, 03 Jul 2026 04:30:00 +0000</pubDate>
      <link>https://dev.to/vedantnarayan/the-loss-function-is-a-business-decision-not-a-math-default-4cd4</link>
      <guid>https://dev.to/vedantnarayan/the-loss-function-is-a-business-decision-not-a-math-default-4cd4</guid>
      <description>&lt;p&gt;I used to think choosing a loss function was a technical detail. Something the framework handled for you.&lt;br&gt;
It isn't. It's one of the most consequential decisions in your entire ML pipeline. And most teams never make it consciously.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why MSE Fails for Classification&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you first learn machine learning, the loss function is Mean Squared Error. It makes sense for regression. But apply it to a churn prediction model and things break fast.&lt;br&gt;
Consider this scenario. Your model predicts 2% churn probability. The account churns. CS never calls. A ₹40 lakh contract walks out the door.&lt;br&gt;
MSE penalty for that failure? &lt;code&gt;(1 - 0.02)² = 0.96&lt;/code&gt;.&lt;br&gt;
Now consider a correct confident prediction — 90% churn, account churns. MSE penalty: &lt;code&gt;(1 - 0.90)² = 0.01&lt;/code&gt;.&lt;br&gt;
The ratio between catastrophic failure and correct confidence is barely 100x. That doesn't feel right. And it isn't.&lt;br&gt;
There's also a structural problem. When you combine the logistic function with MSE, the loss surface goes non-convex. Multiple local minima. Flat regions where gradients vanish. Gradient descent gets lost and never finds the global optimum.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Cross-Entropy Won&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Binary cross-entropy encodes a simple but powerful idea: &lt;strong&gt;being confidently wrong is a different category of failure.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prediction   Actual   CE Loss
0.90         1        -log(0.90) = 0.10   &amp;lt;- minimal
0.50         1        -log(0.50) = 0.69   &amp;lt;- moderate
0.02         1        -log(0.02) = 3.91   &amp;lt;- catastrophic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The penalty isn't linear or quadratic. It's logarithmic which means confident wrong predictions get hit exponentially harder.&lt;/p&gt;

&lt;p&gt;Cross-entropy won for three principled reasons:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Mathematical harmony.&lt;/strong&gt; Combine cross-entropy with the logistic function and you get a perfectly convex loss surface. One bowl. One global minimum. Gradient descent always finds it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Maximum Likelihood Estimation.&lt;/strong&gt; Minimizing cross-entropy is equivalent to maximizing the likelihood of your training data under the model, the most principled framework in statistics, formalized by R.A. Fisher in 1922.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Calibrated probabilities.&lt;/strong&gt; A model trained with cross-entropy learns to produce probabilities that reflect reality. Its 0.8 prediction actually means roughly 80% of similar cases converted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But Cross-Entropy Is Still Symmetric&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's what most tutorials skip.&lt;/p&gt;

&lt;p&gt;Cross-entropy treats false positives and false negatives equally. Your business almost certainly doesn't.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzzhnbgt6gvwn2qkwftqh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzzhnbgt6gvwn2qkwftqh.png" alt=" " width="771" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These are not the same cost. Yet your model punishes them identically by default.&lt;/p&gt;

&lt;p&gt;These are not the same cost. Yet your model punishes them identically by default.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two levers to fix this:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lower the threshold&lt;/strong&gt; from 0.5 to 0.2. Flag more accounts. Miss fewer churners. Accept more false alarms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use class weights&lt;/strong&gt; to explicitly penalise false negatives harder during training.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The model defaults to 0.5 and balanced classes. If you haven't explicitly overridden that, the model made a business decision for you.&lt;/p&gt;

&lt;p&gt;Did it make the right one?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwjsl8kkvl0kqe09xwxna.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwjsl8kkvl0kqe09xwxna.png" alt=" " width="800" height="973"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>saas</category>
      <category>datascience</category>
      <category>mlengineering</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Every ML Model You'll Ever Build Follows the Same Three Moves</title>
      <dc:creator>Vedant Narayan</dc:creator>
      <pubDate>Tue, 30 Jun 2026 16:30:00 +0000</pubDate>
      <link>https://dev.to/vedantnarayan/every-ml-model-youll-ever-build-follows-the-same-three-moves-20ad</link>
      <guid>https://dev.to/vedantnarayan/every-ml-model-youll-ever-build-follows-the-same-three-moves-20ad</guid>
      <description>&lt;p&gt;I spent years jumping between algorithms without seeing the pattern underneath them.&lt;br&gt;
Linear regression. Logistic regression. Gradient boosting. Neural networks. Each one felt like a separate discipline with its own math, its own intuition, its own debugging headaches.&lt;br&gt;
Then one day it clicked: they're all the same three-step architecture wearing different clothes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hypothesis → Loss → Optimization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's it. That's the whole skeleton.&lt;br&gt;
&lt;strong&gt;Hypothesis&lt;/strong&gt; answers one question: what shape do you think the answer takes?&lt;/p&gt;

&lt;p&gt;For linear regression, your hypothesis is a straight line: y = wx + b. For a decision tree, it's a series of splits. For a neural network, it's a composition of nonlinear functions stacked in layers. Different shapes, same job — propose a function that maps inputs to outputs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Loss&lt;/strong&gt; answers a different question: how wrong is the hypothesis right now?&lt;/p&gt;

&lt;p&gt;Squared error for regression. Cross-entropy for classification. Hinge loss for SVMs. You can even design your own custom loss function if your business problem demands it. The loss function is just a formalized way of saying "here's how much this prediction hurts."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimization&lt;/strong&gt; answers the last question: how do we get less wrong?&lt;/p&gt;

&lt;p&gt;Gradient descent is the most common answer, but it's not the only one. Some problems have closed-form solutions you can solve directly with linear algebra. Some use evolutionary algorithms. Some literally use trial and error at small scale. The optimizer's job is just to nudge the hypothesis toward lower loss, however that nudging gets implemented.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this reframe matters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once I stopped asking "what algorithm should I use?" and started asking "what's my hypothesis, what's my loss, what's my optimization?", model selection got a lot less mysterious.&lt;br&gt;
It also made debugging faster. If a model isn't learning, I no longer guess randomly. I check each step in order: Is the hypothesis class expressive enough to capture the pattern? Is the loss function actually penalizing the errors that matter for this business problem? Is the optimizer converging, or is it stuck, oscillating, or diverging?&lt;br&gt;
Most "my model isn't working" bugs live in exactly one of those three buckets. Naming the bucket cuts debugging time dramatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The pattern goes beyond ML&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I've noticed this same three-step logic shows up outside of pure modeling too. Any time a team builds a scoring system — fraud detection, lead scoring, churn prediction — they're implicitly defining a hypothesis (what signals matter), a loss (what counts as a costly mistake), and an optimization process (how the system improves over time).&lt;br&gt;
The vocabulary changes by domain. The underlying architecture doesn't.&lt;br&gt;
&lt;strong&gt;The takeaway&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Algorithms aren't really different species. They're different instantiations of the same three questions, asked in the same order, every time.&lt;br&gt;
Once you see the skeleton, the muscle is just implementation detail.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjz5qgvv2u2dxbr5fi4ac.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjz5qgvv2u2dxbr5fi4ac.png" alt=" " width="800" height="707"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
