<?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 Jaime Ramírez on Medium]]></title>
        <description><![CDATA[Stories by Jaime Ramírez on Medium]]></description>
        <link>https://medium.com/@jramcast?source=rss-581b6c223324------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ddLGEiDyRBfnBkVs.jpg</url>
            <title>Stories by Jaime Ramírez on Medium</title>
            <link>https://medium.com/@jramcast?source=rss-581b6c223324------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:26:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jramcast/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[Curvas PR y ROC]]></title>
            <link>https://medium.com/bluekiri/curvas-pr-y-roc-1489fbd9a527?source=rss-581b6c223324------2</link>
            <guid isPermaLink="false">https://medium.com/p/1489fbd9a527</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[performance-measurement]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Jaime Ramírez]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 06:13:54 GMT</pubDate>
            <atom:updated>2018-07-19T06:13:54.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OtLIIU30qvUYelUrK7NBQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/VidPb_9mOr4?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Juan Gomez</a> on <a href="https://unsplash.com/search/photos/curve-guggenheim?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Las curvas ROC y PR (precision-recall) son herramientas utilizadas en la evaluación del rendimiento de clasificadores binarios. Estas curvas nos indican de manera visual la relación entre la precisión y la sensibilidad de nuestro modelo, a la vez que sirven para comparar el rendimiento de distintos modelos de clasificación.</p><h3>Precision y Recall</h3><p>Es necesario conocer los conceptos de <strong>precision</strong> y <strong>recall</strong> para entender estas curvas. A pesar de que son conceptos bastante conocidos en el mundo del <strong>machine-learning</strong> y la <strong>inteligencia artificial</strong>, los explicaré brevemente. Estos conceptos nacen de una serie de indicadores que contabilizan si las predicciones de un clasificador binario(positivo o negativo) se han realizado correctamente:</p><p><strong>TP (True positives)</strong>: ejemplos positivos clasificados correctamente. Por ejemplo, supongamos que tenemos un clasificador binario de imágenes de gatitos que nos indica si la imagen es de un gatito o no. El TP es el número de imágenes de gatitos clasificadas positivamente.</p><p><strong>FP (False positives)</strong>: ejemplos negativos clasificados incorrectamente como positivos. En el ejemplo de los gatitos, sería el número de imágenes sin gatitos que son clasificadas positivamente como imagen de gatito. Se puede considerar este valor como aquellas fallos cometidos debido a clasificaciones muy optimistas (muy sesgadas hacia el caso positivo).</p><p><strong>TN (True negatives): </strong>ejemplos negativos clasificados correctamente. De nuevo, en el ejemplo de los gatitos, sería el número de imágenes sin gatitos que son clasificadas negativamente (imagen sin gatito)</p><p><strong>FN (False negatives)</strong>: ejemplos positivos clasificados incorrectamente como positivos. En nuestro ejemplo, es el número de imágenes de gatitos que son clasificadas como negativamente (imagen sin gatito). Podemos pensar en este indicador como el número de ejemplos correctos que escapan a nuestro “radar”.</p><p>Con estas cuatro métricas, podemos calcular los ratios de <strong>precision</strong> y <strong>recall</strong>.</p><p><strong>Precision</strong>: la precisión es el ratio o porcentaje de clasificaciones correctas de nuestro clasificador. En otras palabras, de todo lo que nuestro clasificador clasifica como positivo, correcta o incorrectamente (TP + FP), cual es el ratio de clasificaciones correctas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*e50ohlM6n_yGfsgSpehAIA.png" /></figure><p><strong>Recall</strong>: el recall o <strong>sensibilidad</strong> de nuestro modelo es el ratio de positivos detectado en el dataset por nuestro clasificador. En otras palabras, de todos los positivos reales de nuestro dataset, detectados o no(TP + FN), cual es el ratio de positivos detectados.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*BDfjyiRRMS6oB46S4lTnAw.png" /></figure><h3>Equilibrio entre Precision y Recall</h3><p>Las métricas de precision y recall están relacionadas de manera que si entrenas tu clasificador para aumentar la precisión, disminuirá el recall y viceversa. Veamos la aplicación de esta relación en nuestro ejemplo de los gatitos:</p><p>Supongamos que queremos hacer que nuestro clasificador sea muy sensible a imágenes de gatitos, es decir, queremos aumentar el recall, probablemente a un valor cercano a 1 (100%). Podríamos hacer esto fácilmente si hacemos que nuestro modelo sea una función simple que siempre devuelva True. La desventaja de esto es que nuestra precisión sería muy pobre, prácticamente aleatoria, probablemente cerca del 0.5 si nuestro dataset está balanceado.</p><p>Ahora supongamos que queremos un clasificador muy preciso, con una precisión cerca del 1. Evidentemente, si nuestro clasificador es muy “tiquismiquis” a la hora de considerar una imagen de gatito como válida, nos dejaremos muchas por el camino (tendremos muchos FN) y esto reducirá el recall. Nuestro clasificador será muy preciso, pero menos sensible.</p><p>¿Y como le decimos al clasificador cuál si queremos que sea más preciso, o más sensible? Generalmente, el modelo tomará la decisión de si la clasificación es positiva o negativa si el valor devuelto por el modelo supera un <strong>decision threshold </strong>o umbral de decisión. Si aumentamos este valor, estaremos aumentando la precisión, si lo disminuimos, aumentamos la sensibilidad (recall).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*XSpJVAaTsNFPuVpazuvFEQ.png" /><figcaption>Equilibrio precision-recall en función del umbral de decisión</figcaption></figure><p>Aquí es donde las curvas PR y ROC nos ayudan a ver el equilibrio entre precisión y sensibilidad de un modelo.</p><h3>PR curve (curva precision-recall)</h3><p>La curva PR es el resultado de dibujar la gráfica entre el precision y el recall. Esta gráfica nos permite ver a partir de qué recall tenemos una degradación de la precisión y viceversa. <strong>Lo ideal sería una curva que se acerque lo máximo posible a la esquina superior derecha</strong> (alta precisión y alto recall)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*7mR5PYXP6g6Rm1jsx5qPyQ.png" /></figure><p>En en título del gráfico vemos AP=0.62. Este valor es el <strong>Average precision </strong>y es una manera de calcular el área bajo la curva PR o <strong>PR AUC</strong>, o lo que es lo mismo, el resultado de integrar la curva. El Average Precision nos sirve para evaluar y comparar el rendimiento de modelos. Cuanto más se acerque su valor a 1, mejor será nuestro modelo.</p><h3>ROC curve</h3><p>La curva ROC (receiver operating characteristic) es parecida a la curva PR pero cambiando algunos valores. Relaciona el recall con el ratio de falsos positivos. Es decir relaciona la sensibilidad de nuestro modelo con los fallos optimistas (clasificar los negativos como positivos). Tiene sentido ya que, generalmente, si aumentamos el recall, nuestro modelo tenderá a ser más optimista e introducirá mas falsos positivos en la clasificación.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*QE3RnPEQuxPYBovUZ-mu2Q.png" /></figure><p><strong>En las curvas ROC, nos interesa que la curva se acerque lo máximo posible a la esquina superior izquierda</strong> de la gráfica, de manera que el hecho de aumentar la sensibilidad (el recall) no haga que nuestro modelo introduzca más falsos positivos.</p><p>En este caso también podemos calcular el <strong>ROC AUC,</strong> que también nos sirve como métrica para resumir la curva y poder comparar modelos. De manera similar al Average Precision, nos interesa que su valor se acerque lo máximo posible a 1.</p><h3>Diferencias entre curvas ROC y PR</h3><p>Por lo general, usaremos la curva <strong>PR</strong> o el <strong>Average Precision</strong> cuando tengamos problemas de<strong> datasets no balanceados</strong>, es decir, cuando la clase positiva ocurre pocas veces. Cuando hay pocos ejemplos positivos, la curva ROC o el ROC AUC puede dar un valor alto, sin embargo, la curva PR estará lejos de su valor óptimo, poniendo de manifiesto un indicador de precisión relacionado con la baja probabilidad de la clase positiva.</p><p>Será una opción interesante usar la curva <strong>ROC</strong> y el <strong>ROC AUC </strong>cuando tengamos un dataset más balanceado o queramos poner de manifiesto un indicador más relacionado con falsas alarmas (falsos positivos).</p><h3>Referencias</h3><ul><li><a href="http://www.chioka.in/differences-between-roc-auc-and-pr-auc/">Differences between Receiver Operating Characteristic AUC (ROC AUC) and Precision Recall AUC (PR AUC)</a></li><li><a href="https://dl.acm.org/citation.cfm?id=1143874">The relationship between Precision-Recall and ROC curves</a></li><li><a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.average_precision_score.html">sklearn.metrics.average_precision_score - scikit-learn 0.19.1 documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1489fbd9a527" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bluekiri/curvas-pr-y-roc-1489fbd9a527">Curvas PR y ROC</a> was originally published in <a href="https://medium.com/bluekiri">bluekiri</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quality JavaScript projects: testing and linting]]></title>
            <link>https://medium.com/bluekiri/quality-javascript-projects-testing-and-linting-653fc056698d?source=rss-581b6c223324------2</link>
            <guid isPermaLink="false">https://medium.com/p/653fc056698d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Jaime Ramírez]]></dc:creator>
            <pubDate>Wed, 20 Dec 2017 16:14:33 GMT</pubDate>
            <atom:updated>2018-01-08T11:29:27.614Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4aK1MCwOStCcRUyOJoAelQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/BVGMRRFQcf8?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Volkan Olmez</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Thanks to our friend <a href="https://simple.wikipedia.org/wiki/Second_law_of_thermodynamics">the second law of thermodynamics</a>, every aspect of our lives tends to turn into chaos if not subject to proper maintenance and dedication. Software projects are not an exception and I do not need to tell you <strong>how easy it is for a software product to evolve into an awful buggy mess</strong>. Fortunately, nowadays we have a set of validated practices that help and tell us how to create, design and maintain quality software.</p><p>Applying these techniques to our JavaScript projects is not harder than in any other language. I would say it’s even easier, thanks to the vast amount of libraries and tools out there and the active community.</p><p>Here at <a href="https://bluekiri.com/"><strong>Bluekiri</strong></a> we are in the process of improving quality in our JavaScript projects using best practices. Let me show what we are aiming for…</p><h3>Testing</h3><p>As developers, the most common scenario for us is writing unit tests or integration tests. Ocassionally, you might find yourself writing other types of tests, such as functional or E2E tests. I will mainly focus on unit testing here.</p><h4>Mocha or Jest?</h4><p>Among JavasScript testing frameworks, I’ve happily used <a href="https://mochajs.org/">Mocha</a> for years. It is simple, fast, stable and widely adopted. Mocha allows us to easily create test suites (not necessarily unit tests, but also integration tests, and even functional tests). This simplicity comes with a small disadvantage: if your need other testing features, you’ll have to spend more time installing and configuring additional tools.</p><p>I recently gave <a href="https://facebook.github.io/jest/">Jest</a> a try. It feels a bit slower than Mocha, but I like the fact that many features are already integrated and the setup is a piece of cake. For example, I am a big fan of desktop notifications while developing. Sometimes the terminal where you run tests is minified, or not visible in your desktop at the exact moment you make a change in your code. <strong>With desktop notifications, you’ll always have instant visual feedback if you break something</strong>, which is specially helpful for <a href="http://blog.cleancoder.com/uncle-bob/2014/12/17/TheCyclesOfTDD.html">TDD and its red-green-refactor cycle</a>. However, if you want desktop notifications with Mocha, <a href="https://github.com/mochajs/mocha/wiki/Growl-Notifications">you’ll need to install additional libraries</a>, which differ across plaforms (Linux, Windows and Mac).</p><p>Jest also includes built-in code coverage reports, so, for example, you can control whether or not your CI builds pass based on these reports. When working with Mocha, you would need to install coverage tools, such as Istanbul. That being said, Jest’s built-in code coverage is based on Istanbul underneath, so the only difference is that Jest installs it for you and saves you the hassle of writing some scripts for code-coverage checking.</p><p>In addition to using Mocha or Jest, I also use <a href="http://chaijs.com/">Chai</a> as a way to write more readable assertions. The more readable your tests are, the better. Why? Keeping your tests readable makes them easier to maintain. If your tests are easy to maintain, they are less likely to be abandoned.</p><h3>Code linting</h3><p>Code linting ensures that our team’s coding standards are met. Keeping a stable coding standard gives us <a href="https://hackernoon.com/how-linting-and-eslint-improve-code-quality-fa83d2469efe">many benefits</a> such as code quality, readiblity or consistency. It makes it easier for developers to share knowledge, grab code from other colleagues, or in the case of interpreted languages, like JavaScript, protects us against syntax errors.</p><p>I have been using <a href="https://eslint.org/">ESLint</a> for a while. ESLint allows you to create your own coding standard definitions and also extend existing ones. For example, I sometimes extend Airbnb’s <a href="https://github.com/airbnb/javascript">JavaScript Style Guide</a> and adapt it to my needs. Here is an example of a <strong>.eslintrc</strong> file to define our own standard:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a206f72376554cddfb22d8c3863b9857/href">https://medium.com/media/a206f72376554cddfb22d8c3863b9857/href</a></iframe><p>Additionaly, we can combine ESLint with plugins, such as <a href="https://prettier.io/">Prettier</a>, to autofix our linting errors.</p><h3>NPM</h3><p>So, now that we have our testing and linting tools installed and configured, we need to have a set of task or script definitions that integrates these tools with our development and build cycles. Basically this means creating a set of scripts necessary for all your development and build tasks. While Gulp or Grunt are certainly an option,<strong> I also think </strong><a href="https://medium.freecodecamp.org/why-i-left-gulp-and-grunt-for-npm-scripts-3d6853dd22b8"><strong>they add unnecessary abstractions and introduce more dependencies in your project</strong></a>. My preference here is to use NPM scripts to end up with something like this in our <strong>package.json</strong>:</p><pre>&quot;scripts&quot;: {</pre><pre>    &quot;start&quot;: &quot;node src&quot;,</pre><pre>    &quot;start:watch&quot;: &quot;nodemon src&quot;,</pre><pre>    &quot;test&quot;: &quot;jest test --collectCoverage --ci&quot;,</pre><pre>    &quot;test:watch&quot;: &quot;jest test --watchAll --notify&quot;,</pre><pre>    &quot;lint&quot;: &quot;eslint .&quot;,</pre><pre>    &quot;lint:fix&quot;: &quot;eslint --fix .&quot;</pre><pre>}</pre><p>What did we achieve here? Well, now, we have all these commands at our disposal, so for example, when I start making changes to my code, I will probably run npm run start:watch to launch my app in development mode, and, in another terminal, npm run test:watch to run my continuous testing script so that tests are run every time I make a change to my source code.</p><p>Our CI environment should also benefit from these scripts and base build definitions on them. A hypothetic testing stage would execute something like this:</p><pre>npm install<br>npm run lint<br>npm test</pre><p>Which lead us to my last point for today…</p><h3>Continuous integration</h3><p><strong>Be sure to run your tests and linter in your CI builds</strong>. This will ensure that your tests and your coding standards are always in use.</p><p><strong>If you do not have an automated continous integration system, your tests and coding standards are doomed. </strong>My experience is that developers won’t run tests every time they make a change(for hundreds of reasons: unawareness, lazyness, bad memory, lack of time…), your tests and coding standards will be eventually abandoned, and all your previous efforts will have been a waste of time.</p><h3><a href="https://www.npmjs.com/package/create-js-package">create-js-package</a></h3><p>I’ve created a simple tool that bootstraps new JavaScript projects including all these tools installed and ready to use. The tool generates new projects with the following features included:</p><ul><li>Unit testing with Jest and Chai.</li><li>Test watcher for continous testing.</li><li>Test coverage checking.</li><li>ES6 linting based on ESlint and Prettier.</li></ul><p>You can go and take a look at the <a href="https://www.npmjs.com/package/create-js-package">code</a> or also install the tool via NPM to generate your own projects.</p><p>In the next post, I’ll talk more about CI and release management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=653fc056698d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bluekiri/quality-javascript-projects-testing-and-linting-653fc056698d">Quality JavaScript projects: testing and linting</a> was originally published in <a href="https://medium.com/bluekiri">bluekiri</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>