<?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 João Palmeiro on Medium]]></title>
        <description><![CDATA[Stories by João Palmeiro on Medium]]></description>
        <link>https://medium.com/@joaompalmeiro?source=rss-3f58d340dd3b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*aJunml7wqMuhYXcZ0X9JWw.jpeg</url>
            <title>Stories by João Palmeiro on Medium</title>
            <link>https://medium.com/@joaompalmeiro?source=rss-3f58d340dd3b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 11:00:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joaompalmeiro/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[BIY: Preparing a Dataset and Benchmarking AI Models for Scatterplot-Related Tasks]]></title>
            <link>https://medium.com/feedzaitech/biy-preparing-a-dataset-and-benchmarking-ai-models-for-scatterplot-related-tasks-11cbef120cd1?source=rss-3f58d340dd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/11cbef120cd1</guid>
            <category><![CDATA[outlier-detection]]></category>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[large-language-models]]></category>
            <dc:creator><![CDATA[João Palmeiro]]></dc:creator>
            <pubDate>Mon, 19 Jan 2026 14:52:53 GMT</pubDate>
            <atom:updated>2026-01-19T14:52:53.819Z</atom:updated>
            <content:encoded><![CDATA[<h3>Benchmark It Yourself (BIY): Preparing a Dataset and Benchmarking AI Models for Scatterplot-Related Tasks</h3><figure><img alt="A simplified screenshot of an Open WebUI chat with GPT-4.1. The user uploads a scatterplot showing three distinct clusters and asks: “How many clusters are there in the scatterplot? Answer with a number in curly brackets, e.g., {4}.”. The AI responds “{3}”. The user input field shows the next prompt: “How many outliers are there in the scatterplot? Answer with a number in curly brackets, e.g., {3}.”." src="https://cdn-images-1.medium.com/max/1024/1*38-JuFbVd-gW3MKpwh2JxQ.png" /></figure><p>When we need to visualize and interact with millions, or even just thousands, of individual points while analyzing data, we typically resort to rendering them in the browser using a <a href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Client-side_APIs/Drawing_graphics">canvas</a>. The other common approach for the web, SVG, doesn’t scale when the number of individual elements increases to such quantities. However, while solving one problem, canvas charts introduce a new challenge: <a href="https://www.w3.org/WAI/fundamentals/accessibility-intro/"><strong>accessibility</strong></a>.</p><p>Although SVG charts are not accessible by default, they can be by design. Each part of an SVG chart has a corresponding element on the web page, allowing for a programmable, accessible experience for <a href="https://developer.mozilla.org/en-US/docs/Glossary/Screen_reader">screen reader</a> users. We can simply think of SVG as HTML. On the other hand, a canvas chart is just like a PNG image. If a screen reader user tries to learn more about a canvas chart, unless the developer has prepared a detailed description of it, they will just hear the word “image”. There’s no way to get an idea of what one of these charts represents, let alone extract any insights.</p><p>For static charts, the solution can be as simple as preparing a description and integrating it into the rendered chart. However, for platforms leveraging dynamic, large datasets, automatically generating these descriptions is not a simple task, especially for charts like scatterplots where data distributions can assume countless forms.</p><p>At Feedzai, we started exploring ways to generate <strong>data distribution-aware descriptions for scatterplots</strong> from their respective images using recent multimodal AI models. When the raw data is not available, or the datasets are composed of several thousand or million instances, relying on chart images and these models becomes tempting. This combination has the potential to generate such descriptions and serve them alongside their respective charts, significantly improving the accessibility of canvas charts.</p><p>That said, we focused on two main directions: using AI models to directly generate the descriptions, and using AI models to extract structured data (imagine a list of clusters and their respective center coordinates, for example) that will populate a predefined description template. The initial results, however, were mixed, and it wasn’t clear if we were on the right track to ensure adequate descriptions.</p><p>So, before moving on to further testing, we carefully reviewed the literature. Although benchmarks and other interesting findings are <em>scattered</em> all over the place, they <strong>rarely cover scatterplots</strong> and their <a href="https://alper.datav.is/publications/scatterplots/">related tasks</a>. We therefore changed the <em>plot</em> and designed a dataset + benchmark to expand the general understanding of AI models when applied to charts, specifically scatterplots. We focused on evaluating the baseline performance of these models in identifying clusters and outliers at scale — both, if present, should be described properly.</p><p>The work culminated in the <a href="https://research.feedzai.com/publication/benchmark-it-yourself-biy-preparing-a-dataset-and-benchmarking-ai-models-for-scatterplot-related-tasks/">“Benchmark It Yourself (BIY): Preparing a Dataset and Benchmarking AI Models for Scatterplot-Related Tasks” paper</a>, presented at the <a href="https://visxgenai.github.io/">GenAI, Agents, and the Future of VIS workshop</a> during <a href="https://ieeevis.org/year/2025/welcome">IEEE VIS 2025</a>. This blog post covers the main results and conclusions after running the benchmark in question.</p><h3>Dataset and Benchmark</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dM8xis0_TOZJgC5WvkduVg.png" /><figcaption>Examples for each of the data generators, ordered from top-left to bottom-right: Gaussian blobs with and without background noise, Gaussian blobs with outliers, random patterns (no clusters and outliers), relationships (no clusters and outliers), and geometric shape blobs.</figcaption></figure><p>The <strong>dataset</strong> consists of 18,921 synthetic scatterplot images created from 6 data generators (371 different data samples), 17 chart designs, and 3 image sizes. The number of clusters varies between 0 and 6, while the contamination level, when there are outliers, varies between 0.001 and 0.01. We chose to inject a relatively small number of outliers, keeping them well-distanced from the clusters to evaluate the detection of points that are clearly anomalous and relevant to report. In the end, each scatterplot was automatically annotated for clusters and outliers after converting the respective bounding box and point coordinates to screen coordinates (pixels).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HeeUqumHB6BGqM-m6VZxsw.png" /><figcaption>The 17 chart designs for one of the plotted data samples, based on the default Vega-Lite styling. The chart designs are, ordered from top-left to bottom-right: Y-axis only, double-sized points, square points, randomly shaped points, randomly colored points, points only, half-sized points, points at half the default opacity, points at full opacity, default (light theme), dark theme, colored clusters, 21:9 aspect ratio, 16:9 aspect ratio, 9:16 aspect ratio, 4:3 aspect ratio, and 3:4 aspect ratio.</figcaption></figure><p>The <strong>benchmark</strong> was run on a stratified sample of 1,725 scatterplots and for 5 tasks, each defined by a prompt composed of an instruction and a response format:</p><ul><li><strong>Cluster counting</strong> for the number of clusters.</li><li><strong>Cluster detection</strong> for the bounding boxes of each cluster.</li><li><strong>Cluster identification</strong> for the point coordinates of each cluster center.</li><li><strong>Outlier counting </strong>for the number of outliers.</li><li><strong>Outlier identification</strong> for the point coordinates of each outlier.</li></ul><p>In addition to the different tasks, 10 proprietary models from Google and OpenAI were evaluated, along with 3 different prompting strategies: zero-shot, one-shot (prompt + 1 example), and few-shot (prompt + 6 examples).</p><p>For the counting tasks, two performance metrics were computed: Accuracy and Mean Absolute Error (MAE). For the remaining tasks, Precision and Recall were considered with specific thresholds: an Intersection over Union (IoU) of 0.75 for bounding boxes and a Euclidean distance of 10px for point coordinates.</p><h3>Results</h3><p>The overall results for each task are summarized in the charts below. Each is accompanied by its main highlight. Feel free to explore each chart or jump straight to the next section for the key takeaways.</p><figure><img alt="This is a grouped vertical bar chart. Its title is “performance for the cluster counting task”. The y-axis legend is “Accuracy”. The x-axis legend is “model”. The chart is made up of 10 groups of bars: GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, GPT-4o, GPT-4o mini, o3, o4-mini, Flash, Flash-Lite, Flash-Lite (Thinking). Each group contains three bars: zero-shot prompt, one-shot, few-shot." src="https://cdn-images-1.medium.com/max/1024/1*XJwOLE-lnamtJiDNeiwbHw.png" /><figcaption>Cluster counting results (Accuracy). Few-shot prompting is particularly promising for several models from both providers (over 75% Accuracy). The full alternative text for each chart is available in the <a href="https://github.com/feedzai/biy-paper/tree/main/benchmark/results/all">GitHub repository for this paper</a>.</figcaption></figure><figure><img alt="This is a grouped vertical bar chart. Its title is “performance for the cluster counting task”. The y-axis legend is “MAE”. The x-axis legend is “model”. The chart is made up of 10 groups of bars: GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, GPT-4o, GPT-4o mini, o3, o4-mini, Flash, Flash-Lite, Flash-Lite (Thinking). Each group contains three bars: zero-shot prompt, one-shot, few-shot." src="https://cdn-images-1.medium.com/max/1024/1*NiA4Z9QQFnSHIkSz7C_4dQ.png" /><figcaption>Cluster counting results (MAE). MAE is generally low (a lower MAE is better). The highest value is below 2 for Gemini 2.5 Flash-Lite (Thinking).</figcaption></figure><figure><img alt="This is a grouped vertical bar chart. Its title is “performance for the outlier counting task”. The y-axis legend is “Accuracy”. The x-axis legend is “model”. The chart is made up of 10 groups of bars: GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, GPT-4o, GPT-4o mini, o3, o4-mini, Flash, Flash-Lite, Flash-Lite (Thinking). Each group contains three bars: zero-shot prompt, one-shot, few-shot." src="https://cdn-images-1.medium.com/max/1024/1*FpfELA0XGUUkenvY9Xngqg.png" /><figcaption>Outlier counting results (Accuracy). Gemini 2.5 Flash excels at the outlier counting task when one-shot (~87%) and few-shot (~90%) prompted.</figcaption></figure><figure><img alt="This is a grouped vertical bar chart. Its title is “performance for the outlier counting task”. The y-axis legend is “MAE”. The x-axis legend is “model”. The chart is made up of 10 groups of bars: GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, GPT-4o, GPT-4o mini, o3, o4-mini, Flash, Flash-Lite, Flash-Lite (Thinking). Each group contains three bars: zero-shot prompt, one-shot, few-shot." src="https://cdn-images-1.medium.com/max/1024/1*7jIDO-x2DjfhymmskvefaA.png" /><figcaption>Outlier counting results (MAE). MAE is higher for outliers in general. It is particularly high for two OpenAI reasoning models (o3 and o4-mini).</figcaption></figure><figure><img alt="This is a grouped vertical bar chart. Its title is “performance for the cluster detection task”. The y-axis legend is “Recall @ IoU75”. The x-axis legend is “model”. The chart is made up of 10 groups of bars: GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, GPT-4o, GPT-4o mini, o3, o4-mini, Flash, Flash-Lite, Flash-Lite (Thinking). Each group contains three bars: zero-shot prompt, one-shot, few-shot." src="https://cdn-images-1.medium.com/max/1024/1*M8VjQqGPBeNDGmzxfMh_7Q.png" /><figcaption>Cluster detection results (Recall @ IoU75). The performance is very poor. None surpass 25% Recall. The results are similar for Precision.</figcaption></figure><figure><img alt="This is a grouped vertical bar chart. Its title is “performance for the cluster identification task”. The y-axis legend is “Recall @ 10px”. The x-axis legend is “model”. The chart is made up of 10 groups of bars: GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, GPT-4o, GPT-4o mini, o3, o4-mini, Flash, Flash-Lite, Flash-Lite (Thinking). Each group contains three bars: zero-shot prompt, one-shot, few-shot." src="https://cdn-images-1.medium.com/max/1024/1*eLKhpjOSDV042bcjc8Aifw.png" /><figcaption>Cluster identification results (Recall @ 10px). None surpass 25% Recall in the cluster identification task as well. The results are similar for Precision.</figcaption></figure><figure><img alt="This is a grouped vertical bar chart. Its title is “performance for the outlier identification task”. The y-axis legend is “Recall @ 10px”. The x-axis legend is “model”. The chart is made up of 10 groups of bars: GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, GPT-4o, GPT-4o mini, o3, o4-mini, Flash, Flash-Lite, Flash-Lite (Thinking). Each group contains three bars: zero-shot prompt, one-shot, few-shot." src="https://cdn-images-1.medium.com/max/1024/1*KBCajs-OuIfjhu2YXw64lw.png" /><figcaption>Outlier identification results (Recall @ 10px). Recall is also low, although Gemini 2.5 Flash, when few-shot prompted, seems promising (~65%). The results are similar for Precision.</figcaption></figure><h3>Takeaways</h3><p>Based on the results, the main considerations when combining scatterplot images and AI models are as follows:</p><ol><li><strong>Give priority to few-shot prompting.</strong> This prompting strategy consistently outperformed zero-shot prompting across all models and tasks (top models achieved over 90% Accuracy in counting tasks). It is also useful for handling zero-answer scatterplots.</li><li><strong>Avoid localization tasks.</strong> OpenAI and low-cost Google models prompted with strategies similar to those evaluated are unreliable for localization tasks (e.g., detecting clusters) involving scatterplots.</li><li><strong>Invest in other components first, not chart design </strong>(<a href="https://research.feedzai.com/oshuzuxa/2025/10/VIS_x_GenAI__Benchmark_Paper__camera_ready_version_accessible.pdf">page 4</a> for more details). Chart design is fundamental for humans, but it’s a secondary factor when fed into AI models. Nevertheless, it can be beneficial to avoid chart designs with wide aspect ratios (16:9 and 21:9) or seemingly random colors.</li></ol><h3>Further Reading</h3><p>Since this blog post doesn’t cover all the relevant aspects of the dataset and benchmark, feel free to read the <a href="https://research.feedzai.com/publication/benchmark-it-yourself-biy-preparing-a-dataset-and-benchmarking-ai-models-for-scatterplot-related-tasks/">paper</a>, check out the associated <a href="https://github.com/feedzai/biy-paper">GitHub repository</a>, or watch a <a href="https://youtu.be/TZuE47vc3VY?si=JZ16rmMHI7NBjoaj">short presentation</a> about it.</p><p>If you have any questions or feedback, let us know in the comments section.</p><p><em>Diogo Duarte, Pedro Bizarro, Rita Costa, and Sanjay Salomon: thank you so much for your thoughtful feedback that helped me shape this blog post!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6CGwhw0_h84Z39KLCwUDXg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11cbef120cd1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/feedzaitech/biy-preparing-a-dataset-and-benchmarking-ai-models-for-scatterplot-related-tasks-11cbef120cd1">BIY: Preparing a Dataset and Benchmarking AI Models for Scatterplot-Related Tasks</a> was originally published in <a href="https://medium.com/feedzaitech">Feedzai Techblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Here and Now: Reusing Code at Feedzai with JupyterLab Snippets]]></title>
            <link>https://medium.com/feedzaitech/here-and-now-reusing-code-at-feedzai-with-jupyterlab-snippets-ff3b8d880e50?source=rss-3f58d340dd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff3b8d880e50</guid>
            <category><![CDATA[jupyterlab]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[jupyter]]></category>
            <category><![CDATA[snippet]]></category>
            <dc:creator><![CDATA[João Palmeiro]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 13:11:26 GMT</pubDate>
            <atom:updated>2025-03-17T13:11:26.518Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Illustration of a person interacting with a digital document interface. They appear to be in a workspace environment with cabinets containing folders, a bulletin board, and a minimalist design aesthetic." src="https://cdn-images-1.medium.com/max/1024/1*lMreoxxstMmg1oz80qf-fg.png" /></figure><p>Data scientists use different Jupyter notebooks every day — ranging from disposable ones for quick tasks to those shareable with clients. Over time, more and more notebooks accumulate, making it increasingly difficult to reuse them in whole or in part. To mitigate this problem and make the most relevant pieces of code quickly accessible to every data scientist, we developed <strong>JupyterLab Snippets</strong> at Feedzai — our take on leveraging code snippets directly on JupyterLab.</p><p><a href="https://jupyterlab.readthedocs.io/en/latest/">JupyterLab</a> is a computational notebook platform that enables us to carry on data science work (and beyond) via notebooks. These notebooks, where code, text, and images come together, allow us to complete all kinds of tasks, keeping each input close to each output. At Feedzai, data scientists have access to different JupyterLab environments packed with custom notebooks and Python packages. Here they go from analyzing data to training models, from preparing reports to debugging the system — a <a href="https://en.wiktionary.org/wiki/jack_of_all_trades">“lab of all trades”</a>, we could say.</p><p>Given the importance of JupyterLab and notebooks in the daily work of our data scientists, we started a research project that culminated in JupyterLab Snippets. First, we collected statistics from internal notebook repositories across teams and conducted user interviews with junior and senior data scientists. We needed to know more about how data scientists actually use JupyterLab and notebooks, and what their ideas are for a better platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FopBuyq1jLGH3qEae2wFQ.png" /><figcaption>A sneak peek of JupyterLab Snippets. From the very start, every data scientist can import snippets immediately or start their collection by creating one from scratch.</figcaption></figure><p>After compiling the insights, several aspects became clear:</p><ul><li>JupyterLab and notebooks are heavily used for all sorts of data science and ad-hoc tasks (typically one per notebook). There is no single type of task (e.g., exploratory data analysis) that is more commonly addressed with notebooks than others.</li><li>While file structures may look similar at first glance (each environment has at least a model training notebook, for example), data scientists have different and personal workflows for coding notebooks.</li><li>Duplicating past notebooks available in the environment or getting them from repositories is a very common practice.</li><li>Notebooks composed of code snippets is also an identified practice. These notebooks are not intended to be run, and contain code and text for future reference (imagine a notepad in notebook format). This case and the previous one imply removal of unnecessary parts and parameterization.</li><li>Data scientists regularly communicate within teams and individually. Sharing notebooks/snippets is a common practice.</li><li>No significant issues were identified with the JupyterLab/notebook interface.</li></ul><p>It is true that data scientists have their own ways of finding whatever they need for their next notebook, and AI coding assistants are proliferating. Even so, would it be beneficial to improve the experience of reusing code in JupyterLab? After analyzing all the insights, we believe so. We believe in an interface that allows every data scientist to easily manage and use “their snippets” now and in one year, while also facilitating their sharing with other data scientists. JupyterLab Snippets aims to improve the developer experience, focusing on productivity and satisfaction, while having a low maintenance cost. Here is JupyterLab Snippets in its essence.</p><h3>Introducing JupyterLab Snippets</h3><p>JupyterLab Snippets is a <a href="https://jupyterlab.readthedocs.io/en/stable/user/extensions.html">JupyterLab extension</a> for data scientists to create, manage, and use code snippets directly on JupyterLab, facilitating code reuse in their notebooks. To be more precise, the interface is a <a href="https://github.com/jupyterlab/extension-template">JupyterLab extension</a> and the backend, for managing the snippet data, is a <a href="https://jupyter-server.readthedocs.io/en/latest/developers/extensions.html">Jupyter Server one</a>. Both communicate via a REST API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPB6ElAqNaI5MjzjdR5FOw.png" /><figcaption>Two of the three main parts: Snippet Sidebar and Snippet Editor. The snippets are adapted from the <a href="https://altair-viz.github.io/gallery/index.html">Vega-Altair documentation examples</a>.</figcaption></figure><p>The interface, a part of JupyterLab like notebooks and the like, is divided into three main components:</p><ul><li><strong>Snippets Sidebar</strong>: The <em>central hub</em> for JupyterLab Snippets, available as a new tab in the <a href="https://jupyterlab.readthedocs.io/en/latest/user/interface.html#left-and-right-sidebar">right sidebar</a> of JupyterLab. It allows the data scientist to manage and utilize the code snippets. Each snippet is available on a <strong>Snippet Card</strong>.</li><li><strong>Snippet Editor</strong>: The form-like interface for creating new snippets and editing existing ones. When opened, it is available as a tab in the <a href="https://jupyterlab.readthedocs.io/en/latest/user/interface.html#main-work-area">main work area</a> of JupyterLab.</li><li><strong>Shortcuts</strong>: Options for creating snippets from notebook cells. These options are available from the <a href="https://jupyterlab.readthedocs.io/en/latest/user/interface.html#context-menus">context menu</a> after right-clicking on a cell, and the option to start a snippet from a cell is also available from the <a href="https://jupyterlab.readthedocs.io/en/latest/user/interface_customization.html#toolbars">cell toolbar</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BE7AqFoTnRomAjGHCKutSg.png" /><figcaption>Snippet Cards and Shortcuts. Shortcuts consist of new cell context menu options and a new option in the cell toolbar.</figcaption></figure><p>In the <strong>Snippets Sidebar</strong>, in addition to the <em>Personal</em> collection, data scientists will find a set of pre-made snippets: the <em>Feedzai</em> collection. They can switch between both (or view them all at once) by selecting the desired collection in the toolbar just above the list of available snippets. The <em>Feedzai</em> collection is a set of snippets for common actions performed in notebooks, prepared with the help of our data scientists. This collection is specially designed for newcomers who can take advantage of JupyterLab Snippets from day one. Additionally, it is available in a dedicated repository so that anyone can easily contribute to this collection and enrich it for everyone.</p><p>From the <strong>Snippets Sidebar</strong>, data scientists can export all of their snippets in JSON format (each snippet is exportable individually as well). This file makes it easy to share snippets among data scientists, as well as maintain them in repositories for reference. Each data scientist can then import one of these files into their environment, from the dropdown menu shown in the first screenshot, and have access to new snippets.</p><h4>Usage</h4><p>JupyterLab Snippets is designed to be a flexible tool that data scientists can integrate into their workflows in different ways and use as much or as little as they need. There is more than one way to create snippets, and each data scientist may have as few as five or as many as 50 snippets (or even more) at their disposal. Let’s look at a possible simple workflow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oU5xavwk2rShT0-JUN_pIQ.gif" /><figcaption>Creating a new snippet from scratch. The notebook is adapted from the <a href="https://github.com/altair-viz/altair_notebooks">Jupyter Notebooks for Altair repo</a>.</figcaption></figure><ol><li>After launching JupyterLab, the data scientist starts by opening the notebook they are working on.</li><li>Instead of copying and pasting code from a given source to the notebook directly, they open the Snippets Sidebar on the right side of JupyterLab and then the Snippet Editor to create a new snippet.</li><li>Since the data scientist can imagine reusing this piece of code in the future, they create a new snippet with it, including a name, a brief description, and two tags that describe it appropriately.</li><li>Now they insert the new snippet into the notebook and continue working from there.</li><li>Finishing the current notebook, the data scientist clears all the output. Then, when they review the notebook and check that everything is okay, they notice a cell that would also make a useful snippet for the future.</li><li>Since not all the cell content is relevant for a reusable snippet, the data scientist selects only what they want and starts a new snippet from there via the cell context menu.</li><li>Similar to the first snippet, they assign a name and a tag.</li><li>After a while, in a new notebook, the data scientist opens the Snippets Sidebar and quickly inserts both previously created snippets, as they will be useful in this new notebook as well.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R-1f43tP-STIr-O3oSD9nA.gif" /><figcaption>Inserting snippets into a notebook.</figcaption></figure><h3>What’s Next</h3><p>JupyterLab Snippets is now available for data scientists to use across Feedzai. Our current focus is on helping data scientists incorporate JupyterLab Snippets into their daily workflow, addressing any issues that arise, and collecting feedback for future improvements.</p><p>If you have any questions or feedback, let us know in the comments section.</p><p><em>Beatriz Feliciano, Diogo Duarte, Ferran Pla Fernández, Iker Perez Lopez, João Bernardo Narciso, Rita Costa, and Sanjay Salomon: thank you so much for your thoughtful feedback that helped me shape this blog post!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff3b8d880e50" width="1" height="1" alt=""><hr><p><a href="https://medium.com/feedzaitech/here-and-now-reusing-code-at-feedzai-with-jupyterlab-snippets-ff3b8d880e50">Here and Now: Reusing Code at Feedzai with JupyterLab Snippets</a> was originally published in <a href="https://medium.com/feedzaitech">Feedzai Techblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing Data Drift: How We Designed Visualizations to Support Feature Investigation]]></title>
            <link>https://medium.com/feedzaitech/analyzing-data-drift-how-we-designed-visualizations-to-support-feature-investigation-e408d4de7e9f?source=rss-3f58d340dd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e408d4de7e9f</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[João Palmeiro]]></dc:creator>
            <pubDate>Thu, 11 Aug 2022 15:26:53 GMT</pubDate>
            <atom:updated>2022-08-11T15:26:53.657Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8GUd63xiRSK3bFCxCK4IEA.png" /></figure><p>The <a href="https://huyenchip.com/2022/02/07/data-distribution-shifts-and-monitoring.html#train-serving-skew">world is not stationary</a> — things change. Thus, it is unlikely that our production data will follow the same distribution as the training one for our Machine Learning model.</p><p><a href="https://medium.com/feedzaitech/feature-investigation-automatically-detect-drift-in-your-data-over-time-b502074a7358">In the first blog post</a>, we introduced Feature Investigation, a system for automatically detecting and analyzing data drifts, as well as how the algorithm works. Now, it is time to learn about the visualizations developed to help data scientists analyze the outputs and identify patterns and major changes in feature distributions.</p><h3>Table of Contents</h3><ol><li><a href="#3926">Designing the Visualizations</a></li><li><a href="#1a0e">Introducing the Visualizations</a></li><li><a href="#e55f">Implementation and Tech Stack</a></li><li><a href="#e4ce">Future Work</a></li></ol><h3>Designing the Visualizations</h3><p>First things first. In the beginning, we knew the problem that the Feature Investigation system tackles and its relevance. However, we still had a lot of questions about the current practices and needs of data scientists, as well as other solutions out there. In other words, we didn’t know what interface to design and how to integrate it into users’ workflow.</p><p>Before we go through the visualizations, let’s recap our design process. We knew the <em>what</em>, <em>why</em>, and <em>who</em>, but not the <em>how</em>, <em>when</em>, and <em>where</em>. Of course, we started by interviewing data scientists.</p><h4>User Interviews</h4><p>We conducted four semi-structured interviews with data scientists working on different projects/clients at Feedzai. Each interview lasted between 30 to 45 minutes. Together we identified current data monitoring and distribution analysis practices, how these practices are integrating into their workflows, triggers for these processes, and pain points.</p><p>From these interviews, we gained some interesting and generalizable insights:</p><ul><li>Data scientists compare feature distributions considering the <a href="https://en.wikipedia.org/wiki/Deployment_environment">production environment</a>’s most recent or relevant time window with the historical/training ones. Sometimes they also compare distributions over time (and not just two snapshots).</li><li>Data scientists leverage charts and summary statistics via single-use <a href="https://jupyter.org/">Jupyter</a> notebooks or spreadsheets.</li><li>Data scientists prioritize the most important features for predicting the target variable (Feature Importance results), raw features, and features obtained from external data enrichers. Two examples of problems are null values coming from the data enrichers and missing categorical values for one of the features.</li><li>Data scientists have two main triggers to investigate features: Model/System performance changes and deployments. An example of detecting changes is checking the distribution of model scores.</li><li>If the value of the performance metric is different from the expected one, data scientists start by readjusting the threshold to maintain the desired performance. After that, they contact the relevant data provider (data enricher or client). Before this step, data scientists may have to conduct a manual feature analysis to identify potential causes. After solving the problem, they reset the first action (or act as needed).</li></ul><p>Using all the information collected so far (including internal documentation), we moved on to the next part: defining the user flow and requirements.</p><h4>User Flow</h4><p>The user flow is a diagrammatic representation of the typical data scientist workflow that we aim to support with Feature Investigation and its visualizations. Each box corresponds to a step or task. They are connected, forming the expected path and branching off whenever there is more than one suitable option. This technique is interesting not only to help us design a solution but also to validate mockups. By following the mockups based on the user flow, we can confirm whether they support all possible paths defined earlier or not.</p><p>For Feature Investigation, we identified five major parts:</p><ol><li><strong>Data preparation</strong>: Get the data, run Feature Investigation, and select the outputs to analyze.</li><li><strong>Overview</strong>: Do the first screening and identify problematic features.</li><li><strong>Profiling</strong>: Freely explore features/periods and select features for further analysis.</li><li><strong>Knowledge management</strong>: Document insights and save assets.</li><li><strong>Root cause analysis</strong>: Characterize the previously identified features and the respective main changes.</li></ol><p>Breaking down each of the parts, the complete user flow looks like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.figma.com%2Fembed%3Fembed_host%3Doembed%26url%3Dhttps%3A%2F%2Fwww.figma.com%2Ffile%2F8BIuCxzjMTGgpzYUpOP974%2FUser-Flow%3Fnode-id%3D2%253A11&amp;display_name=Figma&amp;url=https%3A%2F%2Fwww.figma.com%2Ffile%2F8BIuCxzjMTGgpzYUpOP974%2FUser-Flow%3Fnode-id%3D2%253A11&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=figma" width="800" height="450" frameborder="0" scrolling="no"><a href="https://medium.com/media/89111f472215229fde831ecc2f06d1e2/href">https://medium.com/media/89111f472215229fde831ecc2f06d1e2/href</a></iframe><p>In other words (or images), the typical workflow boils down to the following steps:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LWK7twnWJBiGVTJ04fXa9g.png" /><figcaption>Simplified user flow.</figcaption></figure><p>After the user flow, we compiled a set of requirements that established the objectives to be accomplished with the visualizations.</p><h4>User Requirements</h4><p>At the end of the day, data scientists need to quickly generate hypotheses and decide the following steps to ensure model performance is not affected by data drifts and data quality issues. In this way, we have established five user requirements:</p><ul><li>Identify and compare data drift patterns.</li><li>Identify relevant features and periods.</li><li>Compare related features.</li><li>Identify the main changing values in the distributions of the features.</li><li>Integrate with the current workflow of data scientists.</li></ul><p>After researching and defining the problem, we started to mock possible solutions and shape the visualizations for Feature Investigation. We also reviewed the literature — check out <a href="https://diglib.eg.org/handle/10.2312/evs20221097">our short paper</a> for more information on related work.</p><h4>Mockups</h4><p>For this stage, we used <a href="https://www.figma.com/">Figma</a> as our collaborative UI design tool. At this point, we had already decided to design two complementary visualizations and approached them in the expected order of use. In other words, after we were satisfied with the design of the first visualization, we moved on to the second one. We will explore each in the “Introducing the Visualizations” section. For now, let’s focus on the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-RgQiwS9zVjYPiQ3U4dGHg.png" /><figcaption>Paper wireframes for one of the visualizations (Histogram).</figcaption></figure><p>We were motivated to include this stage in our project for two reasons:</p><ul><li>To have a moment focused on designing a concrete solution that is as complete as possible, iterating quickly through the various versions.</li><li>To have a clear baseline to plan the development and a common goal for the development itself. This reason was particularly important because we were two people implementing the visualizations, and there were multiple stakeholders.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wa0m5ZByBRhn_JlKAQFsNw.png" /><figcaption>Final mockup (high-fidelity wireframe) for one of the visualizations (Heatmap).</figcaption></figure><p>This way, we prepared everything from paper wireframes with our first sketches to mockups that helped us during development. In addition to mockups for each of the visualizations in their different main states, we also prepared several variations for some parts of them.</p><p>A tool like Figma is handy for creating multiple versions of a Y-axis, for example, so that we can compare the various ideas and decide which one to use. After experimenting with various combinations of font families, font sizes, text alignments, tick styles, and other properties, we implemented a version similar to the Y-axis in the previous image. We have left-aligned the text (instead of <a href="https://altair-viz.github.io/gallery/index.html">right-aligning as usual</a>) to make it easier to compare feature names based on their prefixes.</p><p>After we finished the mockup stage and organized the final mockups (which may change during development), we started planning the implementation of the visualizations for Feature Investigation.</p><h4>Development Planning</h4><p>To plan our effort, we set milestones and more granular tasks. We added these tasks to GitLab as issues in order to manage the work from the Feature Investigation repository. As for the milestones, there were four between October 2021 and January 2022:</p><ol><li>MVP Development.</li><li>User Testing.</li><li>Development.</li><li>User Acceptance Testing.</li></ol><p>On November 18th and 19th, we conducted two user tests to validate our core features and get feedback (User Testing). Up until this point, we have focused on implementing the most important features (including styling) and having a first working version of both charts (MVP Development).</p><p>After organizing the collected feedback and checking our backlog, we got back to development (Development). The focus was on finishing and fine-tuning each visualization to get to the final module version for Feature Investigation.</p><p>In January 2022, before the release near the end of the month, we conducted User Acceptance Tests with two data scientists who also integrated the Feature Investigation project (User Acceptance Testing). These tests consist of executing a set of test cases/tasks previously defined from a script to verify that each piece is working as expected. Beforehand, we prepared an environment similar to what a data scientist uses with a real-world dataset. In our case, we used the dataset we leveraged during development to see the output as representative as possible. Both tests went as expected, and we found less than a handful of minor issues (we improved a part before we released Feature Investigation and the rest after that).</p><p>As a final note, in early January, we added some unit and component tests to our codebase. We also improved one of the visualizations (Histogram) in terms of keyboard navigation and <a href="https://developer.mozilla.org/en-US/docs/Learn/Accessibility/WAI-ARIA_basics">ARIA</a> labeling to make it more accessible. Leaving these additions for late development is something we want to improve on our future projects.</p><p>Fast forward to the present, let’s explore the visualizations and how they can help with data drift analysis!</p><h3>Introducing the Visualizations</h3><p>The visualization module comprises two charts: the <strong>Overview</strong> and the <strong>Histogram</strong>. We designed these charts to be primarily used in sequence. After the data scientist gets a set of drifting features from the Overview, they will try to figure out the issues for each one from the Histogram: Are there new values? Or null values? Has the distribution been skewed?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vWqXI_c1ns6WrkBF7J2LwA.png" /><figcaption>The typical use of the two visualizations in sequence. Read on for more details on each part.</figcaption></figure><p>Let’s move on and get to know each visualization in detail and some of our design choices. To do so, imagine the following situation: Two months have passed since we deployed our first model. Now, we want to understand how the production data distribution is behaving. We <a href="https://huyenchip.com/2022/02/07/data-distribution-shifts-and-monitoring.html#natural-lables">still do not have new labels</a> to evaluate the model’s performance, but we can see if any features are drifting. <a href="https://medium.com/feedzaitech/feature-investigation-automatically-detect-drift-in-your-data-over-time-b502074a7358">Our Reference distribution corresponds to the training dataset, while the production data to the Target distribution.</a> We don’t know what to expect, as this is the first time we have deployed a model and are conducting this type of analysis. So, let’s start by leveraging the Overview and understanding the features’ behaviors in general.</p><h4>Overview</h4><p>The Overview is a heatmap combined with a toolbar and a context menu. These control elements adjust the layout and filter the data to help the data scientist focus on the most relevant parts. This interactivity is particularly useful in this visualization because the heatmap can be huge and overwhelming. There are cases with more than 200 (and even 500!) features and a significant time window for analysis.</p><p>Nevertheless, we can have a first look at all the features by checking the heatmap and scrolling up and down. The Y-axis corresponds to features and the X-axis to time (e.g., days). Each row allows us to analyze the behavior of a feature over time and extract possible patterns. When hovering in each cell, there is a tooltip with information about the associated values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*goqviAB_n5gHdoq_ottYIw.png" /><figcaption>The Overview visualization. At the top, we have the toolbar, followed by the legend, and finally, the heatmap.</figcaption></figure><h4>Toolbar</h4><p>Since we don’t have any features in mind to check, let’s rearrange the layout to highlight features that are worthy of our attention. We have three possibilities at the top, more precisely on the toolbar:</p><ol><li><strong>Features</strong> <strong>widget</strong>: A selection dropdown to show and hide specific features in the visualization. It includes a search prompt within the menu, as well as two helper buttons to select all or none of the features. By default, all features are selected.</li><li><strong>Feature Sorting</strong> <strong>widget</strong>: A selection dropdown to sort the features (Y-axis) according to certain criteria. By default, features keep their original input order.</li><li><strong>Feature Grouping</strong> <strong>widget</strong>: A selection dropdown to cluster features according to an attribute vertically. Currently, it supports the Raw / Engineered option to create a nested layout where the raw features are separate from the ones prepared based on them. In practice, we ended up with two heatmaps.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWtQQV3N4G96g-KLIcsq3Q.png" /><figcaption>The Features widget opened to select features.</figcaption></figure><p>Let’s focus on the second widget. In this widget, we have four criteria to sort the features as if we were going to sort a table:</p><ul><li><strong>Original order</strong>: The default option. The features are sorted according to the input data.</li><li><strong>Alphabetical order</strong>: The features are sorted alphabetically in a case-insensitive way.</li><li><strong>Most alarms</strong>: The features are sorted in descending order of alarm count. An alarm corresponds to a feature whose <em>p</em>-value, at a given moment, is less than or equal to a threshold (significance level). In other words, a feature drifts when there is an alarm.</li><li><strong>Least sum of <em>p</em>-values</strong>: The features are sorted in descending order of the total sum of <em>p</em>-values per feature. This option overlaps with the previous one but allows pulling features that, over time, have smaller <em>p</em>-values, even if they are not small enough to be considered alarms. We may want to keep an eye on these features to act proactively.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F4ne6vzFi9DEXOtQ5UGMmw.png" /><figcaption>Sorting the features in the Overview.</figcaption></figure><p>If there are ties, the features keep the same original relative order. By selecting the Least sum of <em>p</em>-values option, we move all (near-)alarming features to the top. We first notice that there are six features (M1-M3) in alarm whose distributions are significantly different from the Reference ones. We represent alarming features with black squares ⬛.</p><h4>Color Scale</h4><p>Before we go further with our analysis, let’s understand how color works in this heatmap. Color is our visual encoding channel for <em>p</em>-values. After the toolbar, we have a legend for the color scale (and the symbol ✱ used to identify raw features on the Y-axis). We have adopted a tripartite color scale. In the rightmost part, we have all <em>p</em>-values equal to or below the threshold. They are clamped and identified by the black color ⬛. On the other hand, in the leftmost part, we have all <em>p</em>-values greater than a new threshold introduced for the visualizations: the analysis threshold. They are also clamped and identified by a light gray tone ⬜. We have a sensible default for this threshold, but the data scientist can adjust it when starting a new Overview. Finally, in the middle, we have a linear scale of <em>p</em>-values that follows a sequential color scheme (<a href="https://github.com/d3/d3-scale-chromatic">YlOrRd</a> 🟨 🟧 🟥).</p><p>At first glance, this choice may seem strange. Before we continue, please take a look at the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sq51wlqWHeW9Ece-v9TSqg.png" /><figcaption>Why a tripartite color scale?</figcaption></figure><p>Do you think your first impression, at least, is the same in both images? In this image, the data is the same, but the heatmap on the left uses a color scale based on the <em>minimum </em>(the threshold) and maximum values, while the heatmap on the right leverages our tripartite color scale. We believe that using the maximum (normalized) <em>p</em>-value in the color scale, that is, the full range of values, can lead to misinterpretations of the state of the features and make it challenging to analyze the respective patterns.</p><p>In this way, the <strong>analysis threshold</strong> acts as the new maximum <em>p</em>-value. The analysis threshold allows us to focus on a shorter, more relevant range of <em>p</em>-values (occupying the same space). It helps us surface actionable patterns when changes between distributions become more noticeable. It doesn’t matter, for example, whether the (normalized) <em>p</em>-value is 15 or 20 since, for the user, the interpretation is the same — it’s the values closest to the threshold (0.01), and their evolution, that matter. In practice, both endpoints work as categories, while the middle works as a continuous linear scale.</p><h4>Investigation View</h4><p>Now we know how to use the heatmap and have an overview. Let’s continue our analysis and drill down to one of the top features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kxq1ppdg7QlmwiHYcSSfkg.png" /><figcaption>Focusing the analysis on a specific feature (probability_log_T…).</figcaption></figure><p>probability_log_T… is an engineered feature, and although it has no alarms, its distribution appears to be very different from the Reference one. To investigate this feature, we left-click on the feature name to open the context menu. From this menu, in addition to copying the feature name, we can access the investigation view. In this view, the heatmap is focused on the selected feature and its related ones.</p><p>There are two types of related features:</p><ul><li><strong>Feature ancestors</strong>: These are the features used to create the feature under investigation. Raw features have no ancestors.</li><li><strong>Feature descendants</strong>: These are the features created from the feature under investigation. Some of them can be created from more than one feature.</li></ul><p>Some features only have one of the types, while others have both types. There are also features unrelated to any other ones (from the engineering point of view). The investigation view helps surface the features’ hierarchy based on the selected feature (and others added later, if any).</p><p>In addition, we have equipped this view with some actions to facilitate the analysis of a subset of features. Right below the feature under investigation, it is possible to add more features to investigate on the Y-axis. The Related features section is then updated with the ones related to the added feature. As long as there is more than one feature under investigation in this view, it is also possible to adjust the subset of visible related features. By default, all features related to at least one of the features under investigation are shown. However, when clicking on COMMON, only the ones related to all features under investigation are considered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4H7N2nC0reTtZm-L-YYqog.png" /><figcaption>By adding another feature to investigate (ratio_card_proxy_…), we can see what related features they have in common. In this case, there is one (TransactionAmt).</figcaption></figure><p>Using this view and its various actions, we can get insights progressively, locking the analysis on an initial feature and its relationships. For example, we can see that the probability_log_T… feature’s pattern is similar to that of the related card_proxy_stdDev… feature, at least for the most recent days (see the first image in this section). To return to the initial state, we need to click on the reset button next to the title of the first heatmap.</p><p>After analyzing some features carefully, we can go even deeper and compare the Reference and Target distributions for one of them. Looking at the Overview again, we can identify a gradually drifting raw feature that deserves our attention: C9.</p><h4>Histogram</h4><p>The Histogram is a bar-based chart to compare distributions of one of our features. If the feature is continuous, this visualization is a histogram. On the other hand, if categorical, it is a bar chart. For simplicity, we call it just Histogram.</p><p>In this visualization, the Reference distribution is encoded with lines ( — ), while the Target distribution is encoded with gray bars. This design choice was motivated by the main task to be supported by the Histogram: compare the same bins between distributions to see if the Target bar is above, below, or similar to the Reference line (intra-bin comparison). Comparing distribution shapes is secondary while looking for concrete changes to generate hypotheses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_tBP6dyZjcAi-ByF-veT-g.png" /><figcaption>There are notable differences between the second and third bins ([0, 1[ and [1, 2[), in addition to some changes in other bins. In the case of this feature, there are no new values (the first and last bins are empty), considering the Reference range, as well as no null values (the NaN bin is empty).</figcaption></figure><h4>Distributions</h4><p>Please note that we don’t use the Histogram to compare the original data distributions but the moving histograms (“What are Moving Histograms?” section, <a href="https://medium.com/feedzaitech/feature-investigation-automatically-detect-drift-in-your-data-over-time-b502074a7358">first blog post</a>). In the case of continuous features, by default, we show bins of equal width (although the intervals of each bin are different) to facilitate intra-bin comparisons. Near the X-axis, we can toggle between this discrete option and the corresponding linear bins, that is, the original varying-width bins from the moving histograms.</p><p>In addition to the feature values, there are also some complementary bins on the X-axis:</p><ul><li>For <strong>continuous features</strong>, the rightmost bin (NaN), separated from the histogram, accounts for the null values. If this percentage is relatively high, there may be a technical problem with the input data, for example. In addition to this bin, the leftmost and rightmost bins of the histogram accommodate values smaller and larger than the limits of the Reference data range. In other words, these bins are used to record values that did not exist in the Reference period.</li><li>For <strong>categorical features</strong>, the rightmost bin (New values) accounts for all new values of a given feature in the Target distribution. In other words, this bin accommodates the new categories that did not exist in the Reference period (and their total percentage).</li></ul><h4>Interactivity</h4><p>Since some features have many bins, we can brush the chart area with the mouse, so we only see a subset of them. When hovering in each bin, there is a tooltip with information about the associated values and differences.</p><p>For the Y-axis, we only consider relative frequencies (percentages). Near this axis are toggle buttons for the scale type: linear (default) or logarithmic scale.</p><p>Similar to the Overview, the Histogram also has a toolbar. Here, we can find a slider and a date picker to select the date for when we want to compare the distributions of a feature. The <em>p</em>-values are also encoded in the slider (via the slider color), approximating the corresponding row in the heatmap.</p><h4>Feature Stability</h4><p>Between the toolbar and the chart, we have a legend. In addition to clarifying which mark corresponds to each distribution, it also summarizes the stability of a feature during the Reference period according to three categories: low, moderate, and high. During the Reference period, changes over time also occur in the feature distributions. So, this metric allows us to consider the changes in our feature distributions over this period based on the divergence values (“​​Build Reference” section, <a href="https://medium.com/feedzaitech/feature-investigation-automatically-detect-drift-in-your-data-over-time-b502074a7358">first blog post</a>).</p><p>In this way, feature stability helps to weigh the changes we see in the Histogram. We can find some noticeable changes, but the <em>p</em>-value is not that low (see the image below for an example). While some features are very stable (high), others are not (low or moderate). Thus, this metric helps us judge bin changes and contextualize the conclusions we can get.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rLO0ix_JcNkMI35KzqzWHg.png" /><figcaption>Although there are visible differences between the Reference and Target distributions (values are concentrating on the W category), these changes are not alarming. The ProductCD feature has low stability. Furthermore, this feature has no new categories in the Target period, as the New values bin is empty.</figcaption></figure><p>Combining the Overview and the Heatmap, we can explore Feature Investigation outputs and gain insights into the current state of our data distributions. This information is essential to mitigating performance degradation. Before we wrap up this blog post, here are a few words about how we implemented these visualizations.</p><h3>Implementation and Tech Stack</h3><p>We designed the visualizations to be used via <a href="https://jupyterlab.readthedocs.io/en/stable/">JupyterLab</a>. Thus, they are easily integrated into notebooks, one of the main tools of data scientists. Due to this requirement, we considered the output size of notebook cells when arranging the layout of both visualizations.</p><p>To have a Python subpackage for Feature Investigation with full flexibility to develop visualizations/small interfaces, we followed an approach based on a Python API, web-based visualizations, and <a href="https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display">IPython’s </a><a href="https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display">display()</a>. The most similar implementations we found are those of <a href="https://arxiv.org/abs/2005.00160">PipelineProfiler</a> and <a href="https://arxiv.org/abs/2205.03963">NOVA</a>.</p><p>Going into more detail, Python is responsible for preparing and serializing data from the Feature Investigation output and the user-facing API. In this way, each visualization function is imported and used like any other in a Python package. On the other hand, we developed the UI using HTML, CSS, JavaScript, and <a href="https://reactjs.org/">React</a> as the framework. To connect both parts, Python is also responsible for preparing an HTML file for each visualization, embedding it in JupyterLab (from IPython’s display()).</p><p>In short, we have adopted a tech stack consisting mainly of:</p><ul><li><a href="https://ipython.org/"><strong>IPython</strong></a> for embedding web-based visualizations in JupyterLab.</li><li><a href="https://pandas.pydata.org/"><strong>pandas</strong></a> as the DataFrame package.</li><li><a href="https://reactjs.org/"><strong>React</strong></a> as the front-end framework.</li><li><a href="https://lodash.com/"><strong>Lodash</strong></a> for its utilities.</li><li><a href="https://mui.com/"><strong>MUI</strong></a> as the UI component library.</li><li><a href="https://d3js.org/"><strong>D3</strong></a> <a href="https://www.smashingmagazine.com/2018/02/react-d3-ecosystem/">for the math</a> needed to create the visualizations, such as the <a href="https://github.com/d3/d3-scale">scales</a> (rendering/DOM is React’s responsibility).</li><li><a href="https://airbnb.io/visx/"><strong>visx</strong></a> as the Data Visualization component library (for axes, for example).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fkbar2FejahBuuK843LDeQ.png" /><figcaption>Our tech stack for the Feature Investigation visualizations.</figcaption></figure><p>We checked out some component libraries and opted for the MUI. It has all the UI components we needed and an icon set. One of these components is the <a href="https://mui.com/material-ui/react-tooltip/">tooltip</a> one, as its implementation allows it to be used together with <a href="https://developer.mozilla.org/en-US/docs/Web/SVG">SVG</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API">Canvas</a> elements. We also chose MUI for its ease of use, documentation, and maturity.</p><p>Finally, the Overview chart area is implemented with Canvas for scalability reasons (typically, there are too many cells to use SVG properly). On the other hand, the Histogram and all guides, such as axes, are SVG (implemented with visx and custom code).</p><h3>Future Work</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4FfnukWNxX74y2pWEJRdZA.png" /><figcaption>Our logo.</figcaption></figure><p>Feature Investigation is a system for automatically detecting and analyzing data drifts. It supports data scientists in mitigating performance degradation that could negatively impact the business and its users. In addition to data drifts, it can help detect internal errors or data quality issues. Thus, we developed two complementary visualizations designed for data scientists to extract insights and define the next steps.</p><p>To validate the “final” visualizations, we met with one of the data scientists who helped us define the requirements. Over 45 minutes and following a think-aloud protocol, we gathered several findings — check out <a href="https://diglib.eg.org/handle/10.2312/evs20221097">our short paper</a> for more details! In fact, this blog post is not about the final version of our work. In the future, we want to:</p><ul><li>Conduct more user testing and interview users after using Feature Investigation in their projects.</li><li>Implement features from our backlog that were not considered for the current version (e.g., improved Y-axis label truncation and screenshotting).</li><li>Improve support for keyboard navigation and screen readers.</li><li>Explore ways to integrate and visualize individual instances.</li><li>Evaluate reimplementing both visualizations as a <a href="https://jupyterlab.readthedocs.io/en/stable/user/extensions.html">JupyterLab extension</a> using <a href="https://ipywidgets.readthedocs.io/en/7.7.0/developer_docs.html#scope-of-ipywidgets">ipywidgets</a> as a framework. One advantage is the synchronization of data between Python and the front-end.</li></ul><p>Finally, if you have any questions or feedback, let us know in the comments section.</p><p><em>Beatriz Feliciano, Francisca Calisto, Hugo Ferreira, Javier Pérez, Ricardo Moreira, Rita Costa, and Sanjay Salomon: thank you so much for your feedback and help on this blog post!</em></p><p><em>Beatriz Malveiro: it was great working with you on this project and reaching such a result — thank you very much!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e408d4de7e9f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/feedzaitech/analyzing-data-drift-how-we-designed-visualizations-to-support-feature-investigation-e408d4de7e9f">Analyzing Data Drift: How We Designed Visualizations to Support Feature Investigation</a> was originally published in <a href="https://medium.com/feedzaitech">Feedzai Techblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Styling Altair Charts with the feedzai-altair-theme]]></title>
            <link>https://medium.com/feedzaitech/styling-altair-charts-with-the-feedzai-altair-theme-f3dcd27b3b68?source=rss-3f58d340dd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3dcd27b3b68</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[charts]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[altair]]></category>
            <dc:creator><![CDATA[João Palmeiro]]></dc:creator>
            <pubDate>Wed, 08 Jun 2022 11:05:59 GMT</pubDate>
            <atom:updated>2022-06-08T11:05:59.907Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Illustration of a person sitting at a computer. On the wall, there are several charts." src="https://cdn-images-1.medium.com/max/1024/1*nRXDtAJOIpPWb5tdT7-M5Q.png" /></figure><p>If you’ve ever used <a href="https://altair-viz.github.io/index.html">Altair</a> for Data Visualization, you’ll notice that it provides suitable default styles, removing the burden of adapting them each time you create a chart. However, what if you want to use a coherent set of styles across multiple charts other than the default ones?</p><p>At Feedzai, we’ve created an <a href="https://altair-viz.github.io/user_guide/configuration.html#altair-themes">Altair theme</a> based on our internal Data Visualization guidelines — a document with information about different types of charts, recommendations (accessibility included), a style guide for standardized charts, and design tokens (such as font sizes and colors). The Altair theme was originally built to better support data scientists creating charts mainly for communication purposes. Now we are sharing it as an open-source Python package — the <a href="https://github.com/feedzai/feedzai-altair-theme">feedzai-altair-theme package</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W65bUG1XQqOtOBg_V5eVog.png" /><figcaption>The feedzai-altair-theme package logo (right) was created based on the Altair logo (left).</figcaption></figure><h3>Altair and Altair Themes</h3><p><a href="https://altair-viz.github.io/index.html">Altair</a> is a Data Visualization package that wraps <a href="https://vega.github.io/vega-lite/">Vega-Lite</a> for interactive charting in Python. With that in mind, Altair themes are a good way to style multiple charts consistently.</p><p>To leverage Altair themes, we need to prepare a Python dictionary (wrapped in a function) with the relevant <a href="https://altair-viz.github.io/user_guide/configuration.html">configuration</a> for our case. Then, we have to register it via the respective API and enable it (globally). If you prefer to <a href="https://altair-viz.github.io/user_guide/configuration.html#changing-the-theme">use the theme just for a single chart</a>, it is also possible to do it through a context manager with the <a href="https://docs.python.org/3/reference/compound_stmts.html#the-with-statement">with statement</a>.</p><p>Now, let’s create a small theme in order to exemplify the process of preparing custom Altair themes. This small theme will be focused on the Y-axis.</p><h4>Set the Configuration for the Theme</h4><p>First, let’s define a function that returns a dictionary. In this dictionary, we will add the configuration we need to make the charts look the way we want and which will be added to the specification of each chart. In practice, we create a nested dictionary according to the available properties, grouped by configuration types.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1aeb15174d5c3965b110616a9533dfaf/href">https://medium.com/media/1aeb15174d5c3965b110616a9533dfaf/href</a></iframe><p>For this theme, the Y-axis will not have a domain line, the ticks will be larger than the default ones, and we will have dashed gridlines. We will also remove the gray border around the chart area. All options are described in both the <a href="https://altair-viz.github.io/user_guide/configuration.html">Altair</a> and <a href="https://vega.github.io/vega-lite/docs/config.html">Vega-Lite</a> documentations.</p><h4>Register and Enable the New Theme</h4><p>Once we have the theme function, we need to register it under the chosen name (y_axis) and enable the theme.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25846a14cc3e76fa34e1e178945aa920/href">https://medium.com/media/25846a14cc3e76fa34e1e178945aa920/href</a></iframe><p>Now, for example, when displaying a bar chart, we can see that the Y-axis has a different style than the default one, according to our new theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBKtcpf_dX1tP34YEcDWjA.png" /><figcaption>A <a href="https://altair-viz.github.io/gallery/simple_bar_chart.html">bar chart</a> with the default Altair theme (left) and the newly created theme (right). The new theme customizes the Y-axis and removes the gray border around the chart area.</figcaption></figure><p>To revert to the default Altair theme, we just need to run alt.themes.enable(&quot;default&quot;).</p><h3>Packaging Altair Themes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqq9O9jR9ZdtgYjWSgoPOQ.png" /><figcaption>Our theme applied to some charts from the <a href="https://altair-viz.github.io/gallery/index.html">example gallery in the Altair documentation</a>. This theme is a light theme.</figcaption></figure><p>To package and distribute Altair themes, in addition to the typical things of a Python package and the theme function, we can use one specific <a href="https://setuptools.pypa.io/en/latest/userguide/entry_point.html">entry point</a>. This entry point is named <a href="https://github.com/altair-viz/altair/blob/v4.2.0/altair/vegalite/v4/theme.py#L35">altair.vegalite.v4.theme</a>, and it is used in the setup.py file (or equivalent).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/500ebc4e447fb45328d6831f7734967a/href">https://medium.com/media/500ebc4e447fb45328d6831f7734967a/href</a></iframe><p>In this way, there’s no need to import this extra package. The new theme will be available together with the default ones — it is just a matter of enabling it and starting plotting!</p><h3>feedzai-altair-theme Package</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c45e6e4f1aab51dcfc64414c5fd26d4f/href">https://medium.com/media/c45e6e4f1aab51dcfc64414c5fd26d4f/href</a></iframe><p>The feedzai-altair-theme package consists of two major parts: the design tokens (which come from our guidelines) and the theme.</p><p>The <strong>design tokens</strong> are defined in the <a href="https://github.com/feedzai/feedzai-altair-theme/blob/master/feedzai_altair_theme/tokens.py">tokens module</a>. Here we can find the spacing scale, font sizes, border widths, and colors, among other tokens. This separate module allows us to reuse these variables throughout the configuration for the Altair theme. In addition, we can easily map these tokens with our guidelines and other supports, ensuring the desired consistency.</p><p>Additionally, this package organization allows us to use these tokens in a standalone fashion. Considering the available color palettes, we can import the respective variable from the tokens module, choose a sequential color palette different from the default one, and easily apply it to a specific chart.</p><p>The <strong>theme</strong> itself is in the <a href="https://github.com/feedzai/feedzai-altair-theme/blob/master/feedzai_altair_theme/theme.py">theme module</a>. As we saw earlier, it consists of a function that returns a dictionary with all the properties that we intend to customize to obtain the desired style for our charts. One helpful thing in Altair/Vega-Lite is that we only need to define what’s relevant since it provides nice defaults for the rest.</p><h3>Quickstart</h3><p>To know more about the feedzai-altair-theme package, go to our <a href="https://github.com/feedzai/feedzai-altair-theme">GitHub repository</a>. Here you can find how to install the package and how to start using it — there’s also a notebook with some examples based on the ones available in the <a href="https://altair-viz.github.io/gallery/index.html">Altair documentation</a>.</p><p>After installing the package, run this snippet in a Jupyter notebook, for example, and you’ll see the theme applied to your charts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d11067a3c8a4f2e503a40c5be88855fc/href">https://medium.com/media/d11067a3c8a4f2e503a40c5be88855fc/href</a></iframe><p>To see this theme in action, the <a href="https://github.com/feedzai/timeshap">TimeSHAP package</a>, also open-sourced by Feedzai, uses the feedzai theme as part of its visualization subpackage (plot).</p><p>If you have any questions or feedback, feel free to <a href="https://github.com/feedzai/feedzai-altair-theme/issues">open an issue in our repository</a>. In case you try it out in your charts, please let us know and share the results below in the comments section!</p><p><em>Rita Costa, Beatriz Feliciano, Javier Pérez, and Sanjay Salomon: thank you so much for your thoughtful feedback that helped me shape this blog post! Beatriz Malveiro: this effort was only possible thanks to your previous work and your help in preparing the Python package — thank you very much!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3dcd27b3b68" width="1" height="1" alt=""><hr><p><a href="https://medium.com/feedzaitech/styling-altair-charts-with-the-feedzai-altair-theme-f3dcd27b3b68">Styling Altair Charts with the feedzai-altair-theme</a> was originally published in <a href="https://medium.com/feedzaitech">Feedzai Techblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Plotting the first point of the Feedzai Charting Library.]]></title>
            <link>https://medium.com/feedzaitech/plotting-the-first-point-of-the-feedzai-charting-library-50f21b4a5e01?source=rss-3f58d340dd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/50f21b4a5e01</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[vegas]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[João Palmeiro]]></dc:creator>
            <pubDate>Wed, 22 Jan 2020 12:22:10 GMT</pubDate>
            <atom:updated>2020-12-14T00:13:57.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a-yi7OzrpuTZL33GCy2YPg.jpeg" /></figure><h3><strong>{ “context” :</strong></h3><p>Between July and August, I had the opportunity to join Feedzai’s 2019 summer internships as an Engineering Intern. I worked with the Data Visualization folks at the kickoff of the <strong>Feedzai Charting Library</strong>.</p><h3><strong>},<br>{ “motivation” :</strong></h3><p>Feedzai Charting Library — I think you already have a glimpse of what this project is all about just by the name. Data is at the core of Feedzai and their visualization provides an effective way of communicating… but why would Feedzai care about creating its own charting library? Let’s look at some of the macro reasons most supported by the term “Library” rather than the term “Charting”:</p><ul><li>At Feedzai, currently there are no standards for formatting and designing visualizations. This kickoff can also be the beginning of something like a “Data Visualization style guide” that could be integrated into Feedzai’s design system.</li><li>Different technologies/libraries are used for creating charts in Feedzai’s products. This Charting Library would enable us to homogenize everything under the same technology/library.</li><li>Since two charts, although with the same name, may differ, reproducibility is also an important aspect. Thus, the possibility of obtaining the same chart, as agnostic as possible, in different platforms is quite tempting. For example, it would be possible for Data Scientists to use it in Python, Front-End Engineers in web applications and even Business Intelligence Developers in Kibana!</li></ul><p>Although briefly presented, these points summarize the motivation for this modest venture quite well. They are a bit “general”, but in a way, they were born purely from our context — if you have a few different or complementary thoughts about creating a library, in this case, a charting library, feel free to share them in the comments!</p><h3><strong>},<br>{ “feedzaiChartingLibrary” :</strong></h3><p>From this concept, many questions arise regarding the scope of the library: what charts to include, what level of customization to allow, what technologies to use, and more. We have a jungle full of possible paths and traps. And when those traps are activated, they unleash an avalanche of rocks that threaten to bury us. However, instead of rocks, we have pie charts… in 3D. So which way should we go?</p><p>We thought a good starting point would be to expand the React UI Component library used across Feedzai products with components dedicated to different types of charts, and to define these charts in Vega.</p><p>At first glance, it seems we have somewhat blurred platform-agnosticism. However, Vega, as we will talk about later, is very flexible and the idea of a repository with visualizations that everyone can contribute to and use will not be forgotten (<em>#BabyStepsToGiantStrides</em>). For now, let’s dig into the first steps.</p><p>Since the start of this project is intrinsically associated with the internship, it becomes interesting to talk about both at the same time. First things first: the first week of the internship was devoted to onboarding, getting to know Feedzai from the inside (and in terms of Data Visualization), and learning about Vega. It was crucial to get to know Feedzai better before I started writing any code whatsoever because this library must be created and adopted smoothly. It was like visualizing before the visualization (mind = blown?). The next (approximately sequential) steps involved the following actions:</p><ol><li>Become <em>Vegan</em> (did you see what I did there?) and design some sample charts.</li><li>Learn about using React and Vega together, and how React-specific Data Visualization libraries work in general (like <a href="https://uber.github.io/react-vis/">react-vis</a>, <a href="https://formidable.com/open-source/victory/">Victory</a>, <a href="http://recharts.org/en-US/">Recharts</a>, <a href="https://nivo.rocks/">nivo</a>, and <a href="https://vx-demo.now.sh/">vx</a>). The second part was just to get some inspiration. I didn’t copy any code, I swear (😛).</li><li>Integrate React and Vega into a demo application with some charts and interaction.</li><li>Write the JSON specification for a simple histogram.</li><li>Create a new branch from the React UI Component library and add a new component, in this case, a Histogram component that could generate simple histograms as well as overlaid histograms.</li><li>Use the new Histogram component in another Feedzai library to evaluate the possibility of integrating this new component in the future.</li><li>Learn about unit testing (and some theory).</li><li>Write a test suite for the Histogram component.</li><li>Write a blogpost up to this point and then from here to the end.</li></ol><p>Of course, the internship didn’t follow this so linearly; it obviously passed through an <em>activation function</em>. Overall, things proceeded at a good pace, even with some winding moments. During these two months, I followed what I call a <em>DAAAG</em> (don’t confuse it with a DAG, Directed Acyclic Graph, please). <em>DAAAG </em>stands for “Directed Absorption, Application, Assessment Graph” and summarizes the methodology I adopted.</p><p>Starting with “<strong>Absorption</strong>”, I tried to learn as many things as possible to gain the minimum confidence needed to apply (“<strong>Application</strong>”) my learnings and start the work required to meet the goals for this internship.</p><p>After completing small chunks, the “<strong>Assessment</strong>” node would arrive and, with more calm and constructive criticism, I tried to understand if what I did was good, or if I should implement some changes. This way, I wasn’t so stuck on how to implement something, I just let it happen. With the gained knowledge and experience, my critical eye became a little sharper, and the next steps became a little clearer, mitigating the impact of a bad idea and ensuring that every day I made at least a little bit of progress on the roadmap. However, as might be expected, this route was not fully sequential. Over time, it was necessary to jump between nodes in this graph, as I had to check the Vega documentation to learn something new or implement a quick change during the evaluation process to be able to quickly test a new idea, for example.</p><p>You might wonder why we decided to start with the histogram as the first visualization for our library. Good question! There were two reasons:</p><ul><li>First, histograms (in particular a variation of them) are one of the most commonly used chart types within Feedzai and across its products.</li><li>Secondly, introducing and integrating a possible React Component with a ready-to-use histogram (rather than another kind of data visualization) offered a smaller challenge both in terms of complexity and time within Feedzai.</li></ul><p>We’ll get back to these points later, but for now, let’s look at the technologies used besides our old friends “pen and paper”.</p><h3><strong>},<br>{ “technologies” :</strong></h3><p>Regarding the stack used during the internship, the following technologies and libraries stand out:</p><ul><li><a href="https://reactjs.org/">React</a>.</li><li><a href="https://vega.github.io/vega/">Vega</a>.</li><li><a href="https://github.com/vega/vega-embed">Vega-Embed</a>.</li><li><a href="https://jestjs.io/">Jest</a>.</li><li><a href="https://airbnb.io/enzyme/">Enzyme</a>.</li><li><a href="https://lodash.com/">Lodash</a>.</li><li><a href="https://storybook.js.org/">Storybook</a>.</li></ul><p>First of all, <strong>React</strong> is… well, React is React. It is one of the most widely used and known JavaScript libraries for building user interfaces today.</p><p>I’ve mentioned <strong>Vega </strong>a few times already, but I wasn’t referring to the brightest star in the constellation of Lyra. I’ve been referring instead to a visualization grammar of the same name. Vega is a declarative language for describing and creating interactive data visualizations. The description (known by <em>specification</em>) of both the visual appearance and the interactive behaviour of a visualization is done in a JSON format. After that, the specification is parsed by Vega’s JavaScript runtime and we can generate static images or web-based views (using Canvas or SVG). This way, Vega provides a broad set of building blocks that allows you to plan and build flexible visualizations. Some examples of these building blocks are: data loading and transformation, scales, map projections, axes, legends, graphical marks such as rectangles and lines, among others. On the other hand, interactions can be specified using reactive signals that dynamically adjust a visualization in response to input event streams. For more information, you can check the <a href="https://vega.github.io/vega/docs/">documentation</a>. I’d suggest reading <a href="https://vega.github.io/vega/about/">this page</a> as it provides an interesting overview of the foundations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PyN8l3hVhu4iugsZxW8BXQ.png" /><figcaption>Spoiler!</figcaption></figure><p>To make it easy to load a Vega specification into a React Component, we took advantage of <strong>Vega-Embed</strong>, a helpful package that comes with three fantastic extras: a button with action links such as “Save as PNG/SVG”, a tooltip plugin (<a href="https://github.com/vega/vega-tooltip">Vega Tooltip</a>), and some predefined themes (<a href="https://github.com/vega/vega-themes">Vega Themes</a>).</p><p>In order to ensure the created component worked as intended, we coupled a test suite. With the help of <strong>Jest</strong> and <strong>Enzyme</strong>, a set of unit and snapshot tests were defined.</p><p>Jest and Enzyme are different (but complementary) testing tools. While Jest acts as a test runner, assertion library, and mocking library, Enzyme adds some additional utility methods for rendering a component, finding elements, and interacting with them. Both are widely used in React, although Jest, like a good joke, works very well elsewhere (<a href="https://www.typescriptlang.org/">TypeScript</a>, Angular, Vue, etc.).</p><p>Finally, it’s worth mentioning the use of <strong>Lodash</strong>, a JavaScript utility library with lots of methods to solve certain needs in a productive way (like performing a deep comparison between two objects to determine if they are equivalent), and <strong>Storybook</strong>. Storybook provides an excellent sandbox to mock different components (and different states and/or props, for example) and expose them in a pleasant way for the stakeholders. Basically, we end up with a kind of wiki that we can easily browse and check the different available components.</p><p>In short, I think the stack used can be summarized as “JS²” — <strong><em>J</em></strong><em>e </em><strong><em>S</em></strong><em>uis </em><strong><em>J</em></strong><em>ava</em><strong><em>S</em></strong><em>cript</em>.</p><h3><strong>},<br>{ “theDirt” :</strong></h3><p>It is finally time to look at the “dirt”! In this part, I will share some of the details of what we managed to achieve, the problems we faced, and the doubts that remain. I’ll also share some ideas on possible vectors worth exploring in the future.</p><p>First, the <strong>Vega specification</strong>, that is, the JSON file, contains a basic histogram with some artificial data. Thus, it is ready to be used in any of the supported platforms, and we allow anyone interested in testing the Vega specification to see a simple, out-of-the-box example. Therefore, one of the responsibilities of the React <strong>Histogram component</strong> is to adapt and customize this Vega specification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VqqVWlRpwh8wU4bVSZlVAg.png" /><figcaption>The first few lines of a possible Vega specification.</figcaption></figure><p>Before delving into some of the details of the solution’s design, I think it is useful to first give an overview of the <strong>Histogram component</strong>. This component is a class component, with multiple props, that leverages some lifecycle methods. It is important to note that we used refs to facilitate the identification of the container (&lt;div&gt;) in which the histogram is embedded. This allows us to capitalize on the “commit phase” (as we can work with the DOM) to “mount” and “update” the chart (according to the original and new props, respectively). Note that in the “render phase”, we just add the empty container that will later contain the chart. A new container, as well as a new chart, is rendered every time there is an update.</p><p>These are the main <strong>features </strong>of the Histogram component:</p><ul><li>Basic histogram for a single distribution.</li><li>Overlaid/Overlapping histogram for two distributions.</li><li>Legend with customizable labels.</li><li>Vertical axis with a linear or logarithmic scale (semi-log plot).</li><li>Tooltip to show some details associated with each of the bars.</li><li>In the case of the overlaid histogram, an interactive legend that allows viewing only one of two available distributions.</li><li>A dynamic number of labels depending on the number of bins to allow a good strategy for overlapping information on the horizontal axis.</li><li>Button with action links to save the chart in two different image formats.</li><li>A threshold marker to specify a reference value.</li></ul><p>Although a histogram is one of the most widely used and well-known chart types, our component needed to handle challenges beyond styling a simple “set of bars”:</p><ul><li>Given the complexity and size of the data Feedzai handles daily, <strong>all the calculations needed to transform data for visualization are done outside</strong> of the Histogram component.</li><li>We achieved the conjugation between React and Vega through an approach called <strong><em>Lifecycle Methods Wrapping</em></strong>. The lifecycle methods wrap the creation, updating, and removal of Vega charts, establishing a kind of boundary between React and Vega code.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yes5zwK4LrmACQQXnZsi7w.png" /><figcaption><em>Lifecycle Methods Wrapping </em>basic skeleton.</figcaption></figure><p>On the other hand, while it was not difficult to integrate React and Vega, we were walking in uncharted territory. <strong>There aren’t many examples or use cases</strong> that combine React and Vega, and little discussion on possible approaches (as well as advantages and disadvantages). The best (in my opinion) <a href="https://medium.com/@pbesh/react-and-vega-an-alternative-visualization-example-cd76e07dc1cd">blogpost</a> found, written by Peter Beshai, dates back to 2016 and is just a simple proof of concept. It doesn’t cover component creation to integrate into a UI library used in production.</p><p>In order to narrow this gap a bit, and given that Vega uses <a href="https://d3js.org/">D3</a> heavily within its implementation, the research also focused on <strong>how to combine React and D3</strong>, as there are significantly more resources. Given this scenario, it is evident that to extract the potential associated with React and Vega, and <em>DOMinate</em> both at the same time, we needed plenty of room for iteration until we found a final solution.</p><p>One of the ideas that did not go forward was the use of <a href="https://github.com/vega/react-vega"><strong>react-vega</strong></a>. This package is intended to convert Vega specifications into React class components. However, there is no clear advantage in using this package, and improving React support is still a point in the <a href="https://docs.google.com/document/d/1fscSxSJtfkd1m027r1ONCc7O8RdZp1oGABwca2pgV_E/edit?usp=sharing">Vega (and Vega-Lite) roadmap</a> (<em>Improved React Support</em>). So, we chose not to use this additional third-party package. The code that makes up this package has only been checked to complement the research done as it has important details to consider.</p><p>Looking at the Vega roadmap, there are two features that we are really looking forward to: <em>Animations</em> and <em>Labeling</em>.</p><p>Animations would be useful to show small differences if the distribution in the histogram changes. Native support for labelling would allow us to reduce the number of JSON lines currently required to introduce the threshold marker (fortunately, there is already a nice prototype called <a href="https://github.com/vega/vega-label">Vega-Label</a>!).</p><p>Regarding data, <strong>Vega has a well-defined data model</strong> which uses <em>tabular</em> data. This should be kept in mind, as the data that is passed to our component is already transformed and may no longer be in its original shape. Therefore, we may have to reshape it. This happened when we tested the new Histogram component in another Feedzai library to evaluate the possibility of integrating it in the future. Since the data feeding the histogram did not fit a <em>tabular</em> format, it was necessary to make some changes to the calculations and objects to ensure that the histogram received the data as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYJWeqanCbncFZbyDvpLFw.png" /><figcaption>Data model used by Vega.</figcaption></figure><p>Finally, I would like to share some <strong>backlog ideas</strong> in the hope that it gives you a glimpse of possible future steps.</p><p>There’s still a lot to consider regarding the React + Vega relationship, as it was one of the main pivots during the internship. It’s inevitable to wonder if there is a better way to <strong>unfold the relationship between </strong><a href="https://vega.github.io/vega/about/vega-and-d3/"><strong>Vega and D3</strong></a> (or the concept of <em>SVG Illustrations as React Components</em> out there). Strategies for integrating React and D3 have already been widely discussed and proven to work in a way which is consistent with React. This means that D3 is responsible for the mathematical part of creating charts, and the DOM leadership belongs to React. In short, D3 performs all the calculations for SVG paths, scales, layouts, and any transformations that take some data, and then React takes the results of these calculations and draws the chart. This (not vectorized) path is the most React-friendly one. It becomes tempting to consider if there will be a similar way of approximating React and Vega closer together by creating a kind of framework that allows the efficient construction of specifications and components for new types of data visualization. However, <strong>Vega is not D3</strong>, even if the former depends heavily on the latter. D3 is intentionally a lower-level library, a kind of “visualization kernel”, whereas Vega provides a higher-level visualization specification language. By design, D3 maintains an “expressivity advantage” (in some cases it will be better suited for novel charts, for example) and Vega a “convenience advantage” (for a wide range of common, yet customizable visualizations, for example). Therefore, it is important to remember the philosophy of Vega and stick to it. Unfortunately, during the internship, I could not come up with a substantially different strategy from the one implemented, but I strongly believe it exists. Consider this paragraph mainly as <strong>food for thought</strong>.</p><p>Since only unit (and snapshot) tests were implemented, it would be important to consider <strong>other types of tests</strong> in the future (as well as assess their possible interaction with React and Vega), such as integration tests and end-to-end tests, but particularly some <strong>visual regression testing</strong> (unit tests have a very specific low granularity and don’t see the bigger picture).</p><p>Briefly, in visual regression testing, we render a page, take screenshots of specific elements, and then compare the new screenshots with the ones taken earlier. This way, if there are differences, a possible test will fail and a comparison image is created so that a developer can look for any problems in the code. As you can imagine, it is critical that the Feedzai Charting Library charts show exactly what we expect them to show because <strong>small differences in what we see can lead to big differences in what we think</strong>. This type of testing is a useful complement to standard testing, especially when it detects changes that are very difficult for the human eye to spot and that may misrepresent what we hoped to show. If you are interested in learning more, <a href="https://visualregressiontesting.com/">this website</a> is a great aggregator of articles and tools on visual regression testing.</p><h3><strong>},<br>{ “takeaways” :</strong></h3><p>Just two months of work and so much to cover! I hope the previous sections have been clear (and fun) and that you now have a “mind chart” full of ideas for the future.</p><p>These are perhaps the most important things I carry with me from my internship:</p><ul><li><strong><em>The core being the core</em>.</strong> During this internship, I understood the importance and advantages of making sure that I clearly knew the core. In other words, learning Feedzai at my own pace — from the inside, along with its Data Visualization needs — was key to understanding what my job and responsibilities would be, but above all, why and how this project could help Feedzai.</li><li><strong><em>PPT should mean “People, Presentations, and Time”</em>.</strong> It may sound cliché to talk about the importance of teamwork, but there are two specific things that I have experienced and would like to repeat. The weekly syncs, with three people who were always willing to listen and help me, as well as the challenge of presenting the Feedzai Charting Library several times and in distinct contexts, were fundamental to strengthen my learning process and to receive useful feedback. In particular, the weekly syncs, for their periodicity, allowed me to organize my work and quickly tackle any blocks that came up. Regardless of the block, I knew there would be an unblock.</li><li><strong><em>Vega is not a star, it is a constellation</em>.</strong> Not much to add after I’ve spent so much text talking about Vega. Vega (and <a href="https://altair-viz.github.io/index.html">Altair</a>) is an excellent option that I will always keep in mind whenever I need to visualize data. Distinct from more straightforward libraries, such as <a href="https://seaborn.pydata.org/">Seaborn</a>, and also from D3, it has its own characteristics that can be useful.</li><li><strong><em>FreeDOM</em>.</strong> Feedzai is like the DOM — a logical tree where each of us is a node with a unique set of characteristics. Leaving the geek puns aside, the thing that hooked me the most was the freedom and trust they had in me from the first day. It translated into something beautiful where I was able to actively engage. This formula, although intimidating at first, proved to be gratifying, so I truly thank Feedzai for this opportunity. Using my wildcard quote for this blogpost, and looking inside Feedzai, I’m reminded of Steve Jobs’s quote: “It doesn’t make sense to hire smart people and tell them what to do; we hire smart people so they can tell us what to do.”</li><li><strong><em>Data Visualization (not so) cookbook</em>.</strong> Creating a visualization is like cooking steak with white rice; while not being worthy of a Michelin star, it ensures subsistence and provides satisfaction. However, sometimes, you need to show off how great your cooking skills are. The same goes for Data Visualization. What I’m trying to say is that, in some contexts, a “bland” chart won’t do, and it is critical to work towards custom (and customizable) visualizations.</li><li><strong><em>When God created Data Visualization</em>.</strong> A dash of design, a bit of data science, a touch of front-end development… and we ended up with a very tasty mix! In Data Visualization, we have one of those crazy Venn diagrams with lots of subtopics that eventually come together in this discipline. Since I really like daily variety in my job, I was drawn to Data Visualization. If you like mixing different areas of knowledge, then maybe Data Visualization is for you too.</li><li><strong><em>Very fruit ninja</em>.</strong> I ate an average of 2 bananas a day (this sample was taken from a uniform distribution). Maybe I should try other fruits next time.</li></ul><h3><strong>},<br>{ “demo” :</strong></h3><p>Before closing this blogpost, there is one last thing I want to show you. You can find a small demo of a React + Vega application with a basic histogram and a button that allows you to change the size of the bins <a href="https://github.com/joaopalmeiro/react-vega-demo">here</a>. Also, if you want to see other examples, check out the <a href="https://vega.github.io/vega/examples/">examples section</a> of the Vega website.</p><h3><strong>},<br>{ “acknowledgements” :</strong></h3><p>This is the easiest part to write. First, I want to thank Feedzai, as an organization, for this amazing opportunity and all the support. It was two months of extremely gratifying work. From the first contact, I felt a warm atmosphere (which I believe will continue as long as I do not commit any fraud). In particular, I would like to truly thank the three people who supported me most during this period, namely Beatriz Jorge, Liliana Fernandes, and David Polido. You kicked off the idea of the Feedzai Charting Library and, since my interview, you have been present not only to help me and contribute to the project, but also to talk, discuss Data Visualization, and provide me with other complementary opportunities during the internship. It was a really good experience and it allowed me to greatly enrich my “dataset” for the future — thank you very much for everything! Finally, I would also like to thank Krisztina Nagy and Indigo Wilmann for the careful feedback that allowed me to reach the best possible version for this blogpost. Otherwise and alone, this would not be possible.</p><h3>}</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50f21b4a5e01" width="1" height="1" alt=""><hr><p><a href="https://medium.com/feedzaitech/plotting-the-first-point-of-the-feedzai-charting-library-50f21b4a5e01">Plotting the first point of the Feedzai Charting Library.</a> was originally published in <a href="https://medium.com/feedzaitech">Feedzai Techblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A medium () to get tips for the Medium text editor.]]></title>
            <link>https://joaompalmeiro.medium.com/a-medium-to-get-tips-for-the-medium-text-editor-9be4689c9399?source=rss-3f58d340dd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9be4689c9399</guid>
            <category><![CDATA[medium]]></category>
            <dc:creator><![CDATA[João Palmeiro]]></dc:creator>
            <pubDate>Wed, 15 Jan 2020 13:15:05 GMT</pubDate>
            <atom:updated>2021-01-02T21:44:09.264Z</atom:updated>
            <content:encoded><![CDATA[<h3>A medium (😛) to get tips for the Medium text editor</h3><h3>Inline code</h3><p>To add <strong>inline code</strong>, type in `(single backtick) <strong>followed by a whitespace</strong> and then the desired text.</p><ul><li>Without the whitespace: `&lt;div&gt;.</li><li>With the whitespace: &lt;div&gt;.</li></ul><h3>Image captions</h3><p>It’s not possible to italicize all text or individual words in image captions. Image captions can only contain normal, bold, and/or hyperlinked text.</p><figure><img alt="Black rectangle to symbolize a possible image." src="https://cdn-images-1.medium.com/max/600/1*i69pfUp45FRc2MqIp0dQ6w.png" /><figcaption><strong>Example</strong> of an <a href="https://medium.com/@joaompalmeiro/a-medium-to-get-tips-for-the-medium-text-editor-9be4689c9399">image caption</a>.</figcaption></figure><h3>Single-spaced line break</h3><p>To add a single-spaced line break, press Shift + Enter at the end of the line.</p><ul><li><em>Default</em> line break:</li></ul><p>First line of text.</p><p>Second line text.</p><ul><li>Single-spaced line break:</li></ul><p>First line of text.<br>Second line of text.</p><h3>Code snippet images vs. GitHub gists</h3><p>A cleaner, more interactive alternative to code snippet images is <a href="https://gist.github.com/">GitHub gists</a>. Both allow for adding an <em>image</em> caption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yes5zwK4LrmACQQXnZsi7w.png" /><figcaption>Code snippet image (made with <a href="https://carbon.now.sh/">Carbon</a>).</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cdadfa2a74d892e16f325c70e70ca23/href">https://medium.com/media/6cdadfa2a74d892e16f325c70e70ca23/href</a></iframe><h3>Writing math</h3><p>One way to add properly formatted formulas is to embed LaTeX (<a href="https://katex.org/">KaTeX</a>) formulas with <a href="https://embed.fun/">Embed Fun</a>. After publishing a formula, just insert the <em>Direct Link</em> here in the same way as a GitHub gist.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fmath.embed.fun%2Fi7myk1LeoXq7ZCwBWVLLHw&amp;src=https%3A%2F%2Fmath.embed.fun%2Fembed%2Fi7myk1LeoXq7ZCwBWVLLHw&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=embed" width="200" height="135" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd44fdf0980b8de22f94a0702590324a/href">https://medium.com/media/dd44fdf0980b8de22f94a0702590324a/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9be4689c9399" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dia dos Namorados vs. Dia da Mãe ]]></title>
            <link>https://joaompalmeiro.medium.com/dia-dos-namorados-vs-dia-da-mae-a5230416bb98?source=rss-3f58d340dd3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5230416bb98</guid>
            <dc:creator><![CDATA[João Palmeiro]]></dc:creator>
            <pubDate>Fri, 14 Feb 2014 05:18:59 GMT</pubDate>
            <atom:updated>2014-02-14T05:18:59.267Z</atom:updated>
            <content:encoded><![CDATA[<h4>Por exemplo</h4><p>O Dia dos Namorados é como o Dia da Mãe (por exemplo). Um é dedicado aos casais de namorados, o outro é dedicado a uma das pessoas que nos trouxe ao RPG que é a vida. E não é por ser filho e/ou pai, que vou andar a resmungar e a mandar as designadas “dicas” no Dia da Mãe, já que sou pai e/ou filho, em vez de mãe! Eu bem tentei mandar cá em casa, como uma mãe, mas não consegui impor essa hierarquia.</p><p>É verdade que há um Dia do Pai e um Dia da Criança/Filho (uma vez que o filho nasce como uma criança, excepto o Benjamin Button, coitado), então eles têm o seu massivo momento de comemoração. Contudo, senão há um Dia do Solteiro assumido, então, pela Lei do Anulamento do Produto (agora já estou a inventar), todos os outros dias, são “Dias do Solteiro”. E ainda há mais. Se o ano for bissexto, ainda há mais um dia para festejar! E por incrível que pareça, no Dia dos Namorados, os solteiros também podem festejar! Ainda por cima calha a uma sexta-feira este ano, portanto…</p><p>Portanto… Deixem-se de ser brutos e deixem lá os “casais de pombinhos” e das outras espécies, utilizarem as suas “lamechices” e os seus pensamentos eróticos que têm armazenado para um ocasião dita de “especial”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5230416bb98" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>