<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/how-to-call-bullshit-on-ai-companies-aka-a-short-lesson-on-recall/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://cartesianfaith.com/2018/04/10/how-to-call-bullshit-on-ai-companies-aka-a-short-lesson-on-recall/"> R – Cartesian Faith</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Now that software ate the world, what’s for dessert? Those in the know know that it’s AI. It seems everyone took <a rel="nofollow" href="https://www.wired.com/2014/10/future-of-artificial-intelligence/" target="_blank">Kevin Kelly’s recommendation</a> to “take X and add AI” to heart. Fast forward to 2018 and all startups tout adding AI to X. There’s a fine line between hype and bullshit, so how do you separate the substance from the snake oil (or to be fair the dream)? Knowing how to do this is important for investors, prospective customers, and prospective employees.</p>
<div class="wp-caption"><img width="450" src="https://i2.wp.com/www.stageillusion.com/news/wp-content/uploads/Howard-Thurston-sawing.jpg">
<p class="wp-caption-text">Can you identify AI reality from AI illusion?</p>
</div>
<p>The simplest question to ask to cut through the bullshit is “what’s your recall?” You can follow that up with “is your data balanced?” to see through the illusion. Don’t know what recall is? Read on to learn what it is and why it’s important.</p>
<h3>The Abridged Introductory Primer On AI And Machine Learning Models</h3>
<p>Understanding error is key to most engineering and scientific fields. Models make predictions based on the data they were trained on. An error is the difference between what a model predicts and what the actual value is. Most machine learning models frame problems as a classification problem. Why? Here’s a thought experiment: is it easier to guess my weight or guess if I’m overweight or not? If you guessed the latter, read on!</p>
<p>Many classification problems get simplified to binary classification, such as whether <a rel="nofollow" href="https://www.youtube.com/watch?v=ACmydtFDTGs&feature=youtu.be" target="_blank">a picture contains a hot dog or not</a>. Binary decision problems seem trivial, but we use them all the time. For example, consider all of these <a rel="nofollow" href="http://pez.ai/blog/ai-social-impact-3-the-bias-edition/" target="_blank">AI-powered decisions</a>: grant loan/don’t grant loan, guilty/not guilty, hire/don’t hire.</p>
<div class="wp-caption"><img width="450" src="https://i0.wp.com/i.yomyomf.com/wp-content/uploads/2017/05/17233658/not_hot_dog_app.png.jpeg">
<p class="wp-caption-text">Binary classification problems are easiest to solve</p>
</div>
<p>Now, AI companies are obliged to tell you how great their model is. They may say something like “our model is 95% accurate”. Zowee! But what does this mean exactly? In terms of binary classification it means that the model chose the correct class 95% of the time. This seems pretty good, so what’s the problem?</p>
<p>Suppose I create an AI that guesses the gender of a technical employee at Facbook. As of 2017, <a rel="nofollow" href="https://www.forbes.com/sites/clareoconnor/2017/08/02/facebooks-diversity-report-shows-gains-for-women-but-workforce-remains-very-white/#6f9346244375" target="_blank">19% of STEM roles are held by women</a>. Behind the scenes, my model is really simple: it just chooses male every time (bonus question: is this AI?). Because of the data, my model will be 81% accurate. Now 95% doesn’t seem all that impressive. This dataset is known to be unbalanced, because the classes are not proportional. A better dataset would have about 50% women and 50% men. So asking if a dataset is balanced helps to identify some tricks that make models appear smarter than they are.</p>
<div class="wp-caption"><img src="https://i0.wp.com/i.kinja-img.com/gawker-media/image/upload/s--PMEhycaB--/c_fit,fl_progressive,q_80,w_636/1252084842069988967.jpg?w=450&ssl=1" data-recalc-dims="1">
<p class="wp-caption-text">My gender predictor always chooses men</p>
</div>
<h3>Error Metrics</h3>
<p>In machine learning (and elsewhere), two metrics help distinguish good models from bad models. (Disclosure: my model above is bad). Precision and recall are typically defined in terms of true and false. A true positive is when I guess true and the answer is true. How do I convert my male/female classes to true or false? Since there are just two classes, we can convert the classes into an equivalent predicate: <img alt="p(x) = x mbox{ is male}" title="p(x) = x mbox{ is male}" src="https://s0.wp.com/latex.php?latex=p%28x%29+%3D+x+%5Cmbox%7B+is+male%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">. This seems obvious for the male class. For the female class, we are saying that false means <img alt="x mbox{ is not male}" title="x mbox{ is not male}" src="https://s0.wp.com/latex.php?latex=x+%5Cmbox%7B+is+not+male%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">.</p>
<p>Precision is defined as the ratio of true positives versus the sum of true positives and false positives. Mathematically, this looks like</p>
<p><img alt="mbox{precision} = frac{TP}{TP + FP}" title="mbox{precision} = frac{TP}{TP + FP}" src="https://s0.wp.com/latex.php?latex=%5Cmbox%7Bprecision%7D+%3D+%5Cfrac%7BTP%7D%7BTP+%2B+FP%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">.</p>
<p>In other words, of all the cases where you guess true, how many were correct? In terms of gender, for all the cases where you guess male, how many were actually male? If I always guess male, then this value will be 81% if I’m looking at the Facebok data. </p>
<p>On the other hand, recall is the ratio of true positives versus the sum of true positives and false negatives.</p>
<p><img alt="mbox{recall} = frac{TP}{TP + FN}" title="mbox{recall} = frac{TP}{TP + FN}" src="https://s0.wp.com/latex.php?latex=%5Cmbox%7Brecall%7D+%3D+%5Cfrac%7BTP%7D%7BTP+%2B+FN%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<p>In this case, a false negative means seeing a male and guessing female. In other words, of all the male cases, how many did you correctly identify? My stupid model will have a recall of 1 since it never guesses female. A real model will behave differently. For example, in hiring, there may be a lot of highly qualified candidates. Suppose one of my criteria is that someone must come from a Top 10 school. That means I’ve filtered out a lot of highly qualified candidates. In essence, I’m labeling these highly qualified candidates as not qualified. This is a false negative. It’s easy to see how over-zealous filtering will result in a low recall but high precision.</p>
<p>The final metric is accuracy, which is often used in a general sense. The technical definition of accuracy is the sum of true positives and true negatives versus the total number of cases.</p>
<p><img alt="mbox{accuracy} = frac{TP + FP}{N}" title="mbox{accuracy} = frac{TP + FP}{N}" src="https://s0.wp.com/latex.php?latex=%5Cmbox%7Baccuracy%7D+%3D+%5Cfrac%7BTP+%2B+FP%7D%7BN%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<h3>The Relationship Between Precision And Recall</h3>
<p>To better understand the relationship between these two metrics, let’s look at hiring some more. There are numerous companies touting AI-based hiring. Some of these companies focus on screening resumes to identify candidates to interview. There are actually two decisions being made. First is whether to interview someone. The second is whether to hire someone. In predicate form, this looks like <img alt="p(x) = mbox{interview } x" title="p(x) = mbox{interview } x" src="https://s0.wp.com/latex.php?latex=p%28x%29+%3D+%5Cmbox%7Binterview+%7D+x&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">. In a typical scenario, a hiring manager looks at this pool of candidates and decides whether or not each one is actually worthy of an interview. This is precision. Remember that by using highly selective criteria or having an unbalanced dataset, it’s possible to skew precision. </p>
<p>Is this the right metric to evaluate a hiring model? Most tech companies complain that there aren’t enough qualified candidates. According to <a rel="nofollow" href="https://www.timeshighereducation.com/student/news/which-colleges-do-facebook-google-and-other-top-employers-recruit" target="_blank">one analysis</a>, over 50% of Facebook employees listed on LinkedIn graduated from a Top 10 university. (We’ll ignore how “Top 10” is defined for this discussion.) This is about 100,000 people annually out of <a rel="nofollow" href="https://nces.ed.gov/fastfacts/display.asp?id=372" target="_blank">about 3 million students</a> graduating with a bachelor’s or higher. Since Facebook is ignoring many qualified candidates (yes, this is a philosophical question) in the broader population, their hiring has low recall. This same problem exists in the financial world where investment banks and hedge funds typically only hire from the Ivy League. When this becomes part of the hiring rubric, recall is very low. In practical terms, we’re creating an artificially small talent pool in order to optimize precision. Yuck.</p>
<p>Models that follow a similar strategy will also have low recall. An algorithm that focuses on improving precision is only focusing on half the problem. A truly spectacular model would have high recall and high precision. So the next time someone talks about how great their model is, ask them what their recall is and whether their dataset is balanced.</p>
<h3>Technical Notes</h3>
<p>The easiest way to compute accuracy, precision, and recall in R is to construct a confusion matrix. Suppose you have a vector of predictions <code>pred</code> and a vector of actual results <code>act</code>. The confusion matrix is simply the contingency table.</p>
<pre>
pred &lt;- c(TRUE, TRUE, FALSE, TRUE, FALSE, TRUE)
act &lt;- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE)
cm &lt;- table(act, pred)
</pre>
<p>The three performance metrics can be computed easily. It’s useful to remember these definitions and know how to interpret them.</p>
<pre>
accuracy &lt;- sum(cm[diag(cm)]) / sum(cm)
precision &lt;- cm['TRUE','TRUE'] / sum(cm[,'TRUE'])
recall &lt;- cm['TRUE','TRUE'] / sum(cm['TRUE',])
</pre>
<p>Other error and performance metrics exist, not just for classification. Knowing which metrics to use depends on the situation and the relative impact of correct guesses versus incorrect guesses (e.g. mammograms have a high cost for false positives).</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://cartesianfaith.com/2018/04/10/how-to-call-bullshit-on-ai-companies-aka-a-short-lesson-on-recall/"> R – Cartesian Faith</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/uJj3f9z_e1Q" height="1"></a></div>