<?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 Amine Aoullay on Medium]]></title>
        <description><![CDATA[Stories by Amine Aoullay on Medium]]></description>
        <link>https://medium.com/@aoullayamine?source=rss-7a4cf5f2ff10------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AY0zq_zidI-Ikmra9WyNlA.png</url>
            <title>Stories by Amine Aoullay on Medium</title>
            <link>https://medium.com/@aoullayamine?source=rss-7a4cf5f2ff10------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 23:53:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aoullayamine/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[What’s WRONG with Metrics?]]></title>
            <link>https://medium.com/data-science/choosing-the-right-metric-is-a-huge-issue-99ccbe73de61?source=rss-7a4cf5f2ff10------2</link>
            <guid isPermaLink="false">https://medium.com/p/99ccbe73de61</guid>
            <category><![CDATA[metrics]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Amine Aoullay]]></dc:creator>
            <pubDate>Fri, 03 Aug 2018 12:56:10 GMT</pubDate>
            <atom:updated>2018-09-04T21:17:45.438Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*V4KSdNgvBpBPHjpI9vV5SA.jpeg" /></figure><p>For any kind of machine learning problem, you <strong>must</strong> know how you are going to evaluate your results, or what the evaluation metric is.</p><p>In this post, we will be viewing the <strong>most common metrics</strong> out there and discussing the usefulness of each metric depending on the objective and the problem we are trying to solve.</p><h3>Classification Metrics</h3><h4>Accuracy</h4><p>Probably the most straightforward and intuitive metric for classifier performance. It is simply counting the number of times we predicted the right class over the total number of predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*vybvyaIUIQ5JjERWlb2_uQ.png" /></figure><p><strong>When being confronted with the class imbalance problem, accuracy is clearly a wrong metric to use</strong>. Suppose you have 2 classes : Class A is 99% of your data-set and class B is the remaining 1%. You can reach an accuracy of 99% by predicting class A every time case. Which seems to be a good score but it is not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/185/1*ENXQ_IF7Z1rnEu2h8stCJg.png" /></figure><h4>Precision and Recall</h4><p>In general, there is a trade-off between <strong>recall</strong> (percent of truly positive instances that were classified as such) and <strong>precision</strong> (percent of positive classifications that are truly positive).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*aC4mQKv-qR8xykNx9251ZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*y-dMFo9EfaCKHXJevwKOEQ.png" /></figure><p>In situations where you want to detect instances of a minority class, you are usually concerned more with recall than precision. As in the context of fraud detection, it is usually more costly to miss a positive instance than to falsely label a negative instance.</p><h4>F-measure</h4><p>The ideal scenario we all want is to have a high precision<strong> and </strong>high recall!</p><p>But to choose your best model, you need a single number performance summary. F1 score is the harmonic mean of precision and recall:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*zecyXGxeN04Ccb18NaATqQ.png" /></figure><p>The F1-score <strong>does not have a good intuitive explanation</strong>, and it is a special case of a metric known as the F-Beta score, which measures the effectiveness of retrieval with respect to a user who attaches β times as much importance to recall as to precision.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*2YIU9iAzaE_g91vv2XU7Ew.png" /></figure><h4>Kappa</h4><p><strong>Kappa</strong> or Cohen’s Kappa is like classification accuracy, except that it is normalized at the baseline of random chance on your dataset:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*uuJ_PlgMMwZVcyn6dQoYjQ.png" /></figure><p>where po is the observed agreement, and pe is the expected agreement.</p><p>It basically tells you how much better your classifier (po) is performing over the performance of a classifier that simply guesses at random according to the frequency of each class (pe).</p><p>There is <strong>no standardized way to interpret its values</strong>. <a href="https://www.ncbi.nlm.nih.gov/pubmed/843571">Landis and Koch (1977) </a>provide a way to characterize values. According to their scheme a value &lt; 0 is indicating no agreement , 0–0.20 as slight, 0.21–0.40 as fair, 0.41–0.60 as moderate, 0.61–0.80 as substantial, and 0.81–1 as almost perfect agreement.</p><h4>AUC</h4><p>This is one of the popular metrics used in the industry.</p><p>AUC stands for Area Under the Curve. The curve can represents either the ROC curve or the PR curve.</p><blockquote>PR curve illustrates the trade-off between the <strong>precision </strong>and the <strong>recall </strong>at various threshold settings.</blockquote><blockquote>ROC curve is created by plotting the <strong>TPR</strong> (true positive rate), also called sensitivity, against the <strong>FPR</strong> (false positive rate), also called specificity, at various threshold settings.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*b7KR6yPf2NlUhlxLcVKRZA.png" /></figure><p>Here’s a visualization to see how the ROC curve is plotted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*foMOQk2yPp745FTxhL8SCg.gif" /><figcaption>Each point on the ROC curve (left)<strong> </strong>represents a different cutoff value — The curves on the right represent the Class-Conditional Probabilities</figcaption></figure><p>Let’s see what happens when the percentage of overlapping inscreases/decreases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8F-fY3zanGzYeCX0NlN2MQ.gif" /><figcaption>ROC curve (left) and Class-Conditional Probabilities (right) — varying the the percentage of overlapping for a fixed threshold</figcaption></figure><p>The less overlap, the fewer errors and the further the ROC curve moves up and left. Therefore, the better you separate your classes, the higher AUC will go.</p><p>In other words, AUC doesn’t care about absolute values, <strong>it only cares about ranking</strong>. You just need to well seperate your classes the get a high AUC.</p><p><strong>What is the difference between ROC and PR ?</strong></p><p>Recall = True Positive Rate (TPR). So the difference is between the precision and the false positive rate.</p><p>The main difference between these two types of metrics is that precision denominator contains the False Positives while false positive rate denominator contains the True Negatives.</p><blockquote>While precision measures the probability of a sample classified as positive to actually be positive, the false positive rate measures the ratio of false positives within the negative samples.</blockquote><p><strong>Which one should be used ?</strong></p><p>As goes for any metric, it depends entirely on what you mean to do with the data. If your model needs to perform equally well on the positive class as the negative class. For example, for classifying images between cats and dogs, you would like the model to perform well on the cats as well as on the dogs. For this you would use the ROC-AUC. On the other hand, if you’re not really interested in how the model performs on the negative class, but just want to make sure every positive prediction is correct (precision), and that you get as many of the positives predicted as positives as possible (recall), then you should choose PR-AUC.</p><p>In a nutshell:</p><blockquote><strong>Use PR-AUC to focus on small positive class</strong></blockquote><blockquote><strong>Use ROC-AUC when both classes detection is equally important</strong></blockquote><blockquote><strong>Use ROC-AUC when the positives are the majority or switch the labels and use precision and recall</strong></blockquote><p><strong>N.B</strong>: Many people tend to stick with ROC since it tends to be an easier metric to explain in most cases. In addition to that, it is less straight-forward to calculate accurate PR curves. (Check this <a href="https://classeval.wordpress.com/introduction/introduction-to-the-precision-recall-plot/">link</a> for more details).</p><p>That said, AUC also has its disadvantages: it can give potentially misleading results … see the figure below !!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*TZZpIkWDzn53rZYQKkk9YQ.png" /><figcaption>Both models A and B have an equal area under the ROC cure. However, in the high FPR range, model B is better than A, whereas in the low FPR range model A is better than B.</figcaption></figure><p>Some people do not recommend using AUC for the following reasons:</p><blockquote>(1) it ignores the predicted probability values and the goodness-of-fit of the model</blockquote><blockquote>(2) it summarises the test performance over regions of the curve space in which one would rarely operate</blockquote><blockquote>(3) it weights omission and commission errors equally</blockquote><blockquote>(4) it does not give information about the spatial distribution of model errors</blockquote><blockquote>(5) the total extent to which models are carried out highly influences the rate of well-predicted absences and the AUC scores</blockquote><blockquote>“ Jorge M. Lobo, Alberto Jiménez-Valverde and Raimundo Real ”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*FEKOE-h-Aim__6JyV-g0ag.png" /></figure><h4>Partial AUC (pAUC)</h4><p>The partial AUC has been proposed as an alternative measure to the standard AUC. When using the partial AUC, one considers only a specific region of the ROC space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*3VrMcUe9aaR_PcbVUgzb9w.png" /><figcaption>pAUC denotes the area of shaded region</figcaption></figure><h4>Two-Way pAUC</h4><p>Instead of restricting only on false positive rate (FPR), Two-Way pAUC focuses on the partial area under the curve with both horizontal and vertical restrictions. It has been shown that the indirect control of pAUC on true positive rate (TPR) is conceptually and practically misleading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lTPcntMVRE8jv4_A9fi6Sw.png" /><figcaption>Two-way pAUC denotes the area of shaded region A. This shaded region is directly determined by explicit FPR upper bound p0 (= 0.5) and TPR lower bound q0 (= 0.65). In contrast, pAUC denotes the area of both region A and B. Its<strong> indirect</strong> FPR lower bound (green dotted line) is determined by the TPR lower bound q0</figcaption></figure><h4>LogLoss</h4><p>LogLoss is one of the most important classification metric <strong>based on probabilities.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*xOLpWWRuTwUS6vEwVg3K3g.png" /></figure><p>where yi is the true label and pi the probability that yi = 1.</p><p><strong>It’s all about confidence</strong>: If for a particular observation, the classifier assigns a very small probability to the correct class then the corresponding contribution to the Log Loss will be very large. The Log-loss metric can be seen as a “soft” measurement of accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*_iUXBdhGeJ_glKCIjRA1DQ.png" /><figcaption>2 different models — same AUC but different LogLoss</figcaption></figure><p>These 2 models outputs have <strong>same ranking,</strong> and thereforethe <strong>same ROC-AUC, PR-AUC</strong> !</p><p>However, according to the LogLoss value, the model in the right is better than the one in the left .</p><p>And this is obvious since the Logloss <strong>incorporates the idea of probabilistic confidence.</strong></p><p>One drawback of this metric is that the majority class can dominate the loss !!</p><h3>Learning to rank Metrics</h3><p>Now let’s see how can we evaluate a search engine, a recommender system or any system that outputs a list of items.</p><p>In the research literature, sorting ‘items’ is known as learning to rank.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*uXTaF72GgosbWCnLjwRJBQ.png" /><figcaption>Example of ranked urls for a given query</figcaption></figure><p>The 2 most popular ranking metrics are MAP@k and NDCG@k. Let’s see how they works….</p><p>Notations:</p><blockquote><strong>rel(i)</strong> is an indicator function equaling 1 if the item at rank i is relevant and zero otherwise.</blockquote><blockquote><strong>P(i) </strong>is the proportion of returned items in the top-i set that are relevant.</blockquote><blockquote><strong>n</strong> is the number of predictions made by the system.</blockquote><blockquote><strong>m</strong> is the number of relevant items in the full space of items.</blockquote><blockquote><strong>Q</strong> is the total number of queries.</blockquote><p>To explain what MAP@k does, we need to start whith AP@k……</p><h4>AP@k</h4><p>This metric cares about the average precision up to the k-th item</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*Dkc25zz7dRbC9fZlCqtLTw.png" /></figure><p>The normalization factor used prevents the AP@k score from being unfairly suppressed when the number of recommendations couldn’t possibly capture all the correct ones.</p><p>……Don’t worry, here is a simple example to better understand the formula:</p><p>Consider you have to predict an ordered list of <strong>up to 10</strong> items for a given query. And there are only <strong>4</strong> possible correct predictions (ground truth).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*ddkebSr26TLgnE0rxxBb9g.png" /></figure><p>For every prediction, you need to check if it is correct. If it is not, you get no points for that prediction. If it is correct, you get a number of points equal to the number of correct predictions up to and including this one.</p><p>The number you divide by is the number of points possible. In other words, this is the lesser of 10 (the most you can predict) and the number of actual correct answers that exist 4.</p><p>Thus: AP@10 = (1/2 + 2/3 + 3/5 + 4/9 ) / 4 = 0.55</p><h4>MAP@k</h4><p>MAP@k computes the mean of the Average Precision (AP@k) <strong>over all queries</strong>. Yes, an average of an average !!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*U_8xPCEYMFoiLseS60INDw.png" /></figure><p>The AP@k is a measure that takes in a ranked list of your top-k items and compares it to a list of the true set of “relevant” items for a given query. AP@k rewards you for having a lot of relevant items in your list, and for putting the most likely correct ones at the top. Therefore, <strong>order</strong> <strong>matters</strong> a lot in computing an AP@k score. And the MAP@k just computes the mean of AP@k over all your queries.</p><p>Now, let’s explain the other popular ranking quality metric….</p><h4>NDCG@k</h4><p>This metric asserts the following:</p><ol><li>Very relevant results &gt; somewhat relevant results &gt; irrelevant results (<strong>C</strong>umulative <strong>G</strong>ain).</li><li>Relevant results are more useful when they appear earlier in the set of results (<strong>D</strong>iscounting).</li><li>The result of the ranking should be irrelevant to the query performed (<strong>N</strong>ormalization).</li></ol><p>The <strong><em>Cumulative Gain (CG)</em> </strong>is the sum of the relevance scores of the candidates retrieved. It is calculated as the summation of the first k relevance scores:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*NYnQURU_4JxtgMslKeX0zg.png" /></figure><p>The <strong><em>Discounted CG (DCG)</em></strong>, basically penalises the relevance score in function of the item’s position . A logarithmic decay is used:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*klG8Wssng0mkCX9SYLHsSQ.png" /></figure><p>An alternative formulation was <a href="https://dl.acm.org/citation.cfm?doid=1102351.1102363">proposed</a> to give stronger emphasis on retrieving relevant items:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*f1vKUIYdeux9tT-LHgPDEw.png" /></figure><p>N.B: These 2 formulations of <strong>DCG@k</strong> are the same when the relevance values are binary.</p><p>However, this scores doesn’t have a fixed upper bound limit since it depends on the number of results returned by the query, and thus in order to compare DCG of different queries we have to <strong><em>normalise them</em></strong>. To achive that, we divide the DCG value by the best possible (<strong><em>Ideal</em></strong>) ranking, obtaining the <strong><em>NDCG</em></strong>, a value between 0 and 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*ssRWaeNVuPlpjAbCF9-9lQ.png" /></figure><p><strong>MAP@k vs NDCG@k: main difference ?</strong></p><p>Order matters for both of MAP@k and NDCG@k. But the main difference is that MAP@k assumes binary relevance (an item is either of interest or not), while NDCG@k allows relevance scores in form of real numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/297f90dd130f31571494adbdbbd63af1/href">https://medium.com/media/297f90dd130f31571494adbdbbd63af1/href</a></iframe><p>What about metrics for continuous variables ?</p><h3>Regression Metrics</h3><p>When it comes to regression performance metrics … MAE and RMSE are 2 of the most popular metrics.</p><h4>Mean Absolute Error</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*kVz6tauEJSvqoUhJKwKdCw.png" /></figure><h4>Root Mean Squared Error</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*2FuOTKbl8Zv_lqSZBuuthQ.png" /></figure><p><strong>MAE vs RMSE: Which one should be used ?</strong></p><p>Here are some points that may help you decide:</p><blockquote>The RMSE is more appropriate to represent model performance than the MAE when the error distribution is expected to be Gaussian.</blockquote><blockquote>The MAE is suitable to describe uniformly distributed errors.</blockquote><blockquote>MAE is more robust to outliers: minimizing the squared error results in finding its mean, and minimizing the absolute error results in finding its median. And we all know that the median is more robust to outliers than the simple mean.</blockquote><blockquote>RMSE avoids the use of absolute value which is highly undesirable in many mathematical computations. For instance, it might be difficult to calculate the gradient of the MAEs with respect to certain model parameters.</blockquote><p>….What about <strong>R² ?</strong></p><h3>R-squared</h3><p>The definition of R-squared is fairly straight-forward: it is the percentage of the response variable variation that is explained by a linear model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*Qa-yBGhyT-_ovCfcP3kaiw.png" /></figure><p><strong>Misconception:</strong> R² does not lie between 0 and 1. The maximum value of R² is 1 but it may take a negative value.</p><p><strong>Any problem with R² ?</strong></p><p>YES !!! R² always increase when adding new predictors no matter whether they are useful or not:</p><blockquote><em>Whenever you add a variable to your model, the value of its estimated coefficient can either be zero, in which case the proportion of explained variance stays unchanged, or take a nonzero value </em><strong><em>because it improves the quality of the fit</em></strong><em>. By construction, your </em>R²<em> cannot be smaller after adding a variable - </em><a href="https://www.quora.com/Why-when-the-number-of-variables-increases-does-the-R-square-also-increase-in-linear-regression"><em>Maxime Phillot response on Quora</em></a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*COUXre4yBp--B-Azd2iIrQ.jpeg" /></figure><p>How can we overcome this issue ?</p><h4><strong>Adjusted R²</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*YH-Hx6WHgGRJef9lODltlQ.png" /></figure><p>where n is the total number of observations and k is the number of predictors.</p><p>This metric will increase if you add the useful terms and it will decrease if you add less useful predictors.</p><h3>More metrics !!!!</h3><h4><strong>NLP/NLG metrics: BLEU and ROUGE</strong></h4><p>These 2 metrics are complementing and are mostly used for evaluating automatic summarization of texts as well as machine translation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*0mDi2W00z7a4PAiae7mLhQ.jpeg" /></figure><h4>BLEU (Bilingual Evaluation Understudy)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/772dd01700ba6bb6470f2961463eda12/href">https://medium.com/media/772dd01700ba6bb6470f2961463eda12/href</a></iframe><h4><strong>ROUGE (Recall-Oriented Understudy for Gisting Evaluation)</strong></h4><p>ROUGE is based only on recall.</p><p>Based on the feature used for computing recall, ROUGE may be of many types:</p><ul><li><strong>ROUGE-N</strong> based on unigram, bigram, trigram or higher order <strong>N</strong>-gram overlap.</li><li><strong>ROUGE-L/W/S</strong> based on <strong>L</strong>ongest common subsequence (LCS), <strong>W</strong>eighted LCS, and <strong>S</strong>kip-bigram co-occurence statistics, respectively.</li></ul><p>For more information about these metrics you can refer to <a href="http://www.aclweb.org/anthology/W04-1013">Lin’s paper</a>.</p><h4><strong>Speech Recognition metric: WER (Word error rate)</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*sJWe43a5JwObFJ3xYcRnDQ.png" /></figure><p>WER is a common metric used for evaluating ASR (automatic speech recognition) systems. Here is a simple way to understand how WER is calculated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*nPzfbxGYlVAxdqjHo1WHug.png" /></figure><blockquote>Deletion:</blockquote><blockquote><strong>Voice input: </strong>I was connected yesterday <br><strong>ASR result: </strong>I connected yesterday</blockquote><blockquote>Insertion:</blockquote><blockquote><strong>Voice input: </strong>I was connected yesterday <br><strong>ASR result: </strong>I was connected the yesterday</blockquote><blockquote>Substitution:</blockquote><blockquote><strong>Voice input: </strong>I was connected yesterday<br><strong>ASR result: </strong>I was connected yes</blockquote><h3><strong>Bonus !</strong></h3><p>You deserve it for reaching the end.</p><p>Here is a list of challenges you can find in the web that use one of the metrics we presented to evaluate the performance of the participant’s model.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fairtable.com%2Fembed%2FshrWdDHxMcbHJc476&amp;url=https%3A%2F%2Fairtable.com%2FshrWdDHxMcbHJc476&amp;image=https%3A%2F%2Fstatic.airtable.com%2Fimages%2Foembed%2Fairtable.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=airtable" width="800" height="533" frameborder="0" scrolling="no"><a href="https://medium.com/media/e78e114710bc467087ed29ecb68177ca/href">https://medium.com/media/e78e114710bc467087ed29ecb68177ca/href</a></iframe><h3><strong>Conclusion</strong></h3><p>There’s no hard rule to find an ideal metric that says what should be minimized/maximized in all the situations! It purely depends on the business needs and the context of the problem you are trying to solve. The main message is simply that metrics should be embraced and play a critical part when defining a problem.</p><p>Stay tuned and if you liked this article, please leave a 👏 !</p><h3><strong>References</strong></h3><p>[1] <a href="https://www2.unil.ch/biomapper/Download/Lobo-GloEcoBioGeo-2007.pdf">Jorge M. Lobo , A. Jiménez and R.Raimundo, AUC: a misleading measure of the performance of predictive distribution models, 2007</a></p><p>[1] <a href="https://arxiv.org/abs/1508.00298">Kun Lu, Two-Way Partial AUC and Its Properties, 2017</a></p><p>[2] <a href="https://web.stanford.edu/class/cs276/handouts/EvaluationNew-handout-6-per.pdf">Introduction to Information Retrieval, Stanford course</a></p><p>[2]<a href="http://www.aclweb.org/anthology/W04-1013"> Chin-Yew Lin, ROUGE: A Package for Automatic Evaluation of Summaries,2004</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99ccbe73de61" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/choosing-the-right-metric-is-a-huge-issue-99ccbe73de61">What’s WRONG with Metrics?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Noise to your advantage ?]]></title>
            <link>https://medium.com/data-science/how-to-use-noise-to-your-advantage-5301071d9dc3?source=rss-7a4cf5f2ff10------2</link>
            <guid isPermaLink="false">https://medium.com/p/5301071d9dc3</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <dc:creator><![CDATA[Amine Aoullay]]></dc:creator>
            <pubDate>Fri, 08 Jun 2018 11:22:20 GMT</pubDate>
            <atom:updated>2018-06-10T10:10:42.550Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4TyYgJ-3u5hNWwVD" /><figcaption>Photo by <a href="https://unsplash.com/@jasonrosewell?utm_source=medium&amp;utm_medium=referral">Jason Rosewell</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fplay.ht%2Farticles%2F5301071d9dc3&amp;src=https%3A%2F%2Fplay.ht%2Fembed%2F%3Farticle_url%3Dhttps%3A%2F%2Fmedium.com%2F_p%2Fhow-to-use-noise-to-your-advantage-5301071d9dc3&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=play" width="700" height="185" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6a7b2d3453e165040bf348b4341452e/href">https://medium.com/media/f6a7b2d3453e165040bf348b4341452e/href</a></iframe><blockquote><strong>Noise is the number 1 enemy of engineers.</strong></blockquote><p>For scientists, random fluctuations, or noise is undesirable.</p><p>Although typically assumed to degrade performance, it can sometimes improve information processing in non-linear systems. In this post we’ll see some examples where the noise can be used as an advantage.</p><h3>Example 1</h3><h4>Adding Noise into Neural Network</h4><p>Recent works have shown that, by allowing some inaccuracy when training deep neural networks, not only the training performance but also the accuracy of the model can be improved.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F12hBAKC9hS16yQ%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fnoise-12hBAKC9hS16yQ&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F12hBAKC9hS16yQ%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="176" frameborder="0" scrolling="no"><a href="https://medium.com/media/72ab7c65d10604f171e2884d9692f3ac/href">https://medium.com/media/72ab7c65d10604f171e2884d9692f3ac/href</a></iframe><p>Neural networks are capable of learning output functions that can change wildly with small changes in input. Adding noise to inputs randomly is like telling the network to not change the output in a ball around your exact input.</p><p>By limiting the amount of information in a network, we force it to <strong>learn</strong> <strong><em>compact representations</em> </strong>of input features.</p><ul><li><a href="https://arxiv.org/abs/1312.6114"><strong>Variational autoencoders</strong> (VAE)</a> add Gaussian noise to the hidden layer.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*0Ui6q__i0hIsO1DkoyEyxg.png" /></figure><ul><li><a href="http://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf"><strong>Dropout Regularization</strong></a>: randomly zeroing out some fraction of units during training. This technique forces the network to learn useful information under limited bandwidth.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tvcv2PT3cBAmUtZzQTmjeQ.png" /></figure><ul><li><a href="https://arxiv.org/abs/1603.09382"><strong>Deep Networks with Stochastic Depth</strong></a> : similar idea to dropout, but at a per-layer level rather than per-unit level.</li></ul><h3>Example 2</h3><h4>Better Exploration with Parameter Noise</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*1Pda5gvc4ARIO53vnLvnug.png" /></figure><p>RL is an area of <a href="https://en.wikipedia.org/wiki/Machine_learning">machine learning</a> that assumes there is an <strong><em>agent </em></strong>situated in an <strong><em>environment</em></strong>. At each step, the agent takes an <strong><em>action</em></strong>, and it receives an <strong><em>observation</em></strong> and <strong><em>reward</em></strong> from the environment.</p><p>An RL algorithm seeks to maximize the agent’s total reward, given a previously unknown environment, through a learning process that usually involves lots of trial and error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*yqgtLZCaonZDLF45UXy_Mg.jpeg" /></figure><p>To understand the challenge with exploration in Deep RL systems think about researchers that spend lot of times in a Lab without producing any practical application. Equivalently, RL agents can spend a huge amount of resources without converging to a local optimum.</p><p>OpenAI proposes a technique called Parameter-Space-Noise, that introduces noises in the model policy parameters at the beginning of each episode.</p><p>Other approaches were focused on what is known as Action-Space-Noise which introduce noise to change the likelihoods associated with each action the agent might take from one moment to the next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*qwVZzObbaefppvJr30Suhw.png" /><figcaption>Action-Space-Noise (left) and Parameter-Space-Noise (right)</figcaption></figure><blockquote>“We’ve found that adding adaptive noise to the parameters of reinforcement learning algorithms frequently boosts performance” — OpenAI</blockquote><p>The initial results of the Parameter-Space-Noise model proved to be really promising. The technique helps algorithms explore their environments more effectively, leading to higher scores and more elegant behaviors. More details can be found in <a href="https://arxiv.org/abs/1706.01905">the research paper.</a></p><p>The important thing to remember is that adding noise was used as an advantage to boost the exploration performance of reinforcement learning algorithms.</p><h3>Example 3</h3><h4>LEARNING FROM NOISY LABELS (weakly supervised training)</h4><p>Boosting recognition isn’t as simple as throwing more labeled images at these systems. Indeed, manually annotating a large number of images is an expensive and time consuming process.</p><p>Facebook researchers and engineers have addressed this by training image recognition networks on large sets of public images with hashtags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*ZZYQx6or-00YQae2amczgw.png" /></figure><p>Since people often caption their photos with hashtags, it woul’d be a good source of training data for models.</p><p>Facebook developed new approaches that are tailored for doing image recognition experiments using hashtag supervision. This study is described in detail in <a href="https://research.fb.com/publications/exploring-the-limits-of-weakly-supervised-pretraining/">“<strong>Exploring the Limits of Weakly Supervised Pretraining</strong>”</a></p><p>On the COCO object-detection challenge, it has been shown that the use of hashtags for pretraining can boost the average precision of a model by more than 2 percent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WR3dOULWegRxm4EddXyuSQ.jpeg" /></figure><blockquote>“Hashtags can help computer vision systems go beyond general classification terms, in order to recognize specific subcategories and additional elements in an image” — Facebook</blockquote><h3>Conclusion</h3><p>Noise should not be our enemy ! It isn’t always an unwanted disturbance and can often be used as an advantage and even serve as a valuable research tool. If anyone tries to tell you otherwise, well, just give him the examples we presented …</p><p>Stay tuned and if you liked this article, please leave a 👏!</p><h3>Reference</h3><p>[1] Weakly-supervised-pretraining: <a href="https://research.fb.com/publications/exploring-the-limits-of-weakly-supervised-pretraining/">https://research.fb.com/publications/exploring-the-limits-of-weakly-supervised-pretraining/</a></p><p>[2] Better Exploration with Parameter Noise: <a href="https://blog.openai.com/better-exploration-with-parameter-noise/">https://blog.openai.com/better-exploration-with-parameter-noise/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5301071d9dc3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-to-use-noise-to-your-advantage-5301071d9dc3">How to use Noise to your advantage ?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tag2Image and Image2Tag — Joint representations for images and text]]></title>
            <link>https://medium.com/data-science/tag2image-and-image2tag-joint-representations-for-images-and-text-9ad4e5d0d99?source=rss-7a4cf5f2ff10------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ad4e5d0d99</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Amine Aoullay]]></dc:creator>
            <pubDate>Sun, 03 Jun 2018 15:31:21 GMT</pubDate>
            <atom:updated>2018-06-03T16:11:12.298Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*BGyXPUfDXy8_NF8eLwnIoA.jpeg" /></figure><p>Parsing a complex scene and describing its content is not a complex task for humans. Indeed, people can quickly summarize a complicated scene in a few words. But it’s much more complex for computers. To produce systems that can achieve this, we need to combine current state-of-the-art techniques in both Computer Vision and Natural Language Processing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*fCGGx-dXeHtsWKQ449RoWQ.jpeg" /></figure><p>As a first step, we are going to see how to generate feature vectors for both visual images and text data. Then describe the CCA algorithm that will help us join the constructed features in a common space. And finally, present the results of 2 pipelines (<strong>Text2Image</strong> and<strong> Image2Text</strong>) on <a href="http://cocodataset.org/#home">Microsoft COCO dataset</a>.</p><h3>Transfer Learning</h3><h4>Image Features</h4><p>A Convolutional Neural Network (CNN) can be used to extract features from images. The 16-layer VGGNet pre-trained on ImageNet is an example. It was the state-of-the-art model in ImageNet Challenge 2014. We only need to remove the last fully-connected layer and treat the rest of the CNN as a fixed feature extractor for our dataset. This would compute a 4096-D vector for every image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*0Re5o75Qz8vIAYpfWqlrpA.jpeg" /><figcaption>VGG-16 Architecture</figcaption></figure><h4>Tag Features</h4><p>Word embeddings are a group of natural language processing tools aiming at mapping words into a high geometric space. In other words, a word embedding function takes a text corpus as input and produces the word vectors as output such that the distance between any two vectors would capture part of the semantic relationship between the two associated words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*WvCeXN434jvpFFNHKSARow.jpeg" /></figure><p>As an example, ”student” and ”aircraft” are words that are semantically different, so a reasonable embedding space would represent them as vectors that would be very far apart. But ”breakfast” and ”kitchen” are related words, so they need to be embedded close to each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*MD02Y2y4dL4oz9GUtl9zqw.png" /><figcaption>Word embedding space example</figcaption></figure><p>To achieve this mapping, we can use any state-of-the-art pre-trained model: Word2Vec(300-dimensional word vectors pre-trained on Google News dataset) or GLOVE(300-dimensional word vectors pre-trained on Common Crawl dataset with 1.9M vocab)</p><h3>CCA (Canonical Correlation Analysis)</h3><p>Now, we are going to give the high level ideas about a popular and successful approach for mapping visual and textual features to the same latent space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*TpsKmyWFka7Zb_yQ_qGF7w.jpeg" /><figcaption>Two-view CCA minimizes the distance (equivalently, maximizes the correlation) between images (triangles) and their corresponding tags (circles)</figcaption></figure><p>Given 2 sets of N vectors: <strong>X</strong> referring to the image features and <strong>Y</strong> representing the textual features. Let their covariances <strong>Σ</strong>xx and <strong>Σ</strong>yy respectively, and let <strong>Σ</strong>xy be the cross-covariance.</p><p>The linear Canonical Correlation Analysis (CCA) seeks pairs of linear projections that maximizes the correlation of the two views:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*sEbZseXIkQmHFi3-aX9p_A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*ZDrhdByphw-QR53mtc6jbA.jpeg" /></figure><p>The CCA objective can be written as the following optimization problem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*kRL1NkLN0rm57r8cI3CTdA.jpeg" /></figure><p>Let x and y be points referring to the textual and visual data respectively. To compare x and y we can use the cosine similarity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*Hfj7O2OUShhJG_3lEX6ngw.jpeg" /><figcaption>Similarity function</figcaption></figure><h3>Qualitative Results</h3><p>In MS COCO dataset, each image is described by 5 captions. A first step consists of pre-possessing these captions by removing all the stop words and then concatenate them to get one bag of words (BoW). Afterwards, we perform a weighted average of all the embedding words using the TF-IDF technique which consists on weighting words based on how frequently they occur in each caption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*ILLLboAd5A-McZVE8eKZyw.jpeg" /><figcaption>Example of an image and its corresponding captions</figcaption></figure><h4>Tag2Image</h4><p>For this task, we aim to retrieve images that are described by a given query text. Given a query text, we first project its feature vector into the CCA space, and then use it to retrieve the most similar image features from the database.</p><p>Query 1: “<strong>A man playing tennis”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vrROcNu8Eb5EkJzid_KOtQ.jpeg" /></figure><p>Query 2:<strong> “A man jumping in the air in a skateboard”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peaesEd9h0UWicRsgIDTXQ.jpeg" /></figure><p>We can clearly remark that the retrieved images are very close from the query image.</p><h4>Image2Tag</h4><p>Here, we aim to find a set of tags that properly describe a query image. Given a query image, we first project its feature vector into the CCA space, and then use it to retrieve the most similar text features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*9F-UUqj0acpczpIfl4mjxw.jpeg" /></figure><p>In general the retrieved keywords describe quite well the query images. However, we can identify some errors (in red). For instance, with the last example, the word ”walking” was wrongly retrieved. We think that it may be due to the fact that there are many images in the training set that contain both ”people” and ”walking”.</p><h3>Conclusion</h3><p>Canonical Correlation Analysis can be used to build pipelines of multimodal retrieval. Giving a data set of images and their tags, CCA maps their corresponding feature vectors to the same latent space where a common similarity measure could be used to perform Image2Tag and Tag2Image search tasks.</p><p>Stay tuned and if you liked this article, please leave a 👏!</p><h3>Reference</h3><p>[1] <a href="http://slazebni.cs.illinois.edu/publications/yunchao_cca13.pdf">CCA:A Multi-View Embedding Space for Modeling Internet Images, Tags, and their Semantics.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ad4e5d0d99" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/tag2image-and-image2tag-joint-representations-for-images-and-text-9ad4e5d0d99">Tag2Image and Image2Tag — Joint representations for images and text</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spectral Clustering for beginners]]></title>
            <link>https://medium.com/data-science/spectral-clustering-for-beginners-d08b7d25b4d8?source=rss-7a4cf5f2ff10------2</link>
            <guid isPermaLink="false">https://medium.com/p/d08b7d25b4d8</guid>
            <category><![CDATA[graph-theory]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Amine Aoullay]]></dc:creator>
            <pubDate>Mon, 07 May 2018 22:03:14 GMT</pubDate>
            <atom:updated>2018-06-03T17:23:45.027Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AMVjchRuwLEw0iaBzqNZgw.jpeg" /></figure><p>Clustering is one of the most widely used techniques for exploratory data analysis. Its goal is to divide the data points into several groups such that points in the same group are similar and points in different groups are dissimilar to each other.</p><p>Spectral clustering has become increasingly popular due to its simple implementation and promising performance in many graph-based clustering. It can be solved efficiently by standard linear algebra software, and very often outperforms traditional algorithms such as the k-means algorithm.</p><p>Here, we will try to explain very briefly how it works !</p><p>To perform a spectral clustering we need 3 main steps:</p><ol><li>Create a similarity graph between our <em>N</em> objects to cluster.</li><li>Compute the first k eigenvectors of its Laplacian matrix to define a feature vector for each object.</li><li>Run k-means on these features to separate objects into k classes.</li></ol><h4>Step 1:</h4><p>A nice way of representing a set of data points <em>x</em>1, . . . <em>x</em> <em>N</em> is in form of the similarity graph <em>G</em>=(<em>V</em>,<em>E</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*xf0bKxqYRVMAQGaNAAgw8g.jpeg" /><figcaption>Similarity Graph</figcaption></figure><p>There are different ways to construct a graph representing the relationships between data points:</p><ol><li>ε-neighborhood graph: Each vertex is connected to vertices falling inside a ball of radius ε where ε is a real value that has to be tuned in order to catch the local structure of data.</li><li>k-nearest neighbor graph: Each vertex is connected to its k-nearest neighbors where k is an integer number which controls the local relationships of data.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*A2ic_xbhGmd8zWPr3BxlrA.png" /><figcaption>Different similarity graphs</figcaption></figure><p>In the above example we drawn 3 clusters: two “moons” and a Gaussian.</p><p>In the ε-neighborhood graph, we can see that it is difficult to choose a useful parameter ε. With ε = 0.3 as in the figure, the points on the middle moon are already very tightly connected, while the points in the Gaussian are barely connected. This problem always occurs if we have data “on different scales”, that is the distances between data points are different in different regions of the space. However, the k-nearest neighbor graph, can connect points “on different scales”. We can see that points in the low-density Gaussian are connected with points in the high-density moon.</p><h4>Step 2:</h4><p>Now that we have our graph, we need to form its associated Laplacian matrix.</p><p><strong>N.B</strong>: The main tools for spectral clustering are graph Laplacian matrices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GD0E2nvpj853wOz5WTB35Q.jpeg" /></figure><p>All we have to do now is to compute the eigenvectors <em>u</em>_ <em>j</em> of <strong>L </strong>.</p><h4>Step 3:</h4><p>Run k-means :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWNi1CKrMmh3LdPOC20mCA.png" /></figure><p><strong>Application</strong> : spectral clustering in image processing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1irn9cmnbEOY7MVlQ6ojg.png" /><figcaption>Original image (left) and segmented image using spectral clustering (right)</figcaption></figure><h4><strong>Bonus</strong> : How to choose k ?</h4><p>By projecting the points into a non-linear embedding and analyzing the eigenvalues of the Laplacian matrix one can deduce the number of clusters present in the data. When the similarity graph is not fully connected, the multiplicity of the eigenvalue λ = 0 gives us an estimation of k.</p><h3>Conclusion</h3><p>In every scientific field dealing with empirical data, people try to get a first impression on their data by trying to identify groups of similar behavior in their data. In this article we presented how the spectral clustering algorithm works via embedding the vertices of a graph into a low-dimensional space using the bottom eigenvectors of the Laplacian matrix.</p><p>Stay tuned and if you liked this article, please leave a 👏!</p><h3>References</h3><p>[1]<a href="https://www.omicsonline.org/open-access/image-segmentation-by-using-linear-spectral-clustering-2167-0919-1000143.php?aid=81482"> Image Segmentation by Using Linear Spectral Clustering, Sandeep Reddy</a> [2] <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.708.6592&amp;rep=rep1&amp;type=pdf">Graphs in Machine Learning, Michal Valko</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d08b7d25b4d8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/spectral-clustering-for-beginners-d08b7d25b4d8">Spectral Clustering for beginners</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>