<?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 Shubam Sharma on Medium]]></title>
        <description><![CDATA[Stories by Shubam Sharma on Medium]]></description>
        <link>https://medium.com/@shubamsharma1947?source=rss-6f586db9af37------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aPKzvHfWDC9U1Jms.</url>
            <title>Stories by Shubam Sharma on Medium</title>
            <link>https://medium.com/@shubamsharma1947?source=rss-6f586db9af37------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 07:48:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shubamsharma1947/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[MultiClass Logistics Regression — Calculating probability from Co-Efficients manually]]></title>
            <link>https://medium.com/@shubamsharma1947/multiclass-logistics-regression-calculating-probability-from-co-efficients-manually-b604771a0fcd?source=rss-6f586db9af37------2</link>
            <guid isPermaLink="false">https://medium.com/p/b604771a0fcd</guid>
            <category><![CDATA[logistic-regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Shubam Sharma]]></dc:creator>
            <pubDate>Sat, 21 Dec 2019 06:45:27 GMT</pubDate>
            <atom:updated>2019-12-21T07:04:27.879Z</atom:updated>
            <content:encoded><![CDATA[<h3>MultiClass Logistics Regression — Calculating probability from Co-Efficients manually</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*qoe7hXQALaPE9sgfFwbtbA.png" /></figure><p>You can get enough articles on the internet on theoretical explanation so let us dive directly into the code and calculation part.</p><p>Download the IRIS dataset from [https://archive.ics.uci.edu/ml/datasets/iris] and use the below code snippet to get the probability for each class.</p><pre><em># Read Data</em><br>data &lt;- read.csv(&quot;data.txt&quot;)<br>data$Response &lt;- as.integer(as.factor(data$Response))<br><br>str(data)<br><br><em># Split the data between training and test data</em><br>smp_size &lt;- floor(0.65 * nrow(data))<br>set.seed(12367)<br>train_ind &lt;- sample(seq_len(nrow(data)), size = smp_size)<br>train &lt;- data[train_ind, ]<br>test&lt;- data[-train_ind,]<br><br><em># Model Training</em><br>library(nnet)<br>model &lt;- multinom(f,data = train)<br><br>summary(model)<br><br><em># Model Prediction</em><br>test_ot &lt;-  predict(model,test[,-5], type = &quot;prob&quot;)<br><br>write.csv(test_ot,&quot;test_ot.csv&quot;,row.names = FALSE)</pre><p>If you print the summary it will give the coefficient per class and our goal is to calculate the probability from these coefficients.</p><pre>&gt; summary(model)<br>Call:<br>multinom(formula = f, data = train)<br><br>Coefficients:<br>   (Intercept)  sepal.length   sepal.width petal.length    petal.width<br>2  134.4802874  -25.77284772  -47.38188713  56.86300931   0.2084497631<br>3 -239.8188987 -236.88735550 -237.18914565 414.48514520 279.5549607434<br><br>Std. Errors:<br>  (Intercept) sepal.length sepal.width petal.length petal.width<br>2 394.6622457  545.6610907 522.6208079  819.8411404 747.6169787<br>3 394.6622444  545.6610847 522.6208039  819.8411423 747.6169790<br><br>Residual Deviance: 0.003796434529 <br>AIC: 20.00379643 <br>&gt;</pre><p>First, check the image on how we arrive at the formula.</p><p>We get an equation for P(1), P(2), and P(3) which are an alias for the probability of Class 1, 2 and 3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p-DhjrP4NQkUdOBZlBKxFw.jpeg" /></figure><p>Now we will work on Excel to calculate the class probability for these coefficients</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*Pe_Emu0jw49deC44DTLOrg.jpeg" /></figure><p>Our test data has 4 features which represent x1, x2, x3, and x4 of the equation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*ZGZQAZvhKKY6gXiMb5nW3w.jpeg" /></figure><p>The equation for linear regression is used to get the value of y1, y2 and then further deduce exp(y1) and exp(y2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*djtiVkMzb3wwKDz-ITL4Ag.jpeg" /></figure><p>Finally, we used log-odd transformation derived above to arrive at the final probability of each class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*4uF3KNgoBPlUQvbzRO0Nmw.jpeg" /></figure><p>We still have many questions to explain how to arrive at the coefficient per class which I will explain in another article. Meanwhile, you can get the Excel with calculations at below link</p><p>Data : <a href="https://www.linkedin.com/pulse/multiclass-logistics-regression-calculating-from-manually-sharma/">https://www.linkedin.com/pulse/multiclass-logistics-regression-calculating-from-manually-sharma/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b604771a0fcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>