<?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 Ribhu Nirek on Medium]]></title>
        <description><![CDATA[Stories by Ribhu Nirek on Medium]]></description>
        <link>https://medium.com/@ribhu198iit?source=rss-4a828aada3a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SvJFm3BwWqetqpRf</url>
            <title>Stories by Ribhu Nirek on Medium</title>
            <link>https://medium.com/@ribhu198iit?source=rss-4a828aada3a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:47:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ribhu198iit/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[Book Review: How to Lie with Statistics?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/datacated/book-review-how-to-lie-with-statistics-a2267d924f6c?source=rss-4a828aada3a8------2"><img src="https://cdn-images-1.medium.com/max/600/1*on45nitT23B_UYNDA3ZCMg.jpeg" width="600"></a></p><p class="medium-feed-link"><a href="https://medium.com/datacated/book-review-how-to-lie-with-statistics-a2267d924f6c?source=rss-4a828aada3a8------2">Continue reading on DATAcated »</a></p></div>]]></description>
            <link>https://medium.com/datacated/book-review-how-to-lie-with-statistics-a2267d924f6c?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2267d924f6c</guid>
            <category><![CDATA[awareness]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Fri, 14 May 2021 18:42:42 GMT</pubDate>
            <atom:updated>2021-05-14T18:42:42.492Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Why “Data Literacy”]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/datacated/why-data-literacy-30fb07bdec85?source=rss-4a828aada3a8------2"><img src="https://cdn-images-1.medium.com/max/600/1*2VXrY_IuFG5Mb6vkAp2Q9A.gif" width="600"></a></p><p class="medium-feed-snippet">Data Literacy: Way out of the &#x201C;Data Pandemonium&#x201D;</p><p class="medium-feed-link"><a href="https://medium.com/datacated/why-data-literacy-30fb07bdec85?source=rss-4a828aada3a8------2">Continue reading on DATAcated »</a></p></div>]]></description>
            <link>https://medium.com/datacated/why-data-literacy-30fb07bdec85?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/30fb07bdec85</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[data-literacy]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Tue, 13 Apr 2021 02:39:31 GMT</pubDate>
            <atom:updated>2021-04-13T16:51:41.253Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Becoming Ordinary to Be ExtraOrdinary]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://ribhu198iit.medium.com/becoming-ordinary-to-be-extraordinary-c4e98fdf2348?source=rss-4a828aada3a8------2"><img src="https://cdn-images-1.medium.com/max/2600/1*8XU3prTrORGwuAXmn5G8TQ.jpeg" width="3523"></a></p><p class="medium-feed-snippet">Chasing the extraordinary can be an exhilarating and a daunting experience. This account contains takeaways from my endeavors at becoming&#x2026;</p><p class="medium-feed-link"><a href="https://ribhu198iit.medium.com/becoming-ordinary-to-be-extraordinary-c4e98fdf2348?source=rss-4a828aada3a8------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://ribhu198iit.medium.com/becoming-ordinary-to-be-extraordinary-c4e98fdf2348?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4e98fdf2348</guid>
            <category><![CDATA[self-awareness]]></category>
            <category><![CDATA[inspiration]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[success]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Sat, 24 Oct 2020 15:56:51 GMT</pubDate>
            <atom:updated>2020-10-24T15:56:51.474Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Pursuit of Perfect]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://ribhu198iit.medium.com/pursuit-of-perfect-311408c6e268?source=rss-4a828aada3a8------2"><img src="https://cdn-images-1.medium.com/max/800/1*FWOU2VQ-b1H-IP9dK6Bgjw.jpeg" width="800"></a></p><p class="medium-feed-snippet">Dealing with mess and uncertainty</p><p class="medium-feed-link"><a href="https://ribhu198iit.medium.com/pursuit-of-perfect-311408c6e268?source=rss-4a828aada3a8------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://ribhu198iit.medium.com/pursuit-of-perfect-311408c6e268?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/311408c6e268</guid>
            <category><![CDATA[just-do-it]]></category>
            <category><![CDATA[self-awareness]]></category>
            <category><![CDATA[perfectionism]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[self]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Tue, 06 Oct 2020 13:06:45 GMT</pubDate>
            <atom:updated>2020-10-08T19:27:42.308Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Predicting Boston House prices using Linear Regression]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/predicting-boston-house-prices-using-linear-regression-3c6107c662e5?source=rss-4a828aada3a8------2"><img src="https://cdn-images-1.medium.com/max/2250/1*VqQ-2Q2RdkK_bxIVVFfdAw.jpeg" width="2250"></a></p><p class="medium-feed-snippet">Linear Regression: Theory and Application</p><p class="medium-feed-link"><a href="https://medium.com/data-science/predicting-boston-house-prices-using-linear-regression-3c6107c662e5?source=rss-4a828aada3a8------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/predicting-boston-house-prices-using-linear-regression-3c6107c662e5?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c6107c662e5</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Sat, 02 May 2020 02:28:20 GMT</pubDate>
            <atom:updated>2020-05-02T02:28:20.438Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Gaussian Mixture Models(GMM)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/swlh/gaussian-mixture-models-gmm-1327a2a62a?source=rss-4a828aada3a8------2"><img src="https://cdn-images-1.medium.com/max/720/1*TLqrqBWlCPwdE3eERvpxtA.png" width="720"></a></p><p class="medium-feed-snippet">Understanding GMM: Idea, Maths, EM algorithm &amp; python implementation</p><p class="medium-feed-link"><a href="https://medium.com/swlh/gaussian-mixture-models-gmm-1327a2a62a?source=rss-4a828aada3a8------2">Continue reading on The Startup »</a></p></div>]]></description>
            <link>https://medium.com/swlh/gaussian-mixture-models-gmm-1327a2a62a?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1327a2a62a</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Sat, 25 Apr 2020 13:01:01 GMT</pubDate>
            <atom:updated>2020-06-23T15:10:15.194Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Gaussian Mixture Models(GMM)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/gaussian-mixture-models-gmm-6e95cbc38e6e?source=rss-4a828aada3a8------2"><img src="https://cdn-images-1.medium.com/max/720/1*TLqrqBWlCPwdE3eERvpxtA.png" width="720"></a></p><p class="medium-feed-snippet">Understanding GMM: Idea, Maths, EM algorithm &amp; python implementation</p><p class="medium-feed-link"><a href="https://medium.com/data-science/gaussian-mixture-models-gmm-6e95cbc38e6e?source=rss-4a828aada3a8------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/gaussian-mixture-models-gmm-6e95cbc38e6e?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e95cbc38e6e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Thu, 23 Apr 2020 18:03:58 GMT</pubDate>
            <atom:updated>2020-06-23T15:08:01.181Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Gaussian Mixture Models(GMM)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/gaussian-mixture-models-gmm-816f549940c5?source=rss-4a828aada3a8------2"><img src="https://cdn-images-1.medium.com/max/720/1*TLqrqBWlCPwdE3eERvpxtA.png" width="720"></a></p><p class="medium-feed-snippet">Brief: Gaussian mixture models is a popular unsupervised learning algorithm. The GMM approach is similar to K-Means clustering algorithm&#x2026;</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/gaussian-mixture-models-gmm-816f549940c5?source=rss-4a828aada3a8------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/gaussian-mixture-models-gmm-816f549940c5?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/816f549940c5</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[gaussian-mixture-model]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Tue, 21 Apr 2020 03:21:32 GMT</pubDate>
            <atom:updated>2020-06-23T15:11:23.705Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Gaussian Mixture Models(GMM)]]></title>
            <link>https://medium.com/analytics-vidhya/gaussian-mixture-models-gmm-ca9911b72b4e?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca9911b72b4e</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[gaussian-mixture-model]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Mon, 20 Apr 2020 16:52:38 GMT</pubDate>
            <atom:updated>2020-06-23T15:11:01.096Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding GMM: Idea, Maths, EM algorithm &amp; python implementation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5tFTLI-Yc9SEf9Q2FAGrGg.jpeg" /><figcaption>Source: <a href="https://unsplash.com/@franckinjapan">Franck V.</a> via <a href="https://unsplash.com/photos/JjGXjESMxOY">Unsplash</a></figcaption></figure><p><strong><em>Brief</em>: Gaussian mixture models is a popular unsupervised learning algorithm. The GMM approach is similar to K-Means clustering algorithm, but is more robust and therefore useful due to sophistication. In this article, I will be giving a birds-eye view, mathematics(<em>ba</em>ye<em>s</em>ic maths, nothing ab<em>normal</em>), python implementation from scratch and also using sklearn library.</strong></p><h3>Introduction</h3><p>It would be a good idea to check out my blog on <a href="https://medium.com/analytics-vidhya/k-means-clustering-algorithm-ea66d7ef4888">K-Means clustering</a>(3 min read) to get a basic idea of clustering, unsupervised learning and the K-means technique. In clustering, given an unlabelled dataset <strong><em>X</em></strong>, we wish to group the samples into <strong><em>K</em></strong> clusters. In GMMs, it is assumed that different sub-populations(<strong><em>K</em></strong> in total) of <strong><em>X </em></strong>follow a <a href="https://en.wikipedia.org/wiki/Normal_distribution">normal distribution</a>, although we only have information about the probability distribution of the overall population <strong><em>X(</em></strong>hence the name Gaussian Mixture Model). Our task is to able to find the parameters of the <strong><em>K</em></strong> <em>gaussian’s</em> in order to visualize the data <strong><em>X </em></strong>for <a href="https://en.wikipedia.org/wiki/Exploratory_data_analysis"><em>exploratory data analysis</em></a><strong><em> </em></strong>or make predictions on new data.</p><h3>Improvements over K-Means Clustering</h3><p>K-means uses the euclidean distance function to discover clusters in the data. This approach works well as long as the data follows a circular distribution with respect to centroids. But what if the data is non-linear, ellipsoidal? Or data has a non-zero covariance? What if clusters have different mean and covariances?</p><p>This is where Gaussian Mixture Models save the day!</p><blockquote>GMM assumes a mixture of gaussian distributions to have generated the data. It uses with soft-assignment of data points to clusters(i.e. probabilistic and therefore better) contrasting with the K-means approach of hard-assignments of data points to clusters with the assumption of a circular distribution of data around centroids.</blockquote><p>In short, GMM capture works better because <strong>(A)</strong> it captures the uncertainty of data points belonging to different clusters by using soft-assignments, and <strong>(B)</strong> it doesn’t have a bias for circular clusters. So, it works well even with non-linear data distributions.</p><h3>GMM</h3><p>Objective function of <em>GMM</em> is to maximize the <em>likelihood</em> value for the data X, <strong><em>p(X) </em></strong>or the log-likelihood value<strong><em> L</em></strong>(since log is a monotonically increasing function). By assuming a mixture of <strong><em>K</em></strong> gaussians to have generated the data, we can write <strong><em>p(X) </em></strong>as marginalized probability, summed over all <strong><em>K</em></strong> clusters for all data points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*iEmFaU2kGTkx0D_wNTNUgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Udq9JkCv3z9s_WXYtAT2iw.png" /><figcaption>Likelihood value</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*sZlcLTgOugx_iX-ndqwtPg.png" /><figcaption>Log Likelihood value</figcaption></figure><p>With the summation inside the log function above, we cannot obtain an analytical solution. As nasty as it looks, there is an elegant solution to this problem: <a href="https://en.wikipedia.org/wiki/Expectation%E2%80%93maximization_algorithm"><strong><em>Expectation Maximization(EM) algorithm</em></strong></a>.</p><h3>Math(EM)atics</h3><p>The <strong><em>EM algorithm</em></strong> is an <em>iterative</em> algorithm used to find <em>maximum likelihood estimates(MLE)</em> of models where parameters cannot be found directly just like our case here. It consists of two steps: e<em>xpectation</em> step and the <em>maximization</em> step.</p><ol><li><strong><em>Expectation Step</em></strong>: Compute membership values <em>r</em>_<em>ic. </em>This is the probability that data point <em>x_i</em> belongs cluster <em>c</em>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*Qwgw-6MIfjaeqczqg7HuQw.png" /></figure><p>2. <strong><em>Maximization Step</em></strong>: Calculate a new parameter <em>mc</em>, which determines the fraction of points belonging to different clusters. Update the parameters μ, π, Σ by calculating <a href="https://stats.stackexchange.com/questions/351549/maximum-likelihood-estimators-multivariate-gaussian">MLE’s</a> for each cluster c.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*0L_HhYtzU1PmntPrOpG9gQ.png" /></figure><p>Repeat the E-M steps until log-likelihood value <em>L</em> converges.</p><h3>Code</h3><p>Let’s write a basic implementation for GMM in python from scratch.</p><p>Generate 1-D data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd91e5a848dbaf5cd63edaabc8509efa/href">https://medium.com/media/dd91e5a848dbaf5cd63edaabc8509efa/href</a></iframe><p>Initialize parameters for GMM: μ, π, Σ.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51ea7aefe74c8501155d6d0abab66749/href">https://medium.com/media/51ea7aefe74c8501155d6d0abab66749/href</a></iframe><p>Run first iteration of the EM algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d46a6c59baa341ce6359c94cdcddf13/href">https://medium.com/media/4d46a6c59baa341ce6359c94cdcddf13/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*TLqrqBWlCPwdE3eERvpxtA.png" /></figure><p>Put this code in a for loop and box it in a class object. Now we are talking!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecbae249a6fa7b5dcb8329fb8b3c579d/href">https://medium.com/media/ecbae249a6fa7b5dcb8329fb8b3c579d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*dOIr3nPuZGWv9hiawlDGoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*XSy3sZKTBGVYWOhFXXvs-Q.png" /></figure><p>We have a model up and running for 1-D data. Same principle works for higher dimensions(≥ 2D) as well. Only difference is that we will using the multivariate gaussian distribution in this case. Let’s write code for a 2D model.</p><p>Let’s generate some data and write our model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9f5491e29971ce5355e278c676bc457/href">https://medium.com/media/e9f5491e29971ce5355e278c676bc457/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*nu0tAapGQsl4nWhaQjFm7g.png" /><figcaption>2D Blobs</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6307a0e5ea3c9fb73d03f4953d4f40d/href">https://medium.com/media/d6307a0e5ea3c9fb73d03f4953d4f40d/href</a></iframe><p>Let’s make some prediction on this model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb51dd576cebb69a30891dc6a02b0daa/href">https://medium.com/media/cb51dd576cebb69a30891dc6a02b0daa/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ZSpDCoip56QPLt2MDuxZ6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*7jJIlDnyPTvpzxtMqqXmpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*rnumu6d8_8kFFdCiZ_s8uw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*NYxM_vuTSt-fUf1fZJjRhg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*tbo99j-fL1hzzZpG8BKPHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Wnvlfy1BuauVSak7UaFcJQ.png" /></figure><p>Using <a href="https://scikit-learn.org/stable/tutorial/index.html"><strong><em>sklearn</em></strong></a>, the same task can be done within a few lines of code. Pretty slick, huh?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74ffe25e76788fb7c17c93eb2838203e/href">https://medium.com/media/74ffe25e76788fb7c17c93eb2838203e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*nKs7niOt2YAZrwPpOH5uvw.png" /></figure><p>So, GMM classifies the sample to belong to the second cluster. It works!</p><h3>Conclusion</h3><p>Implementing Gaussian Mixture Models is not that difficult. Once you’re clear with the math, it is finding Maximum likelihood estimates for the model whether its 1D or higher-dimensional data. This method is robust and useful in performing clustering tasks. Now that you are familiar with the python implementation of GMMs, you can perform cool stuffs with data sets. Suppose you are given a data set of patients consisting of two parameters: RBC Volume and RBC Hemoglobin Concentration without the labels of sick and healthy patients. Plugging the above model to cluster the data will give you two distinct(<em>almost</em>) masses which you can use for further analysis and predictions.</p><h3>Sources</h3><ol><li><a href="https://www.youtube.com/watch?v=qMTuMa86NzU">https://www.youtube.com/watch?v=qMTuMa86NzU</a></li><li><a href="https://www.python-course.eu/expectation_maximization_and_gaussian_mixture_models.php">https://www.python-course.eu/expectation_maximization_and_gaussian_mixture_models.php</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca9911b72b4e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/gaussian-mixture-models-gmm-ca9911b72b4e">Gaussian Mixture Models(GMM)</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K-Means Clustering Algorithm]]></title>
            <link>https://medium.com/swlh/k-means-clustering-algorithm-16ad985be467?source=rss-4a828aada3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/16ad985be467</guid>
            <category><![CDATA[k-means]]></category>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ribhu Nirek]]></dc:creator>
            <pubDate>Fri, 17 Apr 2020 19:09:13 GMT</pubDate>
            <atom:updated>2020-04-17T19:09:13.883Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Brief</em>: K-means clustering is an unsupervised learning method. In this post, I introduce the idea of unsupervised learning and why it is useful. Then I talk about K-means clustering: mathematical formulation of the problem, python implementation from scratch and also using machine learning libraries.</p><h3>Unsupervised Learning</h3><p>Typically, machine learning models make prediction on data, learning previously unseen patterns to make important business decisions. When the data set consists of labels along with data points, it is known as <a href="https://en.wikipedia.org/wiki/Supervised_learning"><strong><em>supervised learning</em></strong></a><strong><em>, </em></strong>with spam detection, speech recognition, handwriting recognition being some of its use cases. The learning methods where insights are drawn from data points without any <em>ground truth</em> or <em>correct labels</em> falls under the category of <a href="https://en.wikipedia.org/wiki/Unsupervised_learning"><strong><em>unsupervised learning</em></strong></a>.</p><p><em>Unsupervised learning</em> is one of the basic techniques used in <a href="https://en.wikipedia.org/wiki/Exploratory_data_analysis"><em>exploratory data analysis</em></a> to make sense of the data before preparing to make complex machine learning models to make inferences. As this does not consist of human-labelled data, bias is minimized. Also, as there are no labels, there are no correct answers. From a probabilistic standpoint the contrast between <em>supervised</em> and <em>unsupervised learning</em> is the following: supervised learning infers the <em>conditional probability distribution p(x|y)</em>, whereas unsupervised learning is concerned with the <em>prior probability p(x)</em>.</p><h3>K-Means Clustering Algorithm</h3><blockquote>Objective of clustering methods is to separate data points into separate clusters(pre-determined) maximizing inter-cluster distance and minimizing intra-cluster distance(increasing similarity).</blockquote><p>K-Means is one of the clustering techniques in unsupervised learning algorithms. Some other commonly used techniques are <a href="https://en.wikipedia.org/wiki/Fuzzy_clustering">fuzzy clustering</a>(soft k-means), hierarchical clustering, mixture models. <em>Hard clustering</em> or <em>hard k-means</em> is assigning each data point to only one cluster instead (e.g. email Spam or not Spam) instead of assigning a non-zero membership value to each cluster(Spam: 13%, Not Spam: 87%) as in <em>soft k-means</em>. I am covering <em>hard-clustering </em>in this post.</p><p>How the<em> K-means algorithm</em> works:</p><ol><li>Pick <strong><em>k </em></strong>centroids randomly(without replacement) from <strong><em>X</em></strong>.</li></ol><p>2. Compute distance(<em>L2</em> or <em>Euclidean distance</em>) of each <strong><em>x</em></strong> from all <strong><em>μ</em></strong>’s.</p><p>3. Pick the closest cluster one as the label for this <strong><em>x</em></strong>.</p><p>4. Update centroids by finding arithmetic mean of each <strong><em>k</em></strong> clusters.</p><p>5. Repeat steps<em> 2–4</em> until centroids stop changing.</p><p>Mathematically, it can be reduced to finding an optimal partition <strong><em>S*</em></strong> of the dataset <strong><em>X</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IN0bXbGgb-oO1wgaUIOTcg.png" /><figcaption>Mathematical formulation of K-means</figcaption></figure><h3>Code</h3><p>Firstly, I will be writing the basic implementation of k-means from scratch in python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de32bf2acf355bf06eb7b2812c68073e/href">https://medium.com/media/de32bf2acf355bf06eb7b2812c68073e/href</a></iframe><p>Let’s generate some data and apply k-means to see how it works.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab9ece1a8c71d9e60d5b19591124f30f/href">https://medium.com/media/ab9ece1a8c71d9e60d5b19591124f30f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*QkdpziVfDd0muH2jc4fjLg.png" /><figcaption>Synthesized data</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b96df908221b7f120da0b16bd29ecd12/href">https://medium.com/media/b96df908221b7f120da0b16bd29ecd12/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*8BjDi3LU-db2WzklNYc8tA.png" /><figcaption>Output: K-means from scratch</figcaption></figure><p>Not bad, huh? Building a model from scratch in 50 lines of code is cool :)</p><p>The same task can be done within a few lines by importing the scikit-learn library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/319e34dab6a81914ed7bd1f6e6565039/href">https://medium.com/media/319e34dab6a81914ed7bd1f6e6565039/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*GamrTn2I_Q2aymyqbWNC7g.png" /><figcaption>Output: K-means using sklearn</figcaption></figure><p><a href="https://scikit-learn.org/stable/">Sklearn</a> gives pretty much the same output as the model we built from scratch on this dummy data set.</p><p>Once you have written a basic bare and bones structure from scratch and are familiar with the nitty-gritty of the implementation. After that, implementing <strong><em>k-means </em></strong>or any other algorithm is a walk in the park using specialized library functions.</p><h3>Conclusion</h3><p>K-means is one of the simplest unsupervised learning methods. It can be used to draw insights for EDA before moving on to build a sophisticated architecture to make decisions. This blog is a good starting point to get some idea about unsupervised learning, clustering, k-means and its implementation.</p><p>Feel free to read, code and explore to learn more. Drop a note down below to share your experience. Thanks for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16ad985be467" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/k-means-clustering-algorithm-16ad985be467">K-Means Clustering Algorithm</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>