<?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 Lea Setruk on Medium]]></title>
        <description><![CDATA[Stories by Lea Setruk on Medium]]></description>
        <link>https://medium.com/@leasetruk?source=rss-97fe60972395------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fIv4Ahs685hqVvXXH4PrlA.jpeg</url>
            <title>Stories by Lea Setruk on Medium</title>
            <link>https://medium.com/@leasetruk?source=rss-97fe60972395------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 15:50:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leasetruk/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[Recommender Systems]]></title>
            <link>https://leasetruk.medium.com/recommender-systems-6f746266aa94?source=rss-97fe60972395------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f746266aa94</guid>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[collaborative-filtering]]></category>
            <category><![CDATA[recommendations]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Lea Setruk]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 07:17:58 GMT</pubDate>
            <atom:updated>2021-06-09T07:17:58.304Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*BFGn4u7YkzuEpuAz0C-TTg.png" /></figure><h4><strong>Introduction</strong></h4><p>If you have ever felt spied on by internet, then, you have experienced the recommender systems. From Amazon to Netflix, Spotify or even Asos, most e-commerce websites use it. Those websites suggest items (products) you might want to buy, something similar from what you’ve already checked or bought, or read, etc. in order for you to buy more and to make your life easier (but mostly to get your money…).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*_lGB0UTSFwb0wkPeHHDMlA.png" /></figure><h4><strong>The different types of recommender systems:</strong></h4><p>There exist different types of recommender systems:</p><ul><li>Non personalized recommenders</li><li>Content based filtering</li><li>Collaborative filtering (item based, user based)</li></ul><h4><strong>Non personnalized recommender systems:</strong></h4><p>They give general recommendations, not according to your history. It can be popular, trending, new arrivals…</p><p>Mostly, they give you a selection of popular products. To know them, the weighted average ratings of each item is calculated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*_Pq1ebB-vwh-p5uv2X8x4g.png" /></figure><p>You can also add some parameters, according to the age of the client for example, or its location etc…</p><h4><strong>Content-Based Recommender System</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*C4jQ9H4ngrkMOnDqf2bVRA.png" /></figure><p>A content-based recommender works with data that the user provides.</p><p>According to the products you bought (the movies you saw, or the books you read… you get it!), it will recommend you similar products. To do so, it calculates the similiraty between the ones you bought, to the others in the list.</p><p>As the user provides more inputs or takes actions on the recommendations, the engine becomes more and more accurate.</p><p>Let’s take an example. We consider a user that has already rated movies : Movies A (rating = 2/10), B (rating = 10/10), C (rating = 8/10) and D (rating = 7/10). What other movie (E, F or G), the recommender system will recommend him?</p><p>We need to know the genres of the rated movies and make it a one hot encoded matrix and consider also their ratings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*LNTEoCbM8rreSgV2UmFq1A.png" /><figcaption>Movies’ genres matrix (one hot encoded)</figcaption></figure><p>And for the non-rated movies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*wnKZPPbPgGtjNSggczy0Bg.png" /><figcaption>None rated movies’ genres matrix</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*zTYgEYyyB2cquhRkFCco6g.png" /><figcaption>Ratings matrix</figcaption></figure><p>We multiply the one hot encoded matrix by the ratings and we get a weighted genre matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*R5RTEYDWzlMlX1dpzLP3zw.png" /><figcaption>Movies’ genres matrix (one hot encoded)*ratings</figcaption></figure><p>Now, to get the user’s profile, you need to sum the ratings by genres:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*kG13zt_rIBlKdEDn8PO2Cg.png" /><figcaption>User-Genres ratings</figcaption></figure><p>We normalize it (by dividing by the sum of the ratings which is 17+10+25+18=70)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*A1HwduDguWKvFn1b5His2Q.png" /><figcaption>Normalized User-Genres ratings</figcaption></figure><p>Now, to predict the ratings of three new movies: E, F and G, we multiply the normalized user-genres ratings matrix by the non-rated one hot encoded matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*40ZMe5DV-fTllzHt-rBnBA.png" /></figure><p>And summing it, we get the recommendation matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*riprF57ea1wcA-EOvIPiVg.png" /></figure><p>The movie, with the highest weight will be recommended to the user. Here, movie G.</p><h4><strong>Collaborative filtering</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*p_mQJ9_X-MtBbwhcu8zA9Q.png" /></figure><p>The idea behind collaborative filtering is to consider users’ opinions on different items and recommend the best item to each user based on the user’s previous rankings and the opinion of other similar types of users.</p><h4><strong>User-Based Collaborative Filtering</strong></h4><p>The first step is to discover how similar the active user is to the other users.</p><p>To generate recommendation to user U:</p><p>1. Find users with similar rating pattern to U.</p><p>2. Infer top-k or missing ratings for user U based on aggregation of ratings of the similar users.</p><p>To do so, different similarity measurements can be used (ex: Cosine similarity, Euclidian distance…).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*W8LtfQvE3sA06UPqoTDIyg.png" /></figure><p>For example, we’ll calculate the cosine similiraty between users according to their movies’ ratings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*OrU4YOff4F6IWYm-gNc2TA.png" /></figure><p>Similarity(User1,User4)= (8*9)/(8*9) = 1</p><p>Similarity(User2,User4)=[9*6+5*9+5*4]/[sqrt(9²+5²+5²)*sqrt(6²+9²+4²)]=119/135.9 = 0.87</p><p>Similarity(User3,User4)=[8*6+7*9]/[sqrt(8²+7²)*sqr(6²+9²)]=111/115 = 0.96</p><p>We want to recommend to User4 movie A or movie F.</p><p>Rating matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*eevwnrmo6UdpVkq6hyGklQ.png" /><figcaption>Rating matrix (Movies A and F)</figcaption></figure><p>And the similarity matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/1*-2eNgnWJKJUJbvcRkVTCIA.png" /><figcaption>Similarity matrix (Users-User4)</figcaption></figure><p>Multiplication of both:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*p8mc2QpP4ygRtKI_U9NtQA.png" /><figcaption>Rating matrix*Similatiry matrix</figcaption></figure><p>The normalized recommendation matrix is made by dividing each movie’s weighted sum by the sum of the similarity index.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*3dmjA1ct8mL0anKohByOYw.png" /></figure><p>Recommendation matrix (normalized by the sum of similarity):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*urzYLgzuOoIPPOThl7wvQQ.png" /><figcaption>Recommendation matrix</figcaption></figure><p>We obtained the predicted ratings of the user for movie A and movie F. The movie with the highest one will be recommended, which is Movie F.</p><h4><strong>Conclusion</strong></h4><p>A recommender system is a subclass of information filtering system that seeks to predict the “rating” or “preference” a user would give to an item.</p><p>Recommendation algorithms can be divided into two categories: collaborative approaches (user-user, item-item) based on user-item interaction matrix, and content based approaches (such as regression or classification models) that use prior information about users and/or items.</p><p>For the past years, the use of recommender systems has been thriving in many big industries due to the success of online stores.</p><p><strong>You can check my repository using the different types of recommender systems (in Python) with real data (online bookstore): </strong><a href="https://github.com/Lea1612/AI_Recommender_Systems"><strong>https://github.com/Lea1612/AI_Recommender_Systems</strong></a></p><p>If you have further questions, you can contact me on LinkedIn (<a href="https://www.linkedin.com/in/lea-setruk-991378148/">click here</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f746266aa94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K-Means Algorithm (with example)]]></title>
            <link>https://leasetruk.medium.com/k-means-algorithm-with-example-b8994b3c4ef3?source=rss-97fe60972395------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8994b3c4ef3</guid>
            <category><![CDATA[k-means]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[elbow-method]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Lea Setruk]]></dc:creator>
            <pubDate>Mon, 19 Apr 2021 08:44:40 GMT</pubDate>
            <atom:updated>2021-04-19T08:44:40.224Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/561/0*8kmYhsq4oSXbLQmN.png" /></figure><p><strong>Introduction</strong></p><p>K-Means is an unsupervised machine learning algorithm. It is one of the most popular algorithm for clustering. It is used to analyze an unlabeled dataset characterized by features, in order to group “similar” data into <em>k</em> groups (clusters).</p><p>For example, K-Means can be used for behavioral segmentation, anomaly detection, insurance claim, fraud detection, market price or in computer vision etc…</p><p><strong>The algorithm</strong></p><p>How do you define similarity in the data? The similarity between two data points can be measured by the distance between their features.</p><p>The algorithm starts by scaling the data and initializing <em>k </em>centroids (clusters’ centers). Then, it associates each data point to its closest centroid. On the other hand, it computes the average of the assigned point to determine the new centroid. Each centroid defines a cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*qEIe466X2cRaixXgEdaviA.png" /></figure><ol><li>Step 1: Choose <em>k </em>random points as centroids.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*AcBDcuqS9pJXiad1NWg0Eg.png" /></figure><p>Then, the algorithm iterates between the two following steps until convergence.</p><p>2. Step 2: Group each object around its nearest centroid by calculating the Euclidian distance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*AbSR6EMCMfijhRBAmVvfYQ.png" /></figure><p>3. Step 3: Determine the new cluster center by computing the average of the assigned points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*1aqNKCkovLTXTs8eqGO-7w.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F5I3Ei69I40s&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5I3Ei69I40s&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2F5I3Ei69I40s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/37c014c4d2c1cedf1c98fd6a34e1cfaf/href">https://medium.com/media/37c014c4d2c1cedf1c98fd6a34e1cfaf/href</a></iframe><p><strong>How do you choose <em>k</em>? — The Elbow Method.</strong></p><p>The number of clusters depends on the data. It is not always obvious. You need to choose it.</p><p>If <em>k</em> is too small, it won’t represent all of the different categories. If it is too large, it will create unnecessary clusters and can cause overfitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*LMXq8FjkBqeScaV3kej9WQ.png" /></figure><p>One of the method to choose <em>k</em> is the <strong>Elbow Method</strong>. It consists of plotting the explained variation as a function of the number of clusters. Then, you pick the elbow of the curve as <em>k.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*Wxnn_bt15wOJbn1ih-FEoQ.png" /></figure><p><strong>Example of K-Means with Sklearn (iris dataset)</strong></p><pre>### Import the relevant libraries.</pre><pre>import numpy as np<br>import pandas as pd<br>import matplotlib.pyplot as plt</pre><pre>import sklearn<br>from sklearn.preprocessing import scale<br>import sklearn.metrics as sm<br>from sklearn.metrics import confusion_matrix, classification_report</pre><pre>from sklearn.cluster import KMeans<br>from mpl_toolkits.mplot3d import Axes3D<br>from sklearn import datasets</pre><pre>### Load the dataset<br>iris = datasets.load_iris()</pre><pre>### Scale your data and define your features and your targets</pre><pre>X = scale(iris.data) # Scaled features<br>y = pd.DataFrame(iris.target) # Target<br>variable_names = iris.feature_names</pre><pre>### How does the data look?</pre><pre>pd.DataFrame(data= np.c_[X, y],<br>                     columns= variable_names + [&#39;target&#39;]).head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*6mgiAAbkdEuetwDaSfW3KA.png" /></figure><pre>###K-means clustering with k=3</pre><pre>clustering = KMeans(n_clusters=3, random_state=5)<br>clustering.fit(X)</pre><p>Elbow Method:</p><pre>### We calculate the distortions for each value of k<br>### Distortion is the sum of squared distances from each point to its assigned center.</pre><pre>distortions = []<br>K = range(1,10)<br>for k in K:<br>    kmeanModel = KMeans(n_clusters=k)<br>    kmeanModel.fit(X)<br>    distortions.append(kmeanModel.inertia_)</pre><pre>### Plot <br>plt.figure(figsize=(16,8))<br>plt.plot(K, distortions, &#39;bx-&#39;)<br>plt.xlabel(&#39;k&#39;)<br>plt.ylabel(&#39;Distortion&#39;)<br>plt.title(&#39;The Elbow Method showing the optimal k&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*52knKEZ7PSzurPB7pqQvVw.png" /><figcaption>Elbow on k=3</figcaption></figure><pre>### K-Means clustering with k=3</pre><pre>clustering = KMeans(n_clusters=3, random_state=5)<br>clustering.fit(X)</pre><p>Visualization:</p><pre>iris_df = pd.DataFrame(iris.data)<br>iris_df.columns = [&#39;Sepal_Length&#39;, &#39;Sepal_Width&#39;, &#39;Petal_Length&#39;, &#39;Petal_Width&#39;]<br>y.columns = [&#39;Targets&#39;]</pre><pre>plt.subplot(1,2,1)</pre><pre>plt.scatter(x=iris_df.Petal_Length, c=iris.target, y=iris_df.Petal_Width, s=50)</pre><pre>plt.title(&#39;True Classification&#39;)</pre><pre>plt.subplot(1,2,2)</pre><pre>plt.scatter(x=iris_df.Petal_Length, c= iris.target, y=iris_df.Petal_Width, s=50)</pre><pre>plt.title(&#39;K-Means Classification&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*NOIZVOpS3gelGLFBz4m6nQ.png" /></figure><p><strong>Conclusion</strong></p><p>K-Means clustering is one of the most popular clustering algorithms and gives you a good idea of the structure of the dataset.</p><p>However, it doesn’t learn the number of clusters from the data and requires it to be pre-defined, which can be tricky.</p><p>If you have further questions, you can contact me on LinkedIn (<a href="https://www.linkedin.com/in/lea-setruk-991378148/">click here</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8994b3c4ef3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Naive Bayes Classifier (with examples)]]></title>
            <link>https://leasetruk.medium.com/naive-bayes-classifier-with-examples-7b541f9ffedf?source=rss-97fe60972395------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b541f9ffedf</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[naive-bayes]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Lea Setruk]]></dc:creator>
            <pubDate>Wed, 24 Mar 2021 13:59:32 GMT</pubDate>
            <atom:updated>2021-03-24T13:59:32.410Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*El5bBBkaDoaVtpQbOZRIFw.png" /></figure><p><strong>Introduction:</strong></p><p>In machine learning, the purpose is to find certain types of patterns. To do so, you need to train a model over a dataset using algorithms so that the model can learn from those data. Once it is trained, the model can be used to predict on a different data that it hasn’t seen before.</p><p>Machine learning can be used for classification (Does the patient has diabetes?, Does this mail is a spam? etc.).</p><p>Naive Bayes Classifier is a machine learning model used for classification tasks.</p><p><strong>The background you are required to have:</strong></p><p>Probability distribution, density, events, independence between random variables, joint probability, conditional probability…</p><p><strong>How does it work?</strong></p><p>A classifier is a machine learning model that is used to classify different objects based on features. For example, we can classify an email by spam/not spam according to the words in it. Or, we can classify a document by its topic also according to its words.</p><p>Naive Bayes is a simple, yet important probabilistic model. It is based on the Bayes’ theorem.</p><p><em>Bayes’ Theorem:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*wc97pA3wMjGZI6MxBGlhTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*PCA6Bw5kX-CX7IpllmHlGQ.png" /></figure><p>This model is called ‘naïve’ because we naively assume independence between features given the class variable, regardless of any possible <a href="https://en.wikipedia.org/wiki/Correlation_and_dependence">correlations</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*LW68TC6DGZPR1OEOK08t3A.png" /></figure><p>An advantage of naive Bayes is that it only requires a small number of training data to estimate the parameters necessary for classification. It just needs enough data to understand the probabilistic relationship of each feature to the class variable. Indeed, in this model, interactions between features are ignored, so we don’t need examples of these interactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*0XCuLw6pAlZeHGo_eu9MJw.png" /><figcaption>Classification process</figcaption></figure><p>Different types of Naive Bayes exist:</p><ul><li><em>Gaussian Naive Bayes</em>: When dealing with continuous data, with assumption that these values associated with each class are distributed according to a <a href="https://en.wikipedia.org/wiki/Normal_distribution">normal</a> (Gaussian) distribution.</li><li><em>Multinomial Naive Bayes</em>: Features represent the frequencies of events. This model is used for document classification, with events representing the occurrence of a word in a single document.</li><li><em>Bernoulli Naive Bayes</em>: Features are independent <a href="https://en.wikipedia.org/wiki/Boolean_data_type">Booleans</a> (binary variables). Like the multinomial model, this model is mostly used for document classification tasks, where words’ occurrence is used rather than frequencies.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*8v8_LS1K3siVG_JWBlSf9Q.png" /></figure><p><strong>Example:</strong></p><p>John is a student in computer science that loves listening to music. Sometimes, he has homework to do, it can be programming homework, or else. We have some examples of the type of music he listens to, according to some features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*b58UyIqKhTfTwsukJ0FPdA.png" /><figcaption>Data</figcaption></figure><p>Assume you saw John in the morning, he had homework to do that doesn’t require programming. What kind of music would Naive Bayes predict?</p><p>We need to calculate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*l06vCIIvXR_Fdrhn8xRpyQ.png" /></figure><p>Using Bayes’ theorem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*lCs-x_nHpDRJgFJo2wSTHQ.png" /></figure><p>With the independence assumption we obtain:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*yCCqMlgaNrMutnaqQiBiPg.png" /></figure><p>Now, we calculate these probabilities for both of the music types.</p><p>For MusicType = classical:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*8id44iOEhIUbXwDYYtWZag.png" /></figure><p>For MusicType = pop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*83ufalQog-Ygx4OeAb3OBA.png" /></figure><p>Thus, we observe that it is more likely for John to listen to classical music in the morning, when he has a non programming homework to do.</p><p>For another well and clearly explained example, you can watch this video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FO2L2Uv9pdDA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DO2L2Uv9pdDA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FO2L2Uv9pdDA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/73fbca6420fef85706b8e479263aae72/href">https://medium.com/media/73fbca6420fef85706b8e479263aae72/href</a></iframe><p><strong>Conclusion:</strong></p><p>Naive Bayes is a simple classifier model that is usually used for documents classification, spam filtering etc. Despite the fact that the independence assumptions are often inaccurate in reality, the naive Bayes classifier has properties that make it surprisingly useful in practice.</p><p>If you have further questions, you can contact me on LinkedIn (<a href="https://www.linkedin.com/in/lea-setruk-991378148/">click here</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b541f9ffedf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maximum Likelihood Explanation (with examples)]]></title>
            <link>https://leasetruk.medium.com/maximum-likelihood-explanation-with-examples-7bdf960efacd?source=rss-97fe60972395------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bdf960efacd</guid>
            <category><![CDATA[maximum-likelihood]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Lea Setruk]]></dc:creator>
            <pubDate>Sun, 06 Sep 2020 17:07:20 GMT</pubDate>
            <atom:updated>2020-09-06T17:07:20.149Z</atom:updated>
            <content:encoded><![CDATA[<h3>Maximum Likelihood explanation (with examples)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IMf4KaOkx29UltGG0wv-UQ.jpeg" /></figure><p><strong>Introduction </strong>:</p><p>In machine learning, the purpose is to find certain types of patterns. To do so, you need to train a model over a dataset using algorithms so that the model can learn from those data. Once it’s trained, the model can be used to predict on a different data that it hasn’t seen before.</p><p>For example, we can use a ML model in order to predict if a patient has diabetes or if he’s healthy depending on features like its blood pressure, its weight etc…</p><p>Each machine learning model has parameters. They are very important and they define how the model looks like.</p><p>The Maximum Likelihood Estimation (MLE) is a method of estimating the parameters of a model. This estimation method is used a lot.</p><p><strong>The background you’re required to have :</strong></p><p>Probability distributions, density functions, events, independance between random variables, joint probability.</p><p><strong>How does it work ?</strong></p><p>To estimate the parameters using the maximum likelihood method, we need, first of all, to define a likelihood function in order to calculate the conditional probability of observing the data sample given a probability distribution and distribution parameters.</p><p><strong>Likelihood function :</strong></p><p>The likelihood function is a function of statistcal model’s parameters calculated from observed data.</p><p>The words « likelihood » and « probability » don’t have exactly the same meaning. Indeed, « probability » represents the plausibility of an event according to a model, with no specific reference to observed data. And « likelihood » describes the plausibility of a model parameters’ value, given the observation of realizations of a random variable.</p><p>Suppose that the joint probability density function of your sample X = (X1,…,Xn) is f(x| θ), where θ is a vector of parameters. X = x is an observed sample point. Then the function of θ :</p><p>L(θ |x) = f(x |θ) is the likelihood function.</p><p>For a better understanding, if we are in a case that L(θ1|x) &gt; L(θ2|x), then our observed sample x is more likely to have been observed if θ = θ1 than if θ = θ2.</p><p>It also means that the most plausible value for θ between θ1 and θ2, is θ1.</p><p>If we suppose that X1,…,Xn are iid, we can also write the likelihood function as :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*mUZHUPfSlTMloAV3-NER0w.jpeg" /></figure><p>Let see two examples that will help you understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*tBAnOyfxf8HVr4xXWcVhwg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*hB3UtH9JDBtkMou8_1LrgQ.png" /></figure><p><strong>Maximum Likelihood Estimation :</strong></p><p>As said before, the maximum likelihood estimation is a method that determines values for the parameters of a model. Those parameters are found such that they maximize the likelihood function. When we find the maximum of the likelihood function, we actually find the parameters which are most likely to have produced the observed data.</p><p>Often, to make it easy, we actually maximize the log of the likelihood function. We call it the log-likelihood function.</p><p>Indeed, the log function transforms the multiplication to a sum. Moreover, the maximum of the log function is also the maximum of the original function.</p><p>You can use different methods to maximize this function. Usually, when it’s possible, we just derivate it and compare it to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*lQpviWSilAXLYB5q5iaKgA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*F2rBMqgw5PvlHNY2GPOjEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*tAuEdiUeECXZbvblgEHxew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*LPMpImr4foxlRcQz8jXuhw.png" /></figure><p><strong>Visualization :</strong></p><p>Let’s see how the MLE works with normal distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*6ZoAhv0cvZo1mavSs-N8hg.gif" /><figcaption>Thank’s to <a href="https://towardsdatascience.com/@william.fleshman?source=follow_footer--------------------------follow_footer-">William Fleshman</a> — Medium for this great GIF</figcaption></figure><p>You can find a very good explanation of it in this video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXepXtl9YKwc%3Fstart%3D186%26feature%3Doembed%26start%3D186&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXepXtl9YKwc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXepXtl9YKwc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad3ee8403e4273219c44b474634552d5/href">https://medium.com/media/ad3ee8403e4273219c44b474634552d5/href</a></iframe><p><strong>Conclusion :</strong></p><p>Maximum Likelihood Estimation is very useful to find optimal parameters of a Machine Learning model.</p><p>If you have further questions, you can contact me on LinkedIn (<a href="https://www.linkedin.com/in/lea-setruk-991378148/">click here</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bdf960efacd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>