<?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 Maarit Widmann on Medium]]></title>
        <description><![CDATA[Stories by Maarit Widmann on Medium]]></description>
        <link>https://medium.com/@maarit.widmann?source=rss-298582d6a022------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dBzxiiZ_AoL3fprrqkqyqQ.jpeg</url>
            <title>Stories by Maarit Widmann on Medium</title>
            <link>https://medium.com/@maarit.widmann?source=rss-298582d6a022------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:54:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maarit.widmann/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[Understanding and Applying Correspondence Analysis]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/understanding-and-applying-correspondence-analysis-cbd0192dec4?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbd0192dec4</guid>
            <category><![CDATA[correspondence-analysis]]></category>
            <category><![CDATA[knime]]></category>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[theory]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Wed, 26 Jul 2023 07:51:40 GMT</pubDate>
            <atom:updated>2023-07-26T07:51:40.110Z</atom:updated>
            <content:encoded><![CDATA[<h4>DATA SCIENCE THEORY | CORRESPONDENCE ANALYSIS | KNIME ANALYTICS PLATFORM</h4><h4>A low-code approach to analyze associations in categorical data by projecting the categories of the variables onto new numeric dimensions</h4><p><em>Co-author: </em><a href="https://www.linkedin.com/in/alfredo-roccato-2699094/"><em>Alfredo Roccato</em></a><em>. As first published on </em><a href="https://www.infoq.com/articles/knime-correspondence-analysis/"><em>InfoQ</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yF5l9DpVlKlTbQww" /><figcaption>Photo by <a href="https://unsplash.com/@uxindo?utm_source=medium&amp;utm_medium=referral">UX Indonesia</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><h3>Key takeaways</h3><ul><li>Simple correspondence analysis (CA) is a technique to analyze relationships between categorical variables and create profiles based on the projections of the original variables to the new dimensions that it creates</li><li>CA begins with transformation of the raw data into a two-way contingency table that shows the frequency distribution of the variables</li><li>Based on the proximity along the first few of the projected dimensions, we can visually explore the individuals’ and categories’ associations and can interpret a dimension generated by CA as a new, synthetic variable</li><li>Proximity in the feature space indicates positive association, and the closer the angle between two groups/categories is to 90°, the less they are associated</li><li>You can download a pre-packaged CA <a href="https://hub.knime.com/-/spaces/-/latest/~NpFKwwOmYluLxtM1/">workflow from the KNIME Community Hub</a> that implements data reading, preprocessing, descriptive analysis, and CA</li></ul><h3>Introduction</h3><p>Customer segments, personality profiles, social classes, and age generations are examples of effective references to larger groups of people sharing similar characteristics.</p><p>The characteristics that shape these groups are often manifold and thus require multivariate analysis.</p><p>One way to access the variables is via questionnaires. Because the variables are mostly qualitative, the questionnaires produce categorical data with predefined categories, for example, on a <a href="https://en.wikipedia.org/wiki/Likert_scale">Likert-type scale</a>.</p><p>The starting point to analyze the relationships between categorical variables is a contingency table which compares the categories pairwise.</p><p>As the next step, correspondence analysis (CA) performs a multivariate analysis on multiple contingency tables.</p><p>It projects them into a numeric feature space, which captures most of the variability in the data by fewer dimensions.</p><h3>What Is Simple Correspondence Analysis?</h3><p><a href="https://openlibrary.org/books/OL35735067M/L&#39;Analyse_des_donn%C3%A9es">Simple correspondence analysis</a> is a technique to analyze relationships between categorical variables and create profiles based on the projections of the original variables to the new dimensions that it creates. This is useful, for example, when analyzing and visualizing survey data.</p><p>CA processes a two-way contingency table that displays the frequency distribution between two variables. It represents the frequency distribution on numeric, orthogonal dimensions. Based on the proximity along the first few of these dimensions, we can visually explore the individuals’ and categories’ associations.</p><p>We can investigate, for example, if there is a relationship between interest in politics and demographics data such as age. Also, we can interpret a dimension generated by CA as a new, synthetic dimension, such as “status,” that captures several categories which together contribute to “high” or “low” status.</p><h3>How To Perform Correspondence Analysis</h3><h4><strong>Step 1: Data collection</strong></h4><p>We start the data collection by accessing survey data, with records for N individuals who have answered K questions.</p><p>As an example, we use the <a href="https://ess-search.nsd.no/">European Social Survey</a> data from the year 2018 measuring the attitudes, beliefs and behavior patterns in European nations. The data contains metadata and answers from 49,519 individuals recorded in 572 columns. We consider only a subset of the variables and perform CA to analyze the relationships between interest in politics, country, income, family relationship, gender, education, age, and internet usage.</p><p>These variables are transformed into a <a href="https://en.wikipedia.org/wiki/Contingency_table">two-way contingency table</a> (see the next step) based on the definition of row variables, column variables and supplemental variables as described below:</p><ul><li><strong>Row variables</strong> refer to variables that represent the row IDs. In our example, the interest in politics is the row variable. It contains the following four nominal classes: not at all, hardly, quite, and very interested. The data for 98 participants who didn’t provide the information about their interest in politics (not applicable, refusal, no answer, don’t know) were discarded from the analysis.</li><li><strong>Column variables</strong> refer to variables that represent the column headers. The column variables are income, family relationship, gender, education, age, and internet usage.</li><li><strong>Supplementary variables</strong> can be used to interpret the resulting profiles, but they are not used in computing CA. In our example, “country” is the supplementary variable.</li></ul><p>Note that if there were numeric variables, these had to be discretized before performing CA.</p><p>The survey data can be stored in varying formats, for example, in a csv file. Here, each row corresponds to an individual filling out the survey. Each column represents a survey question or metadata, such as the ID of the participant:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZbKtbDDpf1FwRjg3.png" /><figcaption>Figure 1. Raw survey data as a starting point of CA.</figcaption></figure><p>Notice that the column and row variables may need to be binned or encoded to help give a better understanding of the CA results. For example, the survey data reports 10 income deciles, which we encoded to seven income classes: very low, low, mid low, middle, mid high, high, and very high.</p><h4><strong>Step 2: Data preprocessing</strong></h4><p>In data preprocessing, we create a two-way contingency table that shows the frequency distribution of the row and column variables.</p><p>Figure 2. below shows a part of the contingency table for the survey data in our example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/0*Vi0RWQyuJC66N--N.png" /><figcaption>Figure 2. A two-way contingency table showing the preprocessed survey data before computing CA.</figcaption></figure><p>In the first row, it shows how the 17,837 survey participants hardly interested in politics are distributed into two categories, male and female, as well as into the seven categories describing family income. The more column variables there are, and the more categories in each column variable, the wider the table.</p><p>The transformation of the raw data into a contingency table is required to perform CA via the algorithms available, for example, in R software. In the next step, we explain how CA functions under the hood, although it is not necessary for executing such algorithms.</p><h4><strong>Step 3: Computing CA</strong></h4><p>Projecting the data into new numeric dimensions in CA works the same way as in principal component analysis (PCA), by sequentially constructing orthogonal dimensions of the data. This can be performed by <a href="https://en.wikipedia.org/wiki/Singular_value_decomposition">singular value decomposition</a>.</p><p>However, while in PCA, the decomposition is based on maximizing the variance; in CA it is based on maximizing the inertia.</p><p>For each row variable <em>i</em>, <a href="https://www.youtube.com/playlist?list=PLnZgp6epRBbTgO-l-6hLAKTstW7WSGh8A">inertia is calculated</a> with the following formula:</p><p><em>Inertia (i/G_J) =f_(i.)d^2x^2_(i,G_J)</em></p><p>Where <em>f_(i</em>.) is the weight, i.e., the marginal sum of row variable <em>i</em>, and <em>d^2x^2_(i,G_J)</em> is the <a href="https://en.wikipedia.org/wiki/Chi-squared_test">chi-squared distance</a> from the mean profile defined by the marginal probabilities of column variables <em>J</em>. The total inertia is calculated by summing up these inertias for all row variables <em>I</em>. In the extreme case, if the row reflects the mean profile, the inertia of that row variable is zero.</p><p>For column variables, the inertia is the sum of inertias of their categories <em>j</em>:</p><p><em>Inertia (j/G_I) = f_(.j)d^2x^2_(j,G_I),</em></p><p>Where <em>f_(.j)</em> is the weight, the marginal sum of column variable <em>j</em>, and <em>d^2x^2_(j,G_I)</em> is the chi-squared distance from the mean profile defined by the marginal probabilities of <em>I</em> row variables.</p><p>The sum of inertias of all column variables <em>j</em> produces the same total inertia as the sum of inertias of all individuals <em>i</em>.</p><h4>Step 4: Interpreting the results</h4><p>In this step, we explain how to interpret the results of CA visually in a scree plot and biplot and numerically via the output statistics.</p><p><strong><em>Scree plot</em></strong></p><p>To compare the percentages of total inertia that the new dimensions explain, we can take a look at a scree plot as shown in Figure 3:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*pJ_TnfetlBIkMEui.png" /><figcaption>Figure 3. Scree plot showing the percentages of inertia captured by the new dimensions generated by CA.</figcaption></figure><p>In our example, the first dimension explains 89.4% of the inertia, while the second dimension explains 10.19% of it. Together, the first two dimensions explain 99.5% of the total inertia.</p><p><strong><em>Biplot</em></strong></p><p>Next, we project the row and column variables into the first two dimensions and explore them visually in a <a href="https://en.wikipedia.org/wiki/Biplot">biplot</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*tjttr6H5mARdqWGc.png" /><figcaption>Figure 4. Biplot showing the row, column and supplementary variables in two-dimensional space.</figcaption></figure><p>The biplot shows the first two dimensions on the x- and y-axis. It is possible to show the row, column and supplementary variables along the same axes using transition formulas between the coordinates of row, column and supplementary variables.</p><p>Proximity in the feature space indicates positive association. For example, the group of individuals who are very interested in politics (PI: Very) is close to the category of very high income (FI:VeryHigh), and these variables are therefore strongly associated. Also, the categories of very high income and MA level education (EL: V2) are strongly associated. This implies that people with very high income have MA level education more often than an average person from any income class.</p><p>Also, the closer the angle between two groups/categories is to 90°, the less they are associated. For example, the categories “IU: Everyday” and “Age: 45–54” lie on the x- and y-axis, respectively. Therefore, this association is very weak. The contingency table in Figure 5 below confirms this: There is little deviation between the observed and expected value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*uurMVYMGH2uTtpgLbrsZtA.png" /><figcaption>Figure 5. A sample of a contingency table between analyzed variables.</figcaption></figure><p>The categories of the supplementary variable, i.e., the countries, help to interpret the dimensions. It seems that Switzerland (CN:CH) and the Nordic countries such as Denmark and Sweden (CN:DK and CN:SE) are strongly associated with the first dimension. Instead, the Baltic countries such as Estonia and Latvia (CN:EE and CN:LV) are strongly associated with the second dimension.</p><h3>Statistics</h3><p>Finally, we can inspect the groups, categories and new dimensions by looking at the output statistics. The table in Figure 6 shows a sample of the output statistics of CA for our example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/0*AmwMqj9Ej6vd-Ih4.png" /><figcaption>Figure 6 . The output statistics of CA.</figcaption></figure><p>The table contains the variables as row IDs and the statistics as column headers. For supplementary columns, there are no statistics, except dimensions 1 and 2, because they don’t contribute to the dimensions. Dimension 1 seems to relate positively to high levels of interest in politics, family income, education, age group, etc. Therefore, Dimension 1, which is highly important, could be interpreted as a “status” dimension (high vs. low).</p><p>In the table below, we explain what the output statistics of CA quantify and state an example question that we can answer by them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*ftwrYzirWKYR8f1aA16Sfg.png" /><figcaption>Table 1. Definitions and interpretations of the output statistics produced by CA.</figcaption></figure><p>Next, we show how to perform CA and produce the results introduced above in <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Analytics Platform</a>.</p><h3>Practical Implementation of CA</h3><p>In this section, we will introduce how to perform the example application of this article, analyzing social survey data via CA, in <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Analytics Platform</a>. The KNIME workflow below shows the steps.</p><p>You can download the <a href="https://kni.me/w/NpFKwwOmYluLxtM1">Exploring categorical data via Correspondence Analysis</a> workflow from the KNIME Community Hub and open it in KNIME Analytics Platform. <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Analytics Platform</a> is open source and can be downloaded from <a href="https://www.knime.com/downloads">the KNIME website</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5XzCB1q6FF-xTblW.png" /><figcaption>Figure 7. Example of KNIME workflow performing CA on European Social Survey data. You can download the workflow from the <a href="https://kni.me/w/NpFKwwOmYluLxtM1">KNIME Community Hub</a>.</figcaption></figure><p>The workflow progresses in four steps: data reading, preprocessing, descriptive analysis, and CA.</p><p>First, it accesses the data as a CSV file, which stores the data as shown in Figure 1.</p><p>Second, it accesses the dictionaries that contain the descriptions of the codes to replace them in the data. After that, it bins some of the variables into fewer categories. Then, it creates the contingency table as shown in Figure 2.</p><p>Lastly, it computes the CA and produces a view that displays the scree plot, biplot, and statistics table (Figures 3–4 and Table 1). It performs CA using functions of the R software, in particular, the ca() function of the <a href="https://cran.r-project.org/web/packages/ca/ca.pdf">ca package</a>. For the views, it uses the function ggplot() of the <a href="https://ggplot2.tidyverse.org/">ggplot2</a> package. The <a href="https://kni.me/e/6cbZ6X3DrLrH96WD">KNIME Interactive R Statistics Integration</a> allows us to write the script within the visual workflow.</p><p>In addition, it displays a bar chart and contingency table to explore the frequency distributions in the data in parallel to performing CA (Figure 5).</p><h3>Summary</h3><p>In this article, we introduced correspondence analysis, which analyzes associations in categorical data, and showed how it helps to analyze categorical data beyond a contingency table by projecting the categories of the variables onto new numeric dimensions. You can find these associations based on the proximity of the variables in a reduced feature space that could not otherwise be discovered through a pairwise analysis.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbd0192dec4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/understanding-and-applying-correspondence-analysis-cbd0192dec4">Understanding and Applying Correspondence Analysis</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create Workflow & REST Services with KNIME]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/how-to-create-workflow-rest-services-with-knime-229144dffb33?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/229144dffb33</guid>
            <category><![CDATA[getting-started]]></category>
            <category><![CDATA[knime]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[service-orchestration]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Mon, 17 Jul 2023 07:52:44 GMT</pubDate>
            <atom:updated>2023-07-17T07:52:44.583Z</atom:updated>
            <content:encoded><![CDATA[<h4>GETTING STARTED | SERVICE ORCHESTRATION | KNIME ANALYTICS PLATFORM</h4><h4>A guide to service orchestration with KNIME</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fl3zgcnlHLb0kHR8" /><figcaption>Photo by <a href="https://unsplash.com/@johnschno?utm_source=medium&amp;utm_medium=referral">John Schnobrich</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>“I know using the Call Workflow Service nodes can be a little tricky.”</p><p>That’s what my colleague wrote when answering <a href="https://forum.knime.com/t/how-to-send-data-from-the-first-called-workflow-to-the-second-called-workflow/45863">this</a> question on the KNIME Forum. They are indeed a bit tricky but once you get the idea they’re powerful!</p><p>To help you get started with calling workflows in different scenarios, I created this guide for you. I’ll point you to the nodes and simple example workflows that demonstrate how to exchange data between <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME</a> workflows and how to provide data from a <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME</a> workflow to an external tool.</p><p>When you call workflows, you execute isolated logics of the same end-to-end process. These called workflows are known as services, and bundling them together into one process is known as service orchestration. The workflow (or an external tool) calling a service is known as the client.</p><h3>Top 4 Benefits of Service Orchestration</h3><ol><li><strong>Load Applications Faster.</strong> Orchestration enables us to load applications faster. For example, if the service was a workflow and required connecting to databases or updating shared components, we would only perform these operations when the service was actually called with the relevant data from the client.</li><li><strong>Hide Redundant Information.</strong> Choose to only provide the output of the service to the client and not all the logic and intermediate results within it.</li><li><strong>Sequence Tasks in Correct Order/Real-time syncing of data.</strong>Via application orchestration we can also make sure that the tasks are sequenced in the correct order. The service reads its input at the moment when it’s called from the client, which enables real-time syncing of data between the service and client.</li><li><strong>Flexible Application Deployment.</strong> Orchestration also makes application development flexible. The same service can be called by multiple, different clients. Furthermore, the clients and services can be different tools, which enables you to align the business requests with the technical infrastructure effectively.</li></ol><p>I will now show you how to orchestrate your services with KNIME.</p><h3>Workflow Orchestration within KNIME</h3><p>Orchestration with KNIME is based on two types of workflows: <em>Callers </em>and <em>Callees. </em>The <em>Caller </em>is a client that sends/receives data from one or more callee. The <em>Callee </em>is a service that receives data from a caller, executes its task on that data, and sends the result to the client.</p><p>You can create callers and callees with KNIME in different ways. For example:</p><ol><li>Implement the process completely in KNIME</li></ol><ul><li>The caller and callee are both workflows</li></ul><p>2. Expose the workflow to an external/internal client as a <a href="https://en.wikipedia.org/wiki/Representational_state_transfer">REST </a>service</p><ul><li>The caller is an external client OR a workflow</li><li>The callee is a workflow</li></ul><p>3. Have the workflow call a result from an external service via REST</p><ul><li>The caller is a workflow</li><li>The callee is an external service</li></ul><p>In this guide, I’ll focus on the first two cases. I’ll start with the case where the process is implemented completely in KNIME. After that, I’ll show how to turn the callee workflow into a REST service and how to call the REST service from a workflow. Along the way, I will point to example workflows that you can find in my <a href="https://hub.knime.com/-/spaces/-/latest/~uCgwb2IYReTK1T0_/">KNIME Community Hub </a>space.</p><h4>Create Caller &amp; Callee Workflows within KNIME</h4><p>Use the following nodes to create a workflow service:</p><ul><li><a href="https://kni.me/n/SjCp1LKYnOOV8KMB">Workflow Service Input</a></li><li><a href="https://kni.me/n/9xSDVHDks-V8M3VU">Workflow Service Output</a></li></ul><p>Furthermore, you’ll need the <a href="https://kni.me/n/7RdeP2UQqCme0FL0">Call Workflow Service </a>node to call the workflow service.</p><ol><li><strong><em>Create the Callee Workflow within KNIME</em></strong></li></ol><p>I’ll now build a simple workflow service that provides the distribution statistics of its input column. For that, I need the the Statistics node and the <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.knime.callee.WorkflowInputNodeFactory/">Workflow Service Input </a>and <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.knime.callee.WorkflowOutputNodeFactory/">Output </a>nodes, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*SMfGwD1YR_BBaZp1wDooIw.png" /><figcaption>Figure 1. An example of a workflow service. <em>Download the </em><a href="https://hub.knime.com/maarit/spaces/Public/latest/Articles/Simple%20Workflow%20Invocation%20Examples/callees/example%20callee%20(workflow%20service)~BKHUggOyizMgXYoz"><em>example callee (workflow service) </em></a><em>workflow from the KNIME Community Hub.</em></figcaption></figure><p>By default the Workflow Service Input and Output nodes have data table input ports. However, you can change them to any other type according to the nodes between them. The only configuration of the <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.knime.callee.WorkflowInputNodeFactory/">Workflow Service Input </a>and <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.knime.callee.WorkflowOutputNodeFactory/">Output </a>nodes is the name of the parameter retrieved from and passed to the caller (Figure 1).</p><p><strong><em>2. Create the Caller Workflow within KNIME</em></strong></p><p>The workflow calling the workflow service above accesses and filters a numeric column for which the workflow service returns the distribution statistics.</p><p>The caller workflow (Figure 2 below) contains the CSV Reader node to read the data and the Column Filter node to select the column for which the distribution statistics are calculated. After that, we need the <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.knime.caller2.CallWorkflow2NodeFactory/">Call Workflow Service</a> node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ykQuOPdBs0vhIpSauouEA.png" /><figcaption>Figure 2. An example of a workflow calling a workflow service. <em>Download the </em><a href="https://hub.knime.com/-/spaces/-/latest/~yxA33faCGS0uJioV/"><em>call workflow service example </em></a><em>workflow from the KNIME Community Hub.</em></figcaption></figure><p>In Figure 2 you can also see the output of the <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.knime.caller2.CallWorkflow2NodeFactory/">Call Workflow Service </a>node with three columns of type double and one column of type SVG image. In general, when calling workflow services, you can pass and receive data in any port/data type supported in KNIME Analytics Platform.</p><p>The configuration of the <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.knime.caller2.CallWorkflow2NodeFactory/">Call Workflow Service</a> node is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*6XHuvH-7agP1wtZ6uae3Ag.png" /><figcaption>Figure 3. The configuration dialog of the Call Workflow Service node.</figcaption></figure><p>The Workflow path section defines the path (local/remote) to the callee workflow. Below that, you can assign the input/output ports of the node to the input/output parameters of the callee workflow. In the bottom right corner, you can click the “Adjust node ports” button to adjust the ports of the Call Workflow Service node automatically according to the configured callee workflow.</p><p>So far, data was exchanged between two workflows only. In the next section, I show how to exchange data between workflows and external tools, too.</p><h4>Orchestration with KNIME and External Tools: REST Services</h4><p>To expose a callee workflow as a REST service, it needs to contain a Container Input and/or Container Output node. The exact node depends on the expected input and output formats of the REST service. For example, <a href="https://hub.knime.com/knime/extensions/org.knime.features.json/latest/org.knime.json.node.input.JSONInputNodeFactory/">Container Input (JSON)</a> node takes in a custom JSON value, <a href="https://hub.knime.com/knime/extensions/org.knime.features.json/latest/org.knime.json.node.container.input.row.ContainerRowInputNodeFactory/">Container Input (Row)</a> a JSON value in a predefined format, and <a href="https://hub.knime.com/knime/extensions/org.knime.features.json/latest/org.knime.json.node.container.input.variable2.ContainerVariableInputNodeFactory2/">Container Input (Variable) </a>a flow variable value. All workflows containing Container Input/Output nodes are RESTful when deployed to KNIME Server/Business Hub.</p><p>The caller workflow communicates with the workflow’s REST API. You can check the input and output expected from an external client using, for example, <a href="https://www.postman.com/">Postman API Platform</a>. Or, if you want to access the workflow’s REST API from a KNIME workflow, too, you can use the Call Workflow nodes. The <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.json.row.caller3.CallWorkflowRowBased3NodeFactory/">Call Workflow (Row Based) </a>node accesses and provides a JSON column and works with most of the Container Input/Output nodes. The <a href="https://hub.knime.com/knime/extensions/org.knime.features.personalproductivity/latest/org.knime.workflowservices.json.table.caller2.CallWorkflowTable2NodeFactory/">Call Workflow (Table Based) </a>node accesses and provides a data table and works with the Container Input/Output (Table), Container Input (Variable), and Container Input (Credentials) nodes only.</p><p>The table below summarizes the nodes for creating and calling KNIME workflows as REST services and combining them appropriately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*n-oRtMUHdFyLA2ncOpyZCQ.png" /><figcaption>Table 1. Summary of the workflow invocation nodes.</figcaption></figure><p>The table shows how to combine the Caller and Input/Output nodes introduced in this blog post and describes their purpose. There are also Input/Output nodes that take in a file or raw HTTP and are only used in REST services exposed to external tools. For a more comprehensive list of the workflow invocation nodes and their usage, check the <a href="https://docs.knime.com/latest/analytics_platform_workflow_invocation_guide/index.html#introduction">KNIME Workflow Invocation Guide </a>.</p><h4>Turn Callee Workflow into a REST Service</h4><p>The callee workflow (Figure 4 below) contains the Statistics node, the Container Input (JSON), and Container Output (JSON) nodes. In addition, it contains the JSON path, Ungroup, and Table to JSON nodes to format the input column from and to a JSON value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2RZOAYpoppCGQrmMmV-k0w.png" /><figcaption>Figure 4. An example of a workflow as a REST service. <em>Download the </em><a href="https://hub.knime.com/-/spaces/-/latest/~OKqPz1oeQ4RZTrPE/"><em>example callee (row based) </em></a><em>workflow from the KNIME Community Hub.</em></figcaption></figure><p>This workflow, once uploaded to KNIME Server, could now return the distribution statistics to any client calling it via REST. Figure 4 also shows the configuration of the Container Input (JSON) node. There you can define the parameter name and the default JSON value, which is used when the workflow is executed without input.</p><p>If you want to call the workflow from a KNIME workflow, too, I show you how to do that in the section below.</p><h4>Call Workflow as a REST Service</h4><p>The workflow (Figure 5) calling the REST service contains the CSV Reader and Column Filter nodes to access and filter the data, similar to the call workflow service example workflow shown in Figure 2. In addition, it converts the table column into JSON and back with the Table to JSON and JSON to Table nodes. And most importantly, it calls the distribution statistics via REST with the Space Connector and Call Workflow (Row Based) nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1dpBK6sa49XyvmT7eYfJg.png" /><figcaption>Figure 5. An example workflow that calls a workflow as a REST service. <em>Download the </em><a href="https://hub.knime.com/-/spaces/-/latest/~l8JKw7OWF60SD4e9/"><em>call REST service example </em></a><em>workflow from the KNIME Community Hub.</em></figcaption></figure><p>In Figure 5, you can also see the input and output in JSON columns. Because the REST service is a workflow deployed to <a href="https://www.knime.com/knime-business-hub?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Business Hub</a>, the Call Workflow (Row Based) node needs to access that connection provided by the Space Connector node.</p><h3>Now Try More Advanced Workflow Orchestration</h3><p>In this blog post, I have introduced the concept of orchestration and listed its benefits. I guided you through the workflow invocation nodes in KNIME Analytics Platform and shown how to create and call workflows and REST services. I have explained what types of inputs and outputs you can provide to which caller and input/output nodes and summarized which nodes you can combine in applications.</p><p>I hope I have helped you overcome the “tricky beginning” and you can now move on to orchestrating your real applications. If you want to try out a more complicated example of orchestration, <a href="https://hub.knime.com/hayasaka/spaces/KNIME%20Fall%20Summit%20Training%202022/latest/L3-WP%20Productionizing%20Data%20Apps/Session%204%20-%20Orchestration/00.Orchestration%20-%20Exercise~GoKZkL0MIGPItmLz">this exercise </a>on the KNIME Hub guides you through that. The exercise is a part of the L3-DA Productionizing Data Apps <a href="https://www.knime.com/knime-courses">course</a>.</p><p>— — — — -</p><p>As previously published on the KNIME Blog: <a href="https://www.knime.com/blog/call-workflow-service-REST">https://www.knime.com/blog/call-workflow-service-REST</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=229144dffb33" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/how-to-create-workflow-rest-services-with-knime-229144dffb33">How to Create Workflow &amp; REST Services with KNIME</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Certify Your KNIME Time Series Analysis Expertise]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/certify-your-knime-time-series-analysis-expertise-31e9552cdd26?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/31e9552cdd26</guid>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[getting-started]]></category>
            <category><![CDATA[knime]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Fri, 23 Jun 2023 07:32:30 GMT</pubDate>
            <atom:updated>2023-06-23T07:32:30.058Z</atom:updated>
            <content:encoded><![CDATA[<h4>GETTING STARTED | TIME SERIES ANALYSIS | KNIME ANALYTICS PLATFORM</h4><h4>The new KNIME L4-TS Certification Exam</h4><p><em>Co-author: </em><a href="https://www.linkedin.com/in/danieletonini/"><em>Daniele Tonini</em></a></p><p>You can now certify yourself as a KNIME Data Scientist with a specialization in Time Series Analysis with the newly launched L4-TS Certification Exam.</p><figure><img alt="Certify your Time Series Analysis Expertise" src="https://cdn-images-1.medium.com/proxy/0*PrgRsKFQYcjsILM9" /><figcaption>Fig. 1. The Time Series Analysis badge you are awarded with after successfully completing the certification exam.</figcaption></figure><p>The exam was created by Daniele Tonini (Academic Fellow at Bocconi University) and Maarit Widmann (QA Manager, KNIME) who are the authors of the <a href="https://forum.knime.com/t/online-course-l4-ts-introduction-to-time-series-analysis/25327">L4-TS Introduction to Time Series Analysis </a>course and the <a href="https://www.knime.com/codeless-time-series-analysis-with-knime?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">Codeless Time Series Analysis with KNIME</a> book. The exam questions are aligned with the following topics introduced in the course:</p><ul><li>Properties of Time Series</li><li>Goals of Time Series Analysis</li><li>KNIME Time Series Integration</li><li>Descriptive Analytics Methods</li><li>Steps in a Forecasting Application</li><li>Forecasting Techniques</li></ul><p>The <strong>65-minute exam</strong> consists of <strong>45 questions</strong>. The exam costs<strong> $150</strong> but we are offering early examinees the chance to take the exam for free using the <strong>promo code L4-TS-NEW</strong>, which is valid until the <strong>end of July 2023</strong> (see more details below).</p><p>The L4-TS Certification Exam completes the learning path for a Data Scientist specialized in Time Series Analysis. You are then awarded with a learning path badge (fig. 2), which you can share in social media in the same way as the certification badges.</p><figure><img alt="Time series analysis learning path badge" src="https://cdn-images-1.medium.com/proxy/0*76_2NtsRIqJEwzWf" /><figcaption>Fig. 2. The badge you receive after you’ve completed the Time Series Analysis learning path.</figcaption></figure><p>Holders of the certification badge will have certified themselves on fours levels of proficiency: KNIME Analytics Platform (L1 and L2), KNIME Software for Collaboration and Productionizing of Data Science (L3), and finally, the time series functionalities of KNIME and the theory of time series analysis (L4).</p><h3>Specialize in Time Series Analysis</h3><p>It’s “crucial for a business analyst/data scientist to have an understanding of how to approach time series analysis in a practical way […] because this will impact many applications that you can develop for your company”, said <a href="https://partnerships.packt.com/interview-with-daniele-tonini/">Prof. Daniele Tonini in an interview</a>.</p><p>Time series refers to a temporal evolution of some phenomenon. The closing price of a stock, temperature, or the sales of a product are just a few examples of common sources of time series data. Time series data reports the evolution of what happened in several points in the past and is thus different from cross-sectional data that contain only one snapshot of history.</p><p>Understanding the temporal evolution in the past is needed for the most common goal of time series analysis: predicting the future. For this, we can apply techniques of descriptive analysis and forecasting that identify and employ characteristics that act over time. Such characteristics are, for example, trend, periodic fluctuations, anomalies and turning points.</p><p>Time series analysis techniques are based on the characteristics of the time series itself only or they can also take the advantage of external variables. Some of the techniques are specific to time series analysis, also known as “classical methods”, while others are machine learning algorithms used across different data science fields.</p><p>For collection, understanding, and modeling of time series data, you can find relevant use cases in all types of industries: business, environmental science, industrial production, medicine, and more. Among these application areas, time series analysis is used to effectively allocate effort and resources, predict the breakdown of a machine, control and <a href="https://www.knime.com/blog/how-a-social-scientist-investigated-global-emissions">even save emissions</a>.</p><p>If that’s your specialty or interest, then the exam is right for you! Let’s check next how you can prepare for the exam.</p><h3>How to Prepare for the Exam</h3><p>We recommend joining the L4-TS Introduction to Time Series Analysis course. The course will be instructed next time on September 11–15, 2023.</p><p>Before that, we offer the following materials for preparation:</p><ul><li>Codeless Time Series Analysis (e-)Book. Purchase on <a href="https://www.amazon.com/Codeless-Time-analysis-KNIME-implementing-ebook/dp/B0B2PT759P/">Amazon</a>. Studying the book suffices to pass the certification exam and gives you insights into more advanced time series analysis techniques, too.</li><li>Recording of Time Series Analysis Workshop on <a href="https://youtu.be/3rRQIbDChvM">KNIMETV</a>. Summary of the L4-TS Introduction to Time Series course. This recording is good for recapping the relevant topics but doesn’t fully prepare you for the certification exam.</li></ul><p>Are you ready to become a certified KNIME Data Scientist in the specialty of Time Series Analysis? Follow the steps listed below.</p><h3>How to Take the Exam</h3><p>You can find and enroll in the exam via the website of the <a href="https://www.knime.com/certification-program?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Certification Program</a>. For early examinees like you, when you register, you can enter the promotional code <strong>L4-TS-NEW </strong>to take the exam for free until the end of July, 2023.</p><p>Note that you’ll need to have passed the following upstream certifications of the learning path before you can take any L4 certification exam:</p><p>Note that you’ll need to have passed the following upstream certifications of the learning path before you can take any L4 certification exam:</p><ul><li>L1: Basic Proficiency in KNIME Analytics Platform</li><li>L2: Advanced Proficiency in KNIME Analytics Platform</li><li>L3-PC: Proficiency in KNIME Software for Collaboration and Productionizing of Data Science</li></ul><p>If you didn’t pass these yet, now it’s time for that. You can then complete your specialist profile together with the next time series instructor-led course in September, 2023.</p><p>— — — — -</p><p>As first published on the KNIME Blog: <a href="https://www.knime.com/blog/certify-time-series-analysis-expertise?&amp;">https://www.knime.com/blog/certify-time-series-analysis-expertise</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31e9552cdd26" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/certify-your-knime-time-series-analysis-expertise-31e9552cdd26">Certify Your KNIME Time Series Analysis Expertise</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate synthetic data to teach machine learning]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/generate-synthetic-data-to-teach-machine-learning-446b3172c4b1?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/446b3172c4b1</guid>
            <category><![CDATA[synthetic-data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[knime]]></category>
            <category><![CDATA[theory]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Mon, 05 Jun 2023 05:58:53 GMT</pubDate>
            <atom:updated>2023-06-12T11:47:28.828Z</atom:updated>
            <content:encoded><![CDATA[<h4>DATA SCIENCE THEORY | SYNTHETIC DATA | KNIME ANALYTICS PLATFORM</h4><h4>Use KNIME Verified components for ease of reusability and sharing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g4-zb6JtMjNk_bgP" /><figcaption>Photo by <a href="https://unsplash.com/@askkell?utm_source=medium&amp;utm_medium=referral">Andy Kelly</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>As an instructor, you’ll know just how much exercises contribute to a student’s understanding of a topic. But coming up with an instructive and interesting exercise is difficult. The concepts your students are learning vary, they require different kinds of datasets, and the datasets need to be simple enough to allow the student to focus on the task at hand.</p><p>For our own self-paced machine learning course, we came up with a novel solution. Instead of searching, filtering, and transforming real-world datasets, we are generating synthetic datasets. Using these synthetic datasets it is easier to design hands-on exercises for our students to test their knowledge of machine learning algorithms.</p><h3>How can synthetic data help you teach machine learning?</h3><p>Using synthetic data instead of real-world data as a base for practical exercises gives us the following benefits:</p><h4><strong>No excessive volume of exercise data</strong></h4><p>Real-world datasets contain all the types of properties students need to learn about in order to apply the best techniques to deal with them — redundant features, duplicate features, linearly correlated features, and so on. But they might be too large to share and redundant to carry through all exercises of your course.</p><p>With synthetically generated datasets, we can work with compact data that only contains the required number of columns and rows. And we can always rename the columns and create a story around the generated data if we want to make the exercises more engaging.</p><h4><strong>Customize the features of the dataset</strong></h4><p>Many popular datasets for machine learning exercises, such as the <a href="https://www.kaggle.com/datasets/wenruliu/adult-income-dataset">adult dataset</a>, are able to demonstrate one algorithm, the decision tree for example, but lack features to demonstrate other algorithms, the linear regression for example.</p><p>With synthetic data, we can construct the features just as we need, allowing us to demonstrate each algorithm effectively.</p><h4><strong>Generate characteristics that are implicit in real-world data</strong></h4><p>Some characteristics of the data affect how the algorithms perform. At the same time, they are difficult to find in real-world data. For example, knowing whether the classes are linearly separable in the feature space and finding a dataset to demonstrate that might require excessive data exploration. However, this characteristic makes a difference in the performance of two classification algorithms: the logistic regression and the decision tree.</p><p>When we generate synthetic data, we can ensure that the characteristics of the data enable our students to learn to consider which algorithm will perform best.</p><h3>How to generate synthetic data with KNIME verified components?</h3><p>Below we list four KNIME verified components that teachers can use to generate synthetic data and demonstrate classification tasks.</p><ul><li><a href="https://kni.me/c/WsczwfVd2qtrT0ct">Synthetic Data Generator (Classification)</a></li><li><a href="https://kni.me/c/fGEUTTvaVcfB8kdL">Synthetic Data Generator (Regression)</a></li><li><a href="https://kni.me/c/RJgsdfeFyHAdZBT-">Synthetic Data Generator (Multilabel Classification)</a></li><li><a href="https://kni.me/c/W0VlWyiBGPXUD2Em">Synthetic Data Generator (Clustering)</a></li></ul><p>Each component’s functionality is based on the Python <a href="https://scikit-learn.org/">scikit-learn</a> library, yet all the settings for the data generation are defined in the component’s configuration dialog.</p><p>As an example, let’s see how to use the Synthetic Data Generator (Classification) component and generate data for classification. With this data we’ll be able to demonstrate that the logistic regression and decision tree algorithms perform differently.</p><p>In our <a href="https://www.knime.com/knime-self-paced-courses#L4">L4-ML</a> course, we teach students that the decision tree algorithm performs better if the decision boundary is non-linear (left side in figure 3 below), whereas the logistic regression algorithm performs better if the decision boundary is linear (right side in the figure below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*N76bSjR-6tPOT1sep8nyCQ.png" /><figcaption>Figure 1. Demonstrating linearly separable (on the right) and non-separable (on the left) classes in the feature space.</figcaption></figure><p>We want to replicate the scenario illustrated in Figure 1 in synthetic data. We can do so by regulating the class separation parameter in the <a href="https://kni.me/c/WsczwfVd2qtrT0ct">Synthetic Data Generator (Classification)</a> component. Figure 2 below shows the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QzEJZp9RLf20lP-vh_nKLw.png" /><figcaption>Figure 2. Visualizing generated data for classification with high (on the left) and low (on the right) class separation in the feature space.</figcaption></figure><p>The scatter plot on the left shows the desired output, data with linear class separation. For a reference, the scatter plot on the right shows data with no linear class separation. If you want to compare how the linear regression and decision tree algorithms perform on this generated data, try out the corresponding <a href="https://kni.me/w/6ULEJeVQF2Ue4Ep4">exercise workflow</a> of the course.</p><p>The Class Separation parameter and other settings of the component appear in its configuration dialog shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*-3cOGfgPoWPHWOdF7MCexA.png" /><figcaption>Figure 3. The configuration dialog of the Synthetic Data Generator (Classification) component.</figcaption></figure><p>In the configuration dialog, you can control how many features and samples to generate, how many features should be informative/redundant or duplicates. Besides, you can assign the classes into one or more clusters. As an example, Figure 4 below visualizes two kinds of clustering:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YLemi1yxlTW55d8dyr4Y9g.png" /><figcaption>Figure 4. Demonstrating generated data with one (on the left) and two (on the right) clusters within each class.</figcaption></figure><p>On the left, you can see that the green and red classes are not distributed into separate clusters. On the right, you can see two clusters within both classes.</p><p>Finally, it is also possible to regulate the seed parameter to make the data reproducible in repeated executions of the component.</p><h3>Get started with KNIME data generation components</h3><p>In the same way, by following the steps introduced above, you can generate data for a multinomial classification problem, regression problem, or multilabel classification problem.</p><p>Follow these steps to get started:</p><p>1. Configure Python in KNIME:</p><ul><li>Install Miniconda from <a href="https://www.anaconda.com/distrhttps://docs.conda.io/en/latest/miniconda.htmlibution/">https://docs.conda.io/en/latest/miniconda.html</a></li><li>Install the <a href="https://hub.knime.com/knime/extensions/org.knime.features.python2/latest?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Python Integration</a> (legacy)</li><li>Configure KNIME Preferences under File &gt; Preferences &gt; Python and browse to your Miniconda Installation Directory under Conda</li></ul><blockquote><strong>Note.</strong> From KNIME v4.7 onwards, <a href="https://hub.knime.com/knime/extensions/org.knime.features.python3.scripting/latest/?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Python Integration</a> comes with a bundled environment with the scikit-learn and other basic packages pre-installed, and you don’t need to install, configure or know anything around Python. However, the data generation components were created before that and require the manual installation of Conda instructed above. See this <a href="https://www.knime.com/blog/python-script-node-bundled-packages">blog post</a> for more information.</blockquote><p>2. Download Franziska’s example workflow demonstrating the functionality of all components. The workflow is available on the KNIME Community Hub (available at <a href="https://kni.me/w/7hWbEYwXtU6bJ-us">https://kni.me/w/7hWbEYwXtU6bJ-us </a>) and shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nEixiEAR4DzeGximDUOY1w.png" /><figcaption>Figure 5. Workflow for generating data for classification, regression, clustering, and multilabel classification tasks. Download the workflow from the KNIME Community Hub : <a href="https://kni.me/w/7hWbEYwXtU6bJ-us">https://kni.me/w/7hWbEYwXtU6bJ-us</a>.</figcaption></figure><p>3. Inspect and re-configure the components as you like!</p><h3>Synthetic data generation for clear demonstration of ML operations</h3><p>Demonstrating machine learning tasks in practice for teaching purposes is a challenge. Different algorithms require different properties of the data; introducing them all at once expands the exercise data into unwieldy dimensions.</p><p>Our solution is to generate synthetic data for classification, regression, multilabel classification, and clustering with the <a href="https://www.knime.com/verified-components?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Verified Components</a>. These components generate the data you need fast, in a compact size, and with the properties you’d like to demonstrate.</p><p>— — — — -</p><p>As first published on the KNIME Blog: <a href="https://www.knime.com/blog/generate-synthetic-data-teach-ml">https://www.knime.com/blog/generate-synthetic-data-teach-ml</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=446b3172c4b1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/generate-synthetic-data-to-teach-machine-learning-446b3172c4b1">Generate synthetic data to teach machine learning</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three More Techniques for Data Dimensionality Reduction in ML]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/three-new-techniques-for-data-dimensionality-reduction-in-ml-1378a4fe31a9?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/1378a4fe31a9</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[dimensionality-reduction]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[theory]]></category>
            <category><![CDATA[knime]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Fri, 07 Oct 2022 08:35:29 GMT</pubDate>
            <atom:updated>2022-10-07T08:44:06.957Z</atom:updated>
            <content:encoded><![CDATA[<h4>DATA SCIENCE THEORY | DIMENSIONALITY REDUCTION | KNIME ANALYTICS PLATFORM</h4><h4>Implementing LDA, Neural Autoencoder, and t-SNE in a codeless fashion</h4><p><em>As first published in </em><a href="https://thenewstack.io/3-new-techniques-for-data-dimensionality-reduction-in-machine-learning/"><em>The New Stack</em></a><em>. Co-author: </em><a href="https://www.linkedin.com/in/rosaria/"><em>Rosaria Silipo</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_B2evcCSU-LvijSG" /><figcaption>Photo by <a href="https://unsplash.com/@diana_pole?utm_source=medium&amp;utm_medium=referral">Diana Polekhina</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>The full big data explosion has convinced us that more is better. While it is of course true that a large amount of training data helps the machine learning model to learn more rules and better generalize to new data, it is also true that an indiscriminate addition of low-quality data and input features might introduce too much noise and, at the same time, considerably slow down the training algorithm.</p><p>So, in the presence of a dataset with a very high number of data columns, it is good practice to wonder how many of these data features are actually really informative for the model. A number of techniques for data-dimensionality reduction are available to estimate how informative each column is and, if needed, to skim it off the dataset.</p><p>In “<a href="https://medium.com/low-code-for-advanced-data-science/seven-techniques-for-data-dimensionality-reduction-1fe81d6174da">Seven Techniques for Data Dimensionality Reduction</a>”, we provided a review of the seven most commonly used techniques for data-dimensionality reduction, including:</p><ul><li>Ratio of missing values</li><li>Low variance in the column values</li><li>High correlation between two columns</li><li>Principal component analysis (PCA)</li><li>Candidates and split columns in a Random Forest</li><li>Backward feature elimination</li><li>Forward feature construction</li></ul><p>Those are traditional techniques commonly applied to reduce the dimensionality of a dataset by removing all of the columns that either do not bring much information or no new information. Since then, we have started to use three additional techniques, also quite commonly used, and have decided to add them to the list as well.</p><ol><li><a href="https://en.wikipedia.org/wiki/Linear_discriminant_analysis">Linear discriminant analysis (LDA)</a></li><li><a href="https://youtu.be/FzS3tMl4Nsc">Neural autoencoder</a></li><li><a href="https://en.wikipedia.org/wiki/T-distributed_stochastic_neighbor_embedding">t-distributed stochastic neighbor embedding (t-SNE)</a></li></ol><h3>The Dataset</h3><p>In our first review of data dimensionality reduction techniques, we used the two datasets from the <a href="http://kdd.org/kdd-cup/view/kdd-cup-2009">2009 KDD Challenge </a>— the large dataset and the small dataset. The particularity of the large dataset is its very high dimensionality with 15,000 data columns. Most data mining algorithms are implemented column-wise, which makes them slower and slower as the number of data columns increases. This dataset definitely brings out the slowness of a number of machine learning algorithms.</p><p>The <a href="https://www.kdd.org/kdd-cup/view/kdd-cup-2009">2009 KDD Challenge</a> small dataset is definitely lower dimensional than the large dataset but is still characterized by a considerable number of columns: 230 input features and three possible target features. The number of data rows is the same as in the large dataset: 50,000. In this review, for computational reasons, we will focus on the small dataset to show just how effective the proposed techniques are in reducing dimensionality. The dataset is big enough to prove the point in data-dimensionality reduction and small enough to do so in a reasonable amount of time.</p><p>Let’s proceed now with the (re)implementation and comparison of 10 state-of-the-art dimensionality reduction techniques, all currently available and commonly used in the data analytics landscape.</p><h3>Three More Techniques for Data Dimensionality Reduction</h3><p>Let’s implement the three newly added techniques:</p><ol><li>Linear Discriminant Analysis (LDA)</li><li>Neural autoencoder</li><li>t-distributed Stochastic Neighbor Embedding (t-SNE)</li></ol><h4>Linear Discriminant Analysis (LDA)</h4><p>A number <em>m </em>of linear combinations (discriminant functions) of the <em>n </em>input features, with <em>m &lt; n </em>, are produced to be uncorrelated and to maximize class separation. These discriminant functions become the new basis for the dataset. All numeric columns in the dataset are projected onto these linear discriminant functions, effectively moving the dataset from the <em>n</em>-dimensionality to the <em>m</em>-dimensionality.</p><p>In order to apply the LDA technique for dimensionality reduction, the target column has to be selected first. The maximum number of reduced dimensions <em>m</em> is the number of classes in the target column minus one, or if smaller, the number <em>n </em>of numeric columns in the data. Notice that linear discriminant analysis assumes that the target classes follow a multivariate normal distribution with the same variance <a href="https://en.wikipedia.org/wiki/Linear_discriminant_analysis">but with a different mean for each class</a>.</p><h4>Autoencoder</h4><p>An <a href="https://kni.me/w/gW4nBo8ylCMIeP0D">autoencoder</a> is a neural network, with as many output units (<em>n</em>) as input units, at least one hidden layer with <em>m</em> units where <em>m &lt; n</em>, and trained with the <a href="https://kni.me/w/gW4nBo8ylCMIeP0D">backpropagation algorithm</a> to reproduce the input vector onto the output layer. It reduces the numeric columns in the data by using the output of the hidden layer to represent the input vector.</p><p>The first part of the autoencoder — from the input layer to the hidden layer of <em>m </em>units — is called the encoder. It compresses the <em>n </em>dimensions of the input dataset into an <em>m</em>-dimensional space. The second part of the autoencoder — from the hidden layer to the output layer — is known as the decoder. The decoder expands the data vector from an <em>m</em>-dimensional space into the original <em>n</em>-dimensional dataset and brings the data back to their original values.</p><h4>t-distributed Stochastic Neighbor Embedding (t-SNE)</h4><p>This technique reduces the <em>n</em> numeric columns in the dataset to fewer dimensions <em>m</em> (<em>m &lt; n</em>) based on nonlinear local relationships among the data points. Specifically, it models each high-dimensional object by a two- or three-dimensional point in such a way that similar objects are modeled by nearby points and dissimilar objects are modeled by distant points in the new lower dimensional space.</p><p>In the first step, the data points are modeled through a multivariate normal distribution of the numeric columns. In the second step, this distribution is replaced by a lower dimensional t-distribution, which follows the original multivariate normal distribution as closely as possible. The t-distribution gives the probability of picking another point in the dataset as a neighbor to the current point in the lower dimensional space. The perplexity parameter controls the density of the data as the “effective number of neighbors for any point.” The greater the value of the perplexity, the more global structure is considered in the data. The t-SNE technique works only on the current dataset. It is not possible to export the model to apply it to new data.</p><h3>Comparison in Terms of Accuracy and Reduction Rate</h3><p>We implemented all 10 described techniques for dimensionality reduction (described in “<a href="https://medium.com/low-code-for-advanced-data-science/seven-techniques-for-data-dimensionality-reduction-1fe81d6174da">Seven Techniques for Data Dimensionality Reduction</a>” and in this article), applying them to the small dataset of the <a href="https://www.kdd.org/kdd-cup/view/kdd-cup-2009">2009 KDD Cup </a>corpus. Finally, we compared them in terms of reduction ratio and classification accuracy. For dimensionality reduction techniques that are based on a threshold, the optimal threshold was selected by an optimization loop.</p><p>For some techniques, final accuracy and degradation depend on the selected classification model. Therefore, the classification model is chosen from a bag of three basic models as the best-performing model:</p><ul><li>Multilayer feedforward neural networks</li><li>Naive Bayes</li><li>Decision tree</li></ul><p>For such techniques, the final accuracy is obtained by applying all three classification models to the reduced dataset and adopting the one that performs best.</p><p>Overall accuracy and area under the curve (AUC) statistics are reported for all techniques in Table 1. We compare these statistics with the performance of the baseline algorithm that uses all columns for classification.</p><figure><img alt="Seven plus three Techniques for Dimensionality Reduction" src="https://cdn-images-1.medium.com/max/1024/0*EL_oooVcPbygCx3o.png" /><figcaption>Table 1: Number of input columns, reduction rate, overall accuracy, and AuC value for the 7 + 3 dimensionality reduction techniques based on the best classification model trained on the KDD challenge 2009 small dataset.</figcaption></figure><p>A graphical comparison of the accuracy of each reduction technique is shown in Figure 1 below. Here all reduction techniques are reported on the x-axis and the corresponding classification accuracy on the y-axis, as obtained from the best-performing model of the three basic models proposed above.</p><figure><img alt="Three new techniques for data dimensionality reduction" src="https://cdn-images-1.medium.com/max/840/0*zZxwlfpanm1KLHdC.png" /><figcaption>Fig. 1. Accuracies of the best performing models trained on the datasets that were reduced using the 10 selected data dimensionality reduction techniques.</figcaption></figure><p>The receiver operating characteristic (ROC) curves in Figure 2 show a group of best-performing techniques: missing value ratio, high correlation filter and the ensemble tree methods.</p><figure><img alt="Seven plus Three Techniques for Dimensionality Reduction" src="https://cdn-images-1.medium.com/max/1008/0*hWaU3RAd2qBlDDoG.png" /><figcaption>Fig. 2: ROC Curves showing the performances of the best classification model trained on the reduced datasets: each dataset was reduced by a different dimensionality reduction technique.</figcaption></figure><h4>Implementation of the 7+3 Techniques</h4><p>The workflow that implements and compares the 10 dimensionality reduction techniques described in this review is shown in Figure 3. In the workflow, we see 10 parallel branches plus one at the top. Each one of the 10 parallel lower branches implements one of the described techniques for data-dimensionality reduction. The first branch, however, trains the bag of classification models on the whole original dataset with 230 input features.</p><p>Each workflow branch produces the overall accuracy and the probabilities for the positive class by the best-performing classification model trained on the reduced dataset. Finally, the positive class probabilities and actual target class values are used to build the ROC curves, and a bar chart visualizes the accuracies produced by the best-performing classification model for each dataset.</p><p>You can inspect and download the workflow from the <a href="https://kni.me/w/7PBv1kGifxCng2qo">KNIME Hub</a>.</p><figure><img alt="Seven plus Three Techniques for Dimensionality Reduction" src="https://cdn-images-1.medium.com/max/836/0*1-oUY-v-AWD2RbYA.png" /><figcaption>Fig. 3: Implementation of the ten selected dimensionality reduction techniques. Each branch of this workflow outputs the overall accuracy and positive class probabilities produced by the best-performing classification model. An ROC Curve and bar chart then compare the performance of the classification models trained on the reduced datasets. The workflow can be downloaded and inspected from <a href="https://kni.me/w/7PBv1kGifxCng2qo">the KNIME Hub</a>.</figcaption></figure><h3>Summary and Conclusions</h3><p>In this article, we have presented a review of ten popular techniques for data dimensionality reduction. We have actually expanded a previous existing article describing seven of them (ratio of missing values, low variance in the values of a column, high correlation between two columns, principal component analysis (PCA), candidates and split columns in a Random Forest, backward feature elimination, forward feature construction) by adding three additional techniques.</p><p>We trained a few basic machine learning models on the reduced datasets and compared the best-performing ones with each other via reduction rate, accuracy and area under the curve.</p><p>Notice that dimensionality reduction is not only useful to speed up algorithm execution but also to improve model performance.</p><p>In terms of overall accuracy and reduction rate, the Random Forest based technique proved to be the most effective in removing uninteresting columns and retaining most of the information for the classification task at hand. Of course, the evaluation, reduction and consequent ranking of the ten described techniques are applied here to a classification problem; we cannot generalize to effective dimensionality reduction for numerical prediction or even visualization.</p><p>Some of the techniques used in this article are complex and computationally expensive. However, as the results show, even just counting the number of missing values, measuring the column variance and the correlation of pairs of columns — and combining them with more sophisticated methods — can lead to a satisfactory reduction rate while keeping performance unaltered with respect to the baseline models.</p><p>Indeed, in the era of big data, when more is axiomatically better, we have rediscovered that too many noisy or even faulty input data columns often lead to unsatisfactory model performance. Removing uninformative — or even worse — misinformative input columns might help to train a machine learning model on more general data regions, with more general classification rules, and overall with better performances on new, unseen data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1378a4fe31a9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/three-new-techniques-for-data-dimensionality-reduction-in-ml-1378a4fe31a9">Three More Techniques for Data Dimensionality Reduction in ML</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seven Techniques for Data Dimensionality Reduction]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/seven-techniques-for-data-dimensionality-reduction-1fe81d6174da?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fe81d6174da</guid>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[knime]]></category>
            <category><![CDATA[theory]]></category>
            <category><![CDATA[principal-component]]></category>
            <category><![CDATA[dimensionality-reduction]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Fri, 30 Sep 2022 06:25:03 GMT</pubDate>
            <atom:updated>2022-09-30T06:25:03.692Z</atom:updated>
            <content:encoded><![CDATA[<h4>DATA SCIENCE THEORY | DIMENSIONALITY REDUCTION | KNIME ANALYTICS PLATFORM</h4><h4>A codeless KNIME solution to work with datasets with thousands of columns</h4><p><em>Co-author: </em><a href="https://www.linkedin.com/in/rosaria/"><em>Rosaria Silipo</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WpO3zs2SKavxuJip" /><figcaption>Photo by <a href="https://unsplash.com/@johnschno?utm_source=medium&amp;utm_medium=referral">John Schnobrich</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>The recent explosion of data set size, in number of records and attributes, has triggered the development of a number of big data platforms as well as parallel data analytics algorithms. At the same time though, it has pushed for the usage of data dimensionality reduction procedures. Indeed, more is not always better. Large amounts of data might sometimes produce worse performances in data analytics applications.</p><p>One of our most recent projects happened to be about churn prediction and to use the <a href="http://kdd.org/kdd-cup/view/kdd-cup-2009">2009 KDD Challenge</a> large data set. The particularity of this data set consists of its very high dimensionality with 15K data columns. Most data mining algorithms are column-wise implemented, which makes them slower and slower on a growing number of data columns. The first milestone of the project was then to reduce the number of columns in the data set and lose the smallest amount of information possible at the same time.</p><p>Using the project as an excuse, we started exploring the state-of-the-art on dimensionality reduction techniques currently available and accepted in the data analytics landscape.</p><ul><li><strong>Missing Values Ratio</strong>. Data columns with too many missing values are unlikely to carry much useful information. Thus data columns with a number of missing values greater than a given threshold can be removed. The higher the threshold, the more aggressive the reduction.</li><li><strong>Low Variance Filter</strong>. Similarly to the previous technique, data columns with little changes in the data carry little information. Thus all data columns with variance lower than a given threshold are removed. A word of caution: variance is range dependent; therefore normalization is required before applying this technique.</li><li><strong>High Correlation Filter</strong>. Data columns with very similar trends are also likely to carry very similar information. In this case, only one of them will suffice to feed the machine learning model. Here we calculate the correlation coefficient between numerical columns and between nominal columns as the <a href="http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient">Pearson’s Product Moment Coefficient</a> and the <a href="http://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test">Pearson’s chi square value</a> respectively. Pairs of columns with correlation coefficient higher than a threshold are reduced to only one. A word of caution: correlation is scale sensitive; therefore column normalization is required for a meaningful correlation comparison.</li><li><strong>Random Forests / Ensemble Trees</strong>. Decision Tree Ensembles, also referred to as Random Forests, are useful for feature selection in addition to being effective classifiers. One approach to dimensionality reduction is to generate a large and carefully constructed set of trees against a target attribute and then use each attribute’s usage statistics to find the most informative subset of features. Specifically, we can generate a large set (2000) of very shallow trees (2 levels), with each tree being trained on a small fraction (3) of the total number of attributes. If an attribute is often selected as the best split, it is most likely an informative feature to retain. A score calculated on the attribute usage statistics in the Random Forest tells us ‒ relative to the other attributes ‒ which are the most predictive attributes.</li><li><strong>Principal Component Analysis (PCA)</strong>. <a href="http://en.wikipedia.org/wiki/Principal_component_analysis">Principal Component Analysis (PCA) </a>is a statistical procedure that orthogonally transforms the original <em>n </em>coordinates of a data set into a new set of <em>n </em>coordinates called principal components. As a result of the transformation, the first principal component has the largest possible <a href="http://en.wikipedia.org/wiki/Variance">variance</a>; each succeeding component has the highest possible variance under the constraint that it is <a href="http://en.wikipedia.org/wiki/Orthogonal">orthogonal</a> to (i.e., uncorrelated with) the preceding components. Keeping only the first <em>m &lt; n </em>components reduces the data dimensionality while retaining most of the data information, i.e. the variation in the data. Notice that the PCA transformation is sensitive to the relative scaling of the original variables. Data column ranges need to be normalized before applying PCA. Also notice that the new coordinates (PCs) are not real system-produced variables anymore. Applying PCA to your data set loses its interpretability. If interpretability of the results is important for your analysis, PCA is not the transformation for your project.</li><li><strong>Backward Feature Elimination</strong>. In this technique, at a given iteration, the selected classification algorithm is trained on <em>n </em>input features. Then we remove one input feature at a time and train the same model on <em>n-1 </em>input features <em>n </em>times. The input feature whose removal has produced the smallest increase in the error rate is removed, leaving us with <em>n-1 </em>input features. The classification is then repeated using <em>n-2 </em>features, and so on. Each iteration <em>k </em>produces a model trained on <em>n-k </em>features and an error rate <em>e(k). </em>Selecting the maximum tolerable error rate, we define the smallest number of features necessary to reach that classification performance with the selected machine learning algorithm.</li><li><strong>Forward Feature Construction</strong>. This is the inverse process to the Backward Feature Elimination. We start with 1 feature only, progressively adding 1 feature at a time, i.e. the feature that produces the highest increase in performance. Both algorithms, Backward Feature Elimination and Forward Feature Construction, are quite time and computationally expensive. They are practically only applicable to a data set with an already relatively low number of input columns.</li></ul><p>We picked this chance to compare those techniques on the smaller data set of the 2009 KDD challenge in terms of reduction ratio, degrading accuracy, and speed. The final accuracy and its degradation depend, of course, on the model selected for the analysis. Thus, the compromise between reduction ratio and final accuracy is optimized against a bag of three specific models: decision tree, neural networks, and naïve Bayes.</p><p>Running the optimization loop, the best cutoffs, in terms of lowest number of columns and best accuracy, were determined for each one of the seven dimensionality reduction techniques and for the best performing model. The final best model performance, as overall accuracy and Area under the ROC Curve, was compared with the performance of the baseline algorithm using all input features. Results of this comparison are reported in the table below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*uv4eTdlLMZoFugtcrklK3g.png" /><figcaption>Table 1. The comparison of different dimensionality reduction techniques in terms of reduction rate and classification accuracy.</figcaption></figure><p>Notice that the highest reduction ratio without performance degradation is obtained by analyzing the decision cuts in many Random Forests (Random Forests/Ensemble Trees). However, even just counting the number of missing values, measuring the column variance, and measuring the correlation of pairs of columns can lead to a satisfactory reduction rate while keeping performance unaltered with respect to the baseline models.</p><p>What we have learned from this little review exercise, is that dimensionality reduction is not only useful to speed up algorithm execution, but also to improve model performance. The Area under the Curve (AuC) in the table shows a slight increase on the test data, when the missing value ratio, the low variance filter, the high correlation filter criteria, or the Random Forests are applied.</p><p>Indeed, in the era of big data, when more is axiomatically better, we have re-discovered that too many noisy or even faulty input data columns often lead to a less than desirable algorithm performance. Removing un-informative or even worse dis-informative input attributes might help build a model on more extensive data regions, with more general classification rules, and overall with better performances on new unseen data.</p><p>Recently, we asked data analysts on a LinkedIn group for the most used dimensionality reduction techniques, besides the seven described in this blog post. The answers involved Random Projections, NMF, (Stacked) Auto-encoders, Chi-square or Information Gain, Multidimensional Scaling, Correspondence Analysis, Factor Analysis, Clustering, and Bayesian Models. Thanks to <strong>Asterios Stergioudis, Raoul Savos, and Michael Will who provided the suggestions on the LinkedIn group.</strong></p><p>Following that, we implemented 3 more techniques — t-distributed Stochastic Neighbor Embedding (t-SNE), Autoencoder, and Linear Discriminant Analysis (LDA). They are described in a second part of this article, which was published on <a href="https://thenewstack.io/3-new-techniques-for-data-dimensionality-reduction-in-machine-learning/">The New Stack</a>.</p><p>The altogether 10 dimensionality reduction techniques described in these articles are implemented in one workflow shown below, available on the <a href="https://kni.me/s/N5EJ6HlVYYfjPqLg">KNIME Hub</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/0*EdzDpCbXoSIjydkn.png" /><figcaption>Figure 1. A KNIME workflow implementing different dimensionality reduction techniques and comparing their performances and reduction rates.</figcaption></figure><p>Both small and large data sets from the 2009 KDD Challenge can be downloaded from <a href="http://kdd.org/kdd-cup/view/kdd-cup-2009/Data">http://kdd.org/kdd-cup/view/kdd-cup-2009/Data</a>.</p><p>Below are the ROC curves for all the evaluated dimensionality reduction techniques and the best performing machine learning algorithm. The value of the area under the curve is shown in the legend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/0*lJ4ylX_B2ndsxVWR.png" /><figcaption>Figure 2. The ROC curves after reducing the dimensions in the training data via different dimensionality reduction techniques.</figcaption></figure><h3>Summary</h3><p>In this article, we have defined seven dimensionality reduction techniques that you can use to improve the speed and performance when training machine learning models on high-dimensional data.</p><p>We have also introduced a <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME</a> workflow that implements them and compares them in terms of the reduction rate and performance when trained on three different classification algorithms. You can download the workflow from the <a href="https://kni.me/s/N5EJ6HlVYYfjPqLg">KNIME Hub</a>.</p><p>Beyond this overview article, we describe the tiny details of implementing the techniques in a <a href="https://www.knime.com/sites/default/files/inline-images/knime_seventechniquesdatadimreduction.pdf">related whitepaper</a>.</p><p>— — — — -</p><p>As first published on the KNIME Blog: <a href="https://www.knime.com/blog/seven-techniques-for-data-dimensionality-reduction">https://www.knime.com/blog/seven-techniques-for-data-dimensionality-reduction</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fe81d6174da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/seven-techniques-for-data-dimensionality-reduction-1fe81d6174da">Seven Techniques for Data Dimensionality Reduction</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy Interpretation of a Logistic Regression Model with Delta-p Statistics]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/easy-interpretation-of-a-logistic-regression-model-with-delta-p-statistics-70270c346895?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/70270c346895</guid>
            <category><![CDATA[interpretability]]></category>
            <category><![CDATA[theory]]></category>
            <category><![CDATA[knime]]></category>
            <category><![CDATA[logistic-regression]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Fri, 15 Jul 2022 07:49:01 GMT</pubDate>
            <atom:updated>2022-07-15T07:49:01.935Z</atom:updated>
            <content:encoded><![CDATA[<h4>DATA SCIENCE THEORY | LOGISTIC REGRESSION | KNIME ANALYTICS PLATFORM</h4><h4>Understand and assess easily the individual effects that make a credit application succeed or fail</h4><p><em>As first published in </em><a href="https://www.infoq.com/articles/logistic-regression-model-with-delta-p-statistics/"><em>InfoQ</em></a><em>. Co-author: </em><a href="https://www.linkedin.com/in/alfredo-roccato-2699094/"><em>Alfredo Roccato</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MmujLlpfquBm8ISH" /><figcaption>Photo by <a href="https://unsplash.com/es/@nypl?utm_source=medium&amp;utm_medium=referral">The New York Public Library</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><h4><strong>Key Takeaways</strong></h4><ul><li>With Delta-p statistics, the predictions based on a logistic regression model are easy to understand by non-technical decision-makers.</li><li>Learn how to calculate the Delta-p statistics based on the coefficients of a logistic regression model for credit application processing.</li><li>Data workflow includes the steps for accessing the raw data to train the logistic regression model and evaluating the effects of individual predictor columns with Delta-p statistics.</li><li>Keep in mind logistic regression might not be the best choice when working with high-dimensional data, with many correlated predictor columns.</li></ul><p>Imagine a situation where a credit customer applies for a credit, the bank collects data about the customer — demographics, existing funds, and so on — and predicts the creditworthiness of the customer with a machine learning model. The customer’s credit application is rejected, but the banker doesn’t know why exactly. Or, a bank wants to advertise their credits, and the target group should be those who eventually can get a credit. But who are they?</p><p>In these kinds of situations, we would prefer a model that is easy to interpret, such as the logistic regression model. Delta-p statistics make interpretation of the coefficients even easier. With Delta-p statistics at hand, the banker doesn’t need a data scientist to be able to inform the customer, for example, that the credit application was rejected because all applicants who apply for credit for educational purposes have a very low chance of getting credit. The decision is justified, the customer is not personally hurt, and he or she might come back in a few years to apply for a mortgage.</p><p>In this article, we explain how to calculate the Delta-p statistics based on the coefficients of a logistic regression model. We demonstrate the process from raw data to model training and model evaluation with a <a href="https://www.knime.com/?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME</a> workflow where each intermediate step has a visual representation. However, the process could be implemented in any tool.</p><h3>Assessing the Effect of a Single Predictor with the Delta-p Statistics</h3><p>We will describe the functioning of the logistic regression model and the interpretation of its coefficients. After that, we will explain how to calculate and interpret the Delta-p statistics based on the coefficients. Finally, we will introduce a real-world example of comparing two predictor columns of a credit scoring model with the Delta-p statistics.</p><h4>Logistic Regression Model</h4><p>When we use the <a href="https://en.wikipedia.org/wiki/Logistic_regression">logistic regression algorithm </a>for classification, we model the probability of the target class, for example, the probability of a bad credit rating, with a <a href="https://en.wikipedia.org/wiki/Logistic_function">logistic function </a>. Let’s say we have a binomial logistic regression model with a target column <em>y</em>, credit rating, with two classes that are represented by 0 (good credit rating) and 1 (bad credit rating). The <a href="https://en.wikipedia.org/wiki/Logit">log odds </a>of the target class (<em>y</em>=1) vs. the reference class (<em>y</em>=0) is a linear combination <em>βx</em> of the predictor columns <em>x</em> (account balance, credit duration, credit purpose, etc.). A logistic function of <em>βx</em> transforms the log odds into a probability of the target class:</p><figure><img alt="Easy Interpretation of a Logistic Regression Model with Delta-p" src="https://cdn-images-1.medium.com/max/619/0*Vl5AdDxt1zLBN9v7.png" /></figure><p>where <em>β </em>is the vector of coefficients for predictor columns <em>x</em> in the logistic regression model that predicts target class <em>y</em>.</p><p>The target and reference classes can be arbitrarily chosen. In our case, the target class is “bad credit rating,” and the reference class is “good credit rating.”</p><h4>Delta-p Statistics</h4><p>If a single predictor column <em>x_i</em> is continuous, the coefficient <em>β_i </em>corresponds to the change in the log odds of the target class when <em>x_i </em>increases by 1. If <em>x_i</em> is a binomial column, the coefficient value <em>β_i</em> is the change in the log odds when <em>x_i</em> changes from 0 to 1. The change in the probability of the target class is provided by the logistic function, as shown in Figure 1.</p><figure><img alt="Easy Interpretation of a Logistic Regression Model with Delta-p" src="https://cdn-images-1.medium.com/max/429/0*Rkdr2trsEGquSo0p.png" /><figcaption>Figure 1. Logistic function modeling the probability of the target class <em>y</em>=1 as a function of one continuous predictor column x_i.</figcaption></figure><p>The Delta-p statistics transforms the coefficient values<em> β_i</em> into percentage effects on the probability of the target class compared to an average data point e.g., an average credit applicant.</p><p>By definition, the Delta-p statistic is a measure of the discrete change in the estimated probability of the occurrence of an outcome given a one-unit change in the independent variable of interest, with all other variables held constant at their mean values. For example, if the Delta-p value of a predictor column <em>x_i</em> is 0.2, then a unit increase in this column (or a change from 0 to 1 in a binomial column) increases the probability of the target class by 20 %. The probabilities before and after the unit increase are called prior and post probabilities, respectively. The following formulas show how to calculate the prior and post probabilities of the target class and, finally, the Delta-p statistics as their difference [1]:</p><figure><img alt="Easy Interpretation of a Logistic Regression Model with Delta-p" src="https://cdn-images-1.medium.com/max/833/0*wfeiKdoEmxJteX2i.png" /></figure><h3>Use Case: The Effect of Credit Purpose and Current Account Balance on Credit Rating</h3><p>Let’s now demonstrate this with an example, and check how the credit purpose and balance of an existing account improve or worsen the credit rating. We use the German credit card data provided by the <a href="https://archive.ics.uci.edu/ml/datasets/statlog+(german+credit+data)">UCI Machine Learning Repository</a>. The dataset contains 21 columns that provide information about demographics and economic conditions of 1,000 credit applicants. Thirty percent of the applicants have a bad credit rating, and 70 % have a good rating. You can download the data in .data format by clicking “Data Folder” at top of the page, and selecting the “german.data” item on the next page. The german.data file can be opened in a text editor and saved, for example, in CSV format. The column names and descriptions of the values in the categorical columns are provided in the german.doc file, accessible via the same page.</p><p>The workflow in Figure 2 shows the process from accessing the raw data to training the logistic regression model and evaluating the effects of individual predictor columns with Delta-p statistics.</p><ul><li><a href="https://kni.me/w/dQwCNoz4SyzPhJdn">Download the workflow, Assessing Effects of Single Predictors with Delta-p from the KNIME Hub here</a></li></ul><p>The process is divided into the following steps, each one implemented within a separate colored box: Accessing data (1), preprocessing data as required by the logistic regression algorithm (2), training the model (3), and calculating the Delta-p statistics based on the model coefficients (4). In the preprocessing step, we convert the target column from the 1/2 notation to “bad”/“good.” We also transform two originally multinomial predictor columns into binomial columns: We encode the “checking” column into two values “negative”/“some funds or no account” based on the status of the existing bank account. We encode the “purpose” column into values “education”/“no education” to assess the effect of education as a credit purpose. Finally, we handle missing values and normalize the numeric columns in the data.</p><figure><img alt="Easy Interpretation of a Logistic Regression Model with Delta-p" src="https://cdn-images-1.medium.com/max/1014/0*t2bTuOoE6DD8yS-b.png" /><figcaption>Figure 2. The process from accessing raw credit customer data to training a credit rating model, and to evaluating the effects of predictor columns on the credit rating with Delta-p statistics. This solution was built in KNIME Analytics Platform, and the <a href="https://kni.me/w/dQwCNoz4SyzPhJdn">Assessing Effects of Single Predictors with Delta-p </a>workflow can be inspected and downloaded on the KNIME Hub.</figcaption></figure><p>Figure 3 shows the coefficient statistics of the logistic regression model, reproducible in any tool. The “Coeff.” column shows the coefficient values for the different predictor columns, 0.683 for <em>purpose=education</em>. The “P&gt;|z|” column shows the p-values of the coefficients, 0.055 for <em>purpose=education</em>. This means that education as a credit purpose increases the probability of a bad credit rating, since the coefficient value is positive, and this effect is significant at 90 % significance level, since the p-value is smaller than 0.1.</p><figure><img alt="Easy Interpretation of a Logistic Regression Model with Delta-p" src="https://cdn-images-1.medium.com/max/715/0*G7tpVxncfw2GWhRJ.jpg" /><figcaption>Figure 3. Coefficient statistics of a logistic regression model that predicts the credit rating good/bad of a credit applicant.</figcaption></figure><p>By looking at the coefficient statistics of the logistic regression model, we find out that education as a credit purpose increases the probability of a bad credit rating compared to other credit purposes. In addition, the coefficient value 0.683 tells that the log odds ratio for getting a bad credit rating with/without education as the credit purpose is 0.683, and the odds ratio of the two groups is e^0.683=1.979. What would this mean, for example, in a group of 100 credit applicants, let’s say 20 of them with education as the purpose (group 1) and the remaining 80 with another purpose (group 2)? If 10 out of the 80 applicants in group 2 have a bad credit rating, so their odds is 0.125, then according to the odds ratio 1.979, the odds for group 1 must be ~2 times the odds of group 2, so 0.25 in this case. Therefore a quarter (in this case 5) of the applicants in group 1 must have a bad credit rating!</p><p>The coefficient statistics have a universal scale, and we can use them to compare the magnitude and the effect of different predictor columns. However, to understand the effect of a single predictor, the Delta-p statistics provide an easier way! Let’s take a look:</p><p>In Figure 4 you can see the Delta-p statistics and the intermediate results in calculating it, also shown below for the <em>purpose=education</em> variable:</p><figure><img alt="Easy Interpretation of a Logistic Regression Model with Delta-p" src="https://cdn-images-1.medium.com/max/1024/0*yurj5CHYmDHopaOt.png" /></figure><figure><img alt="Easy Interpretation of a Logistic Regression Model with Delta-p" src="https://cdn-images-1.medium.com/max/1024/0*cqsmaOBFudnHccfC.png" /><figcaption>Figure 4. Delta-p statistics, its intermediate results, and the corresponding coefficient statistics of a logistic regression model that predicts the credit rating good/bad of a credit applicant.</figcaption></figure><p>The value 0.159 of the Delta-p statistics indicates that education as a credit purpose increases the probability of a bad credit rating by 15.9 % compared to an average credit application.</p><p>If we wanted to compare the effect to the opposite situation, i.e., the credit purpose is not education, instead of an average credit applicant, we would need to recalculate the prior probability and also mean-center the binomial values of the predictor column of interest <em>x_i</em>. In our data, 5 % of the people apply the credit for education purposes, so the mean of the “purpose” column <em>x_i</em> is 0.05.</p><figure><img alt="Easy Interpretation of a Logistic Regression Model with Delta-p" src="https://cdn-images-1.medium.com/max/1024/0*-FHk4VDxV3Sp6c63.png" /></figure><p>The value 0.158 of the Delta-p statistics indicates that the credit applied for educational purposes increases the probability of a bad credit rating by 15.8 % compared to those who apply it for other purposes. There’s hardly any difference to the previous situation where we compared against an average applicant and obtained the Delta-p value of 0.159 (Figure 4). This means that the credit applicants with other purposes than education are very close to the sample average in terms of their credit rating, apparently because they make up 95% of the total sample.</p><p>Now we know that applying for credit for education purposes has a negative effect on the credit rating. Which column could have a positive effect? Let’s check the effect of the other dummy column that we created, the “checking” column that tells if the balance of the existing account is negative. The coefficient value of <em>checking=some funds or no account</em> is -1.063 with a p-value 0, as you can see in the first row in Figure 3.</p><p>As the Delta-p statistics -0.171 in the first row in Figure 4 show, credit applicants with no negative account balance tend to have a 17.1 % lower probability of a bad credit rating than an average credit applicant. Interestingly, we found two columns, purpose and checking, that have an effect of almost the same size but in a different direction. If we look at the odds ratio of these two variables in Figure 4, we wouldn’t get the same information at first glance: The odds ratio is 0.345 for <em>checking=some funds or no account</em> and 1.979 for <em>purpose=education</em>.</p><h3>Conclusions</h3><p>In this article, we have introduced Delta-p statistics as a straightforward way of interpreting the coefficients of a logistic regression model. With Delta-p statistics, the predictions based on a logistic regression model are easy to understand by non-technical decision-makers.</p><p>We used Delta-p statistics to assess the individual effects that make a credit application succeed or fail. Of course, the use cases of Delta-p statistics are many more. For example, we could use Delta-p statistics to determine the individual touchpoints that decrease or increase customer satisfaction the most or to find the symptoms with the highest relevance, when detecting a disease. Also, notice that not always the whole process from raw data to model training and model evaluation needs to be completed, Delta-p statistics can also be used to re-evaluate the coefficients of a previously trained logistic regression model.</p><p>Delta-p statistics can only be used to assess the individual effects of predictor columns in a logistic regression model. Logistic regression might not be the best choice when working with high dimensional data, with many correlated predictor columns, and columns not correlated with the target column. The target classes also need to be <a href="https://en.wikipedia.org/wiki/Linear_separability">linearly separable</a> in the feature space.</p><p>If you want to replicate the procedure described in the article, one option is to install the open-source <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Analytics Platform</a> on their laptops and download the KNIME workflow attached to the article for free. A visual representation of the workflow is available on the KNIME Hub without installing KNIME Analytics Platform. Other options are to implement the calculations in another programming tool, or even perform them manually with a calculator.</p><h4>References</h4><p>[1] Cruce, T. M. (2009). A Note on the Calculation and Interpretation of the Delta-p Statistic for Categorical Independent Variables, Research in High Education, 50(6), 608–622.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70270c346895" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/easy-interpretation-of-a-logistic-regression-model-with-delta-p-statistics-70270c346895">Easy Interpretation of a Logistic Regression Model with Delta-p Statistics</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cohort Analysis: Seeing the Forest for the Trees]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/cohort-analysis-seeing-the-forest-for-the-trees-16a26cfab203?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/16a26cfab203</guid>
            <category><![CDATA[accounting]]></category>
            <category><![CDATA[knime]]></category>
            <category><![CDATA[theory]]></category>
            <category><![CDATA[finance-and-banking]]></category>
            <category><![CDATA[cohort-analysis]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Wed, 22 Jun 2022 08:04:44 GMT</pubDate>
            <atom:updated>2022-07-06T08:38:09.803Z</atom:updated>
            <content:encoded><![CDATA[<h4>DATA SCIENCE THEORY | COHORT ANALYSIS | KNIME ANALYTICS PLATFORM</h4><h4>Revealing a comprehensive view of your business with KNIME</h4><p><em>Co-author: </em><a href="https://www.linkedin.com/in/felix-kergl-r%C3%A4pple-0a083519a/"><em>Felix Kergl-Räpple</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mZMf3T3-nkfJ1Mn-" /><figcaption>Photo by <a href="https://unsplash.com/@ellentanner?utm_source=medium&amp;utm_medium=referral">Ellen Tanner</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A marketing campaign or publication of a new release can make numbers of customers boom for a while. But what are the effects in the long run? Do the customers stay or churn? Do any of them return at some point? Does the overall revenue increase?</p><p>Patterns can be detected in customer behavior: for example, patterns in the regular behavior of customers, i.e. behavior that is not affected by our marketing campaigns or other similar actions. Based on the patterns, we might want to try to find a critical contract duration that determines whether customers will become loyal customers or not. Another scenario worth analyzing is customer groups — to see if different conditions in contracts with different starting points cause these different customer groups to show equal loyalty or not.</p><p>To answer these questions, we can analyze our sales data over time by time-based cohorts.</p><h3>Identifying Long-Term Customer Behavior</h3><p><a href="https://en.wikipedia.org/wiki/Cohort_analysis">Cohort analysis</a> provides long-term feedback on our business decisions and customer engagement. Therefore, we use time as one dimension in the analysis. The second dimension is the metric that we analyze: contract value, customer count, number of orders, or anything else that quantifies the behavior of our customers. This “customer value” is shown separately for different cohorts. Cohorts are groupings in the data that share similar characteristics based on time, segment, or size. Given these three dimensions, we can identify patterns and trends that wouldn’t be visible in the individual records, thus providing a more complete look at our business.</p><p>Before starting the cohort analysis, we have to define:</p><ol><li>The cohorts that we consider in our data. They could be, for example, customers who started doing business with you within the same time frame (time-based cohorts), customers buying similar products (segment-based cohorts), or medium- and large-size companies (size-based cohorts).</li><li>The information that we want to show for the different cohorts over time. It could be an established metric, such as annually recurring revenue or churn rate, or anything else that answers our questions about the customers, and serves the final goal to improve our business.</li></ol><p>In this blog post we want to concentrate on time-based cohorts. In the next sections we introduce the steps you go through to build a cohort chart (Figure 1), from formatting the data to visualizing the selected metric by time and cohort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*zI2daxwRZMrvrv0C" /><figcaption>Figure 1: An example of a cohort chart to analyze customer count, or any other metric such as ARR, by time and time-based cohort.</figcaption></figure><h3>Example: Analyze the Number, Value, and Duration of Contracts</h3><p>Let’s start by having a look at an example cohort analysis and see how the company’s business is doing. The company issues contracts — software licenses, mobile contracts, or magazine subscriptions, for example. Based on the starting time of the contract, we assign each customer to a time-based cohort.</p><p>The results of the cohort analysis enable us to answer questions such as:</p><ul><li>Can we detect a positive trend in terms of more customers and more revenue? Is the trend stable?</li><li>Do customers who entered into a contract in a particular year generate more revenue than customers who started in other years?</li><li>Which year(s) show the greatest customer churn?</li><li>Does the value of the contracts remain stable over time?</li><li>Has the average revenue per customer increased or decreased?</li></ul><h4>Data</h4><p>In our example, the data contains information about contracts upsells, downgrades, and churn events. There are 45 contracts and 12 customers. Contract periods range from January 2015 to December 2019. Each row in the data shows the start and end time of the contract period, the contract value, and an ID that identifies the customer. You can see a sample of the data in Figure 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/0*9c9qZoZBfLQh7X3N" /><figcaption>Figure 2: Data containing information on contract IDs, values, and periods. In the first step of the cohort analysis, this dataset is transformed into time series by assigning recurring values to single months within the periods.</figcaption></figure><p>The first step in the cohort analysis is to assign recurring values to the single months within the contract periods. Recurring values exclude one-time events, that is, they only consider the services that are constantly provided over a limited time period: subscriptions to software, support, content, etc.</p><h4>Step 1: Calculate Recurring Values</h4><p>When we calculate recurring values, we format the original contract data into time series data where each row contains a single month, a recurring value, and an ID. We can do this calculation with the “Calculate Recurring Values” component shown in Figure 3. The component is available for download on the <a href="https://kni.me/w/w90yTJFZX7-2Jrw4">KNIME Hub</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*_VfV1MgjW4qSfpgb" /><figcaption>Figure 3: Transforming contract data into time series data where each row contains a single month, a value, and an ID. The “Calculate Recurring Values” component which performs the calculation is available on the <a href="https://kni.me/w/w90yTJFZX7-2Jrw4">KNIME Hub</a>.</figcaption></figure><p><strong>Input table. </strong>An example of an input table for the “Calculate Recurring Revenue” component is shown in Figure 2. The table must contain two columns that define the start and end date of each contract period, one column for the contract value, and one column for the ID.</p><p><strong>Output table. </strong>The output table of the component shows each individual month within the contract period, and the recurring values for each month. For example, if we had a row for a contract with a value of EUR 30,000 and a contract period of 12 months, the output table would show 12 rows for this contract, one for each month, and a monthly recurring value of EUR 2,500 (Figure 4).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*im5VcFmzgRX0UJRM" /><figcaption>Figure 4: Example input and output data of the “<a href="https://kni.me/w/w90yTJFZX7-2Jrw4">Calculate Recurring Values</a>” component that converts contracts data into time series data: records by contract period and ID are expanded to monthly recurring values by single month and ID.</figcaption></figure><p>Now, after formatting the data, we are ready to move on to the next step where we build the cohort chart. We can subsequently use the chart to answer the questions about the state of our business.</p><h4>Step 2: Inspect Revenue and Customer Count by Time and Cohort</h4><p>In this second step, we calculate the selected metric separately for each month and time-based cohort. For example, we could have two customers who started in 2018, one with a monthly recurring revenue of EUR 2,000 and the other with monthly recurring revenue of EUR 3,000. These two customers would then constitute a single time-based cohort called “Started 2018”. The monthly recurring revenue for this cohort is therefore EUR 5,000 until at least one of the two customers upgrades, downgrades, or churns.</p><p>The time series data could also come from any other source. It could be the daily sales coming from subscriptions or grocery stores, for example. Regardless of what the data actually show, note that in order to perform cohort analysis, each record must contain a timestamp, identifier, and a value.</p><p>The workflow in Figure 5 shows two components that enable you to analyze time-based cohorts using the following metrics:</p><ul><li>annually/monthly recurring revenue (ARR/MRR)</li><li>annually/monthly recurring revenue relative to customer count</li><li>customer count</li><li>churn rate</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/0*22SaCRyTkTUskN4c" /><figcaption>Figure 5: Analyzing time-based cohorts with the “<a href="https://kni.me/w/OCM1X3nGSJ1qe0Nq">ARR and MRR by Time-based Cohort</a>” and “<a href="https://kni.me/w/YH6r20ivuOTJBYv5">Customer Count and Time-based Cohort</a>” components available on the KNIME Hub. Both components produce an interactive view showing how the selected metric develops over time for each cohort.</figcaption></figure><p>Example outputs of these components are shown in Figure 6. The line plot on the left shows the ARR for each cohort over time. The stacked area chart on the right shows the cumulative customer count for the different cohorts over time. The metric, the granularity of the cohorts, and the chart type can be defined in the configuration dialogs of the components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fu58XIQIyl4JAqog" /><figcaption>Figure 6: Cohort charts as produced by the “<a href="https://kni.me/w/OCM1X3nGSJ1qe0Nq">ARR and MRR by Time-based Cohort</a>” and “<a href="https://kni.me/w/YH6r20ivuOTJBYv5">Customer Count and Churn Rate by Time-based Cohort</a>” components. The line plot on the left shows the ARR for each cohort over time; the stacked area chart on the right shows the customer count for each cohort and in total over time.</figcaption></figure><p>From the line plot on the left in Figure 6, we can see that the ARR develops differently for the four time-based cohorts:</p><ul><li>The customers who started in 2015 (blue line) increase their ARR value in the first year, but reach a low in the second half of 2016. Their ARR starts increasing again in 2017 and returns to its original value at the beginning of 2018.</li><li>The customers who started in 2016 (orange line) show an increase in ARR by the end of 2017. Their ARR starts to decline through to the beginning of 2019, where it then settles down to a constant value.</li><li>The customers who started their contracts in 2017 (green line) have a constant ARR value over the whole time period from the beginning of 2017 to the end of 2019.</li><li>The customers who started in 2018 (red line) increase their revenue until it sets to a constant value at the beginning of 2019.</li></ul><p>From the stacked area chart on the right in Figure 6, we can see that the decreasing ARR of the “Started 2015” cohort (blue area) causes a low in total ARR at the end of 2016 but it starts increasing again due to the additional ARR coming from the “Started 2016” cohort (orange area) and the constant ARR coming from the “Started 2017” cohort (green area). The decreasing ARR for the “Started 2016” cohort cannot be compensated by the ARR coming from the “Started 2018” cohort (red area). This means that the maximum total ARR is reached at the beginning of 2018 before the ARR of “Started 2016” starts to decline.</p><h3>Shared Components</h3><p>Now, it’s your turn to analyze your own customer data and build the cohort charts. Drag and drop the components from <a href="https://hub.knime.com/knime/spaces/Examples/latest/00_Components/Financial%20Analysis/">the KNIME Hub</a>, and follow the steps as described above. You can use the configuration dialogs of the components to customize your cohort analysis: create time series with daily recurring values, extract cohorts based on the starting month, calculate the churn rate, or some of the other available metrics. If you want, you can also change the functionality of the components for your purpose: add new metrics and charts, for example.</p><blockquote><strong><em>Note.</em></strong><em> Check out these videos </em><a href="https://youtu.be/NppFyVaL9IY"><em>“What is a Component?”</em></a><em>, “</em><a href="https://youtu.be/x3hAKezILX0"><em>Component Configurations</em></a><em>”, and </em><a href="https://youtu.be/vt807Bg7Jag"><em>“Sharing and Linking Components”</em></a><em> for more details on components.</em></blockquote><h3>Summary</h3><p>Cohort analysis gives us a robust and comprehensive view of the state of our business. Cohort analysis gives us feedback over a long cycle of business. It smooths occasional fluctuations, giving us perspective on our customers’ behavior in the long term. Cohort analysis can reveal patterns in customer behavior that are only visible when we analyze customers by groups. For example, an increase in actual numbers could still mean a decrease in loyalty.</p><p>The steps in building a cohort chart from contract data include blending data, filling gaps in time series and checking for zero values, sorting, and pivoting, along with other data preprocessing operations. The components introduced in this blog post automate these steps, yet they let us define the key settings, such as the granularity of the cohorts and the metric to analyze.</p><p>If you’re interested in more resources for automating financial analysis, check out this <a href="https://www.knime.com/finance-data-analysis?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">Finance Data Analysis</a> page on the KNIME website.</p><p>— — — — -</p><p>As first published on the KNIME Blog: <a href="https://www.knime.com/blog/seeing-the-forest-for-the-trees-cohort-analysis">https://www.knime.com/blog/seeing-the-forest-for-the-trees-cohort-analysis</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16a26cfab203" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/cohort-analysis-seeing-the-forest-for-the-trees-16a26cfab203">Cohort Analysis: Seeing the Forest for the Trees</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Time Series Analysis Application]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/building-a-time-series-analysis-application-7891fc9815ee?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/7891fc9815ee</guid>
            <category><![CDATA[knime]]></category>
            <category><![CDATA[theory]]></category>
            <category><![CDATA[editors-pick]]></category>
            <category><![CDATA[time-series-analysis]]></category>
            <category><![CDATA[time-series-forecasting]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Wed, 15 Jun 2022 09:18:36 GMT</pubDate>
            <atom:updated>2022-07-06T16:53:07.104Z</atom:updated>
            <content:encoded><![CDATA[<h4>DATA SCIENCE THEORY | TIME SERIES ANALYSIS | KNIME ANALYTICS PLATFORM</h4><h4><em>Describing the process of accessing, pre-processing, and forecasting time series</em></h4><p><em>Co-authors: </em><a href="https://www.linkedin.com/in/danieletonini/"><em>Daniele Tonini</em></a><em>, and </em><a href="https://www.linkedin.com/in/corey-weisinger-709525121/"><em>Corey Weisinger</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZPpCMVvlgRjIYsPx" /><figcaption>Photo by <a href="https://unsplash.com/@agebarros?utm_source=medium&amp;utm_medium=referral">Agê Barros</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>A time series analysis application starts from data access and pre-processing, proceeds with model training and evaluation, and finishes with deployment — like any other data science application. Yet for time series data the techniques applied in these steps are different in comparison to cross-sectional data, because time series data are collected by observing the same object multiple times, and the pre-processing and model training steps consider this temporal structure of the data.</p><p>In this article, we introduce different sources of time series data, explain common pre-processing techniques, and compare different approaches to forecasting. Finally, we show how to execute a time series application in <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Analytics Platform</a>.</p><h3>Accessing Time Series</h3><p>Time series data are collected by observing the same object over time. The sources of time series data and thus applications are many, for example, daily sales data from a supermarket for demand prediction, yearly macroeconomic data from a country for long-term political planning, and sensor data from a smartwatch for health tracking. The different sources produce time series data at different levels of detail and constancy. As an example, we could have a GDP value for a country per year and a sensor value from a smartwatch per second. On the other hand, the GDP values fluctuate less and all always available, while the smartwatch signals might be anomalous or completely missing with a low battery for example. Especially, if we are observing random events, such as disease infections or spontaneous customer visits, the aperiodicity of the raw data is expected by the nature of the data collection.</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/1024/0*rdMOCNtP_ppfZGS5.png" /><figcaption>Figure 1: A time series is collected by observing the same object over time. The observable objects vary from tiny single objects such as muscles in a human body to larger entities, such as countries.</figcaption></figure><h3>Pre-processing Time Series</h3><p>After accessing time series data, the next step is to clean and transform it as required by, firstly, the original shape of the data, and secondly, the analytics purpose.</p><p>Below we introduce a few common pre-processing steps for time series data.</p><h4><strong>Sorting, partitioning, and aggregation</strong></h4><p>The sorting of the time series ensures that the time series is in chronological order. This sorting should also be preserved when partitioning the data into training and test sets. Therefore, the appropriate partitioning strategy is called “take from the top”, which takes the first <em>x</em> rows for training and uses the remaining rows for testing. Furthermore, if the data contain more than one record per timestamp, for example when you have multiple orders per day, a required pre-processing step is to aggregate the recorded values by the timestamp. This aggregation step produces a time series with only one value per timestamp. Another purpose of aggregating time series data is to reduce its granularity. For example, to obtain monthly data from originally daily data, you can aggregate the daily values into, for example, the monthly total values. The aggregation by date and time fields is called time aggregation.</p><h4><strong>Missing value handling</strong></h4><p>Missing value handling refers to firstly, introducing possible missing timestamps into the time series, and secondly, imputing the corresponding missing values. The result, a time series with a value for each timestamp at regular intervals, is called equally spaced.</p><p>Popular missing value handling strategies for time series data are based on a fixed value or a statistical measure, such as the moving average, previous/next value, and linear interpolation. The moving average is a good approximation of randomly missing values in irregular data. The replacement strategies based on a previous/next value and linear interpolation perform well for time series data with autocorrelation. If the missing values are not missing at random, due to holidays, for example, you can replace them with 0 or another known value. On the other hand, if the missing values occur far enough in the past, you can also ignore the older data.</p><h4><strong>Smoothing and outlier detection</strong></h4><p>Smoothing reduces redundant details and noise in time series data, while outlier detection treats exceptional values that might otherwise bias the analysis. For smoothing, popular techniques are called <a href="https://en.wikipedia.org/wiki/Moving_average">moving average </a>and <a href="https://en.wikipedia.org/wiki/Exponential_smoothing#:~:text=Exponential%20smoothing%20is%20a%20rule,exponentially%20decreasing%20weights%20over%20time.">exponential smoothing</a>. For outlier detection, a common approach is the box plot, which is based on quantile statistics. This approach removes or truncates the values that lie outside the whiskers of a box plot, that is values that lie exceptionally far beyond the first or the third quantile. However, keep in mind that a part of the exceptional fluctuation can be due to seasonality. Therefore, for time series data with seasonality, it’s recommended to inspect the variation with a conditional box plot because it displays the outliers at each point of the seasonal cycle separately.</p><p>Besides via smoothing and outlier detection, you can obtain a more regular time series by extracting a subset of it, for example, by only considering the sales of one product instead of the sales of the whole supermarket, or by clustering the data.</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/1024/0*mECdGdis_Dz9AoCI.png" /><figcaption>Figure 2: Time aggregation, missing value handling, and outlier detection are examples of techniques for pre-processing time series data.</figcaption></figure><h3>Exploring and Decomposing Time Series</h3><p>After pre-processing, the next step is visual exploration and time series decomposition. Visual exploration reveals long and short-term patterns and temporal relationships that we can use to better comprehend the dynamics of the time series. Decomposition separates the dynamics of the time series into regular and irregular components.</p><p>Below we introduce techniques for visual exploration and time series decomposition.</p><h4><strong>Visual exploration of time series</strong></h4><p>A widely used plot for exploring time series is the <strong>line plot </strong>that shows all values in the time series and displays a possible direction (trend), regular fluctuation (seasonality), outliers, gaps, or turning points in it.</p><p>For time series with a seasonal pattern, a <strong>seasonal plot </strong>shows the dynamics of subsequent seasonal cycles in parallel. For example, for sales data with yearly seasonality, the seasonal plot can show if a specific month, let’s say July, was a stronger sales month this year than last year.</p><p>A <strong>conditional box plot</strong> shows the variability of the data at different points of the seasonal cycle. With a conditional box plot, you can treat extreme values as normal/exceptional by comparing them to the median of comparable data points instead of all data. Furthermore, in a conditional box plot, you can also inspect how much the variability differs through the seasonal cycle.</p><p>A <strong>lag plot </strong>compares the current values to the past values in a scatter plot and reveals if there is autocorrelation in the time series at this lag.</p><p>Finally, the <strong>autocorrelation (ACF) plot</strong> shows the lag with the highest autocorrelation and thus also displays the length of the possible seasonal cycle. For example, if you observe a peak at lag 7 in the ACF plot, and you have daily data, then there is weekly seasonality in the data. The ACF plot also shows if the time series is stationary. We will talk more about stationarity in the next section.</p><p>In Figure 3 below we show examples of the visual exploration techniques that we introduce above:</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/1024/0*nlfhSZkpgwFu4y5F.png" /><figcaption>Figure 3: Lag plot, conditional box plot, line plot, seasonal plot and autocorrelation plot are examples of visual exploration techniques of time series.</figcaption></figure><h4><strong>Classical decomposition of time series</strong></h4><p>Classical decomposition means extracting the regular dynamics of the time series, called trend and seasonality, and its irregular part called residual, from the time series into separate components. The decomposition contributes to the final forecasting in two ways. Firstly, forecasting by the regular dynamics provides a benchmark for the more complex forecasting models. These models should exceed their forecasting performance to be worth training. Secondly, decomposing the time series produces a <a href="https://en.wikipedia.org/wiki/Stationary_process">stationary </a>time series, which is required before training an ARIMA model. Notice that sometimes additional transformations on the residual series might be required to make it stationary, such as first-order differencing to stabilize the mean, or log transformation to stabilize the variance.</p><p>To decompose the trend component from the time series, we fit a regression model through the data. And to decompose the seasonal components, we difference the data at the lag where the major spike in the ACF plot occurs. To decompose a possible second seasonality, we can difference the differenced time series at the lag of the second seasonality. Differencing the data a third time is rarely required.</p><p>After decomposing the time series, we can do a final check for stationarity with, for example, the <a href="https://en.wikipedia.org/wiki/Ljung%E2%80%93Box_test">Ljung-box test</a>. After that, we can move on to training the forecasting model.</p><h3>Training a forecasting model</h3><p>The next step is to train the forecasting model. We can do this with an ARIMA model or a machine learning model. An ARIMA model can only be trained on the residual part of the time series, because it’s stationary, while a machine learning model doesn’t have the same restriction and can also be trained on the original time series. In addition, a seasonal ARIMA (SARIMA) model can be trained on the original, non-stationary time series data.</p><p>In the following sections, we summarize a few different forecasting techniques, which you select from and compare for your use case.</p><h4><strong>(S)ARIMA models</strong></h4><p><a href="https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average">ARIMA </a>(AutoRegressive Integrated Moving Average) model is a linear regression model between the current and past values (AR-part), and also between the current and past forecast errors (MA-part). If the model has a non-zero I-part, then the data are differenced in order to make it stationary. A SARIMA model is the same as an ARIMA model plus regressors at seasonal lags. Modeling data with an ARIMA model requires stationary data, and a stationary time series doesn’t have predictable patterns in the long term. Thus, the declining accuracy in the long-term forecasts can be seen in the increasing confidence intervals of the forecasts. Furthermore, having more data is not always better for training an ARIMA model: Large datasets increase the training time and might introduce noise that bias the algorithm.</p><h4><strong>Machine Learning models</strong></h4><p>Machine learning models use the lagged values as predictor columns, yet they are treated as any other predictor columns. Machine learning models can identify complex dynamics and long-term patterns in the data, provided that enough training data are available. In general, the more complex the dynamics of the time series, the more data are needed for training the forecasting model. When training a machine learning model on the original data instead of the residual, it’s recommended to compare its forecasting performance to the benchmark obtained by classical decomposition to make sure that the model also captures the irregular dynamics and is thus worth training.</p><h4><strong>Tips on model selection</strong></h4><p>The model selection is based on the forecasting performance and also other aspects related to the real-world use case. Below we highlight a few of them.</p><p><strong>Forecastability.</strong> A time series can be difficult to forecast by nature because it describes a randomly evolving process. In such a case it often makes sense to go for a simpler model and not invest resources in modeling dynamics that are unpredictable.</p><p><strong>Interpretability.</strong> If important decisions are based on the results of the model, the domain expert might prefer a model that is easier to interpret over a model that performs slightly better. For example, a neural network is difficult to understand without data science skills, while a model based on classical decomposition is more intuitive.</p><p><strong>Available data.</strong> All data that is related to the dynamics of the time series is not always available or worth collecting. For example, adding explanatory variables — other predictors than past values of the time series itself — to the time series model might improve the forecast accuracy. However, the explanatory variables need to be forecast, too, which increases the complexity of the model.</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/1024/0*xgxSxJvjLWERDYMh.png" /><figcaption>Figure 4: The availability, complexity, and randomness of the data and the interpretability of the model are examples of aspects that determine the selection of the forecasting model. As an example, the line plot in the top left corner shows the forecasts by a neural network trained with too little training data. The line plots in the bottom left corner show a completely random process and a process with a change in its dynamics. The line plot on the right shows a time series that follows an ARIMA (2,1,1) process.</figcaption></figure><h4>Model Evaluation</h4><p>After training a model, the next step is to evaluate it. We can generate two kinds of evaluation metrics that report the in-sample and out-sample prediction performance of the model, respectively. The in-sample prediction performance reports the model’s prediction performance on the training data. The out-sample prediction performance reports the model’s performance on the test data that follows the training data in time.</p><p>One recommended error metric for evaluating a forecasting model is the mean absolute percentage error (<a href="https://en.wikipedia.org/wiki/Mean_absolute_percentage_error">MAPE</a>), which provides the error in a universal scale, as a percentage of the actual value. However, if the actual values contain zeros, this metric is not defined, and then other error metrics, like the root mean squared error (<a href="https://en.wikipedia.org/wiki/Root-mean-square_deviation">RMSE</a>), can be used. Notice that the <a href="https://en.wikipedia.org/wiki/Coefficient_of_determination">R-squared</a> metric should not be used to evaluate the prediction performance on non-stationary data because it reports a better performance when the variance increases.</p><h3>Forecasting and Reconstructing Time Series</h3><p>We’re almost there! We introduce the last analytics steps, forecasting and reconstructing the signal, in the following sections.</p><h4><strong>Dynamic forecasting</strong></h4><p>In dynamic deployment, only one point in the future is forecast at a time, and the past data are updated by this forecast value to generate the next forecast (Figure 5). The purpose of the dynamic deployment is to improve the out-sample prediction performance of the model.</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/991/0*SOobfC9qBNOfEcau.png" /><figcaption>Figure 5: In dynamic deployment, only one forecast is generated at a time, and this forecast is added to the past data to generate the next forecast one step further ahead in time.</figcaption></figure><h4><strong>Restoring trend and seasonalities</strong></h4><p>The final forecast value consists of the forecast residual value to which the trend and seasonality components have been restored. We start composing the final forecast by adding values in the residual series at the lag where the first seasonality occurs. For example, if we have daily residual series <strong>y </strong>which has been differenced at lag 7 (weekly seasonality), restoring this seasonality would require the following calculation:</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/392/0*1sQqI1jQZalng1u0.png" /></figure><p>where <em>t</em>ᵢ<em> </em>is the last time index in the training data, and <em>h </em>is the forecast horizon.</p><p>After that, we restore the second seasonality by repeating the calculation described above at the lag of the second seasonality. Finally, we restore the trend component to the time series by applying the regression model representing the trend component.</p><h3>Completing a Time Series Application in KNIME Analytics Platform</h3><p>Finally, we show how to execute a time series application using <a href="https://www.knime.com/knime-analytics-platform?utm_source=medium&amp;utm_medium=organic&amp;utm_term=&amp;utm_content=&amp;utm_campaign=com_journal">KNIME Analytics Platform</a>. Figure 6 below shows an example workflow (available on <a href="https://kni.me/w/HahI9s4ecV71ILKT">the KNIME Hub</a>). The workflow accesses, pre-processes and visualizes time series data. Then, it decomposes it and trains an ARIMA model on it. In the workflow, we use <a href="https://hub.knime.com/knime/spaces/Examples/latest/00_Components/Time%20Series/">time series components</a> that perform dedicated time series analysis tasks, such as time aggregation and time series decomposition.</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/1024/0*XHyJNGijMLf6vgsJ.png" /><figcaption>Figure 6: A workflow for accessing, pre-processing, visualizing and modeling time series. Download the workflow from the <a href="https://kni.me/w/HahI9s4ecV71ILKT">KNIME Hub</a>.</figcaption></figure><p>The example workflow processes superstore sales data provided by <a href="https://www.tableau.com/">Tableau</a>. The Sample-Superstore.xls file is available on <a href="https://www.kaggle.com/pruthvi1995/superstore-sales">Kaggle</a>. We analyze the orders of all products from 2014 to 2017, altogether 9994 rows.</p><p>After accessing the data, we perform the following pre-processing steps:</p><ol><li>We calculate the total sales per day with the GroupBy node so that we only have one value per day. At this point, though, the days when no orders were submitted are missing.</li><li>Next, we introduce the missing days into the time series with the <a href="https://kni.me/c/lTj0tRRU1w6R6JEd">Timestamp Alignment</a> component and replace the missing sales values with a fixed value 0 with the Missing Value node.</li><li>After that, we perform time aggregation with the <a href="https://kni.me/c/KYVj-Ayb9VdSNjiS">Aggregation Granularity</a> components to obtain the average sales in each month and in each year, respectively, for visual exploration and forecasting.</li></ol><p>After pre-processing, we perform visual exploration via the Line Plot and Conditional Box Plot nodes and the <a href="https://kni.me/c/zpF1WFnJoSjwvWqD">Decompose Signal</a> component. Figure 7 below shows the results:</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/1024/0*4Pzz9iWRrJYzYVIZ.png" /><figcaption><em>Figure 7: Exploring the time series visually via line plots and autocorrelation plots.</em></figcaption></figure><p>We find out that there’s a turning point at the beginning of the year 2015, as the line plot on the top right in Figure 7 shows. The line plot on the left shows the values of the monthly sales with a yearly seasonality: there are two regular peaks at the end of each year, and a lower peak at the beginning of each year. We detect the same yearly seasonality by looking at the ACF plot in the bottom left corner, which shows a major spike at lag 12. The ACF plot in the bottom right corner shows no significant autocorrelation in the residual series after decomposing the time series. The decomposed parts of the time series, that is trend, seasonality, and residual are shown in the line plot in the middle.</p><p>Next, we model the residual series of the monthly average sales with an ARIMA model. We look for the best model with the <a href="https://kni.me/c/_ROfECTX-hZ84VW4">Auto ARIMA Learner</a> component with max order 4 for the AR and MA parts and max order 1 for the I part. The best performing model based on <a href="https://en.wikipedia.org/wiki/Akaike_information_criterion">Akaike information criterion </a>is ARIMA (0, 1, 4), and the resulting R-squared on the (stationary!) residual series is 0.073.</p><p>Finally, we perform out-sample forecasting in a separate workflow. The workflow is available on the <a href="https://kni.me/w/nRzAJzVATgcqry9h">KNIME Hub</a> and shown in Figure 8:</p><figure><img alt="Building a Time Series Application" src="https://cdn-images-1.medium.com/max/1024/0*RWgAg3rtka6EzBFW.png" /><figcaption><em>Figure 8: Workflow to forecast the monthly sales with an ARIMA (0,1,4) model using dynamic deployment. The workflow is available on the </em><a href="https://kni.me/w/nRzAJzVATgcqry9h"><em>KNIME Hub</em></a><em>.</em></figcaption></figure><p>It forecasts the monthly sales in 2017 using an ARIMA (0,1,4) model and the dynamic deployment approach. It also reconstructs the final forecasts by restoring the trend and yearly seasonality to the forecast residuals. Finally, it compares the actual and forecast sales values in a line plot and via scoring metrics. The MAPE value of the forecasts is 0.336, which means that the actual sales values deviate on average 33.6% from the forecast values.</p><h3>Summary</h3><p>In this article, we have introduced you to the specific analytics techniques for time series data and completed an example time series analytics application in KNIME Analytics Platform.</p><p>Are you looking for a more comprehensive guide on time series analysis with KNIME?</p><blockquote>Codeless Time Series Analysis with KNIME is in progress by the time series specialists at KNIME, Corey Weisinger and Maarit Widmann, and Professor Daniele Tonini from Bocconi University (IT).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*a5nvqANlYzciCR4-gj6RAA.png" /></figure><p><strong>The book is already available for pre-order on Amazon:</strong></p><p><a href="https://www.amazon.de/dp/1803232064">Codeless Time series analysis with KNIME: A practical guide to implementing forecasting models for time series analysis applications</a></p><p>Watch out for the release in <strong>August 2022</strong> by <a href="https://www.packtpub.com/product/codeless-time-series-analysis-with-knime/9781803232065">Packt Publishing</a>!</p><h4>References</h4><p>[1] Chambers, John C., Satinder K. Mullick, and Donald D. Smith. <em>How to choose the right forecasting technique </em>. Harvard University, Graduate School of Business Administration, 1971.</p><p>[2] Hyndman, Rob J., and George Athanasopoulos. <em>Forecasting: principles and practice </em>. OTexts, 2018.</p><p>— — — — -</p><p>As first published on the KNIME Blog: <a href="https://www.knime.com/blog/building-a-time-series-analysis-application">https://www.knime.com/blog/building-a-time-series-analysis-application</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7891fc9815ee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/building-a-time-series-analysis-application-7891fc9815ee">Building a Time Series Analysis Application</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Modeling to Scoring: Correcting Predicted Class Probabilities in Imbalanced Datasets]]></title>
            <link>https://medium.com/low-code-for-advanced-data-science/from-modeling-to-scoring-correcting-predicted-class-probabilities-in-imbalanced-datasets-dce2b14a013b?source=rss-298582d6a022------2</link>
            <guid isPermaLink="false">https://medium.com/p/dce2b14a013b</guid>
            <category><![CDATA[knime]]></category>
            <category><![CDATA[class-probability]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[imbalanced-data]]></category>
            <category><![CDATA[theory]]></category>
            <dc:creator><![CDATA[Maarit Widmann]]></dc:creator>
            <pubDate>Wed, 04 May 2022 07:40:17 GMT</pubDate>
            <atom:updated>2022-05-04T07:40:17.212Z</atom:updated>
            <content:encoded><![CDATA[<h4>DATA SCIENCE THEORY | CLASS PROBABILITIES | KNIME ANALYTICS PLATFORM</h4><h4>Correct the predicted class probabilities by the information on the a priori class distribution</h4><p><em>Co-author: </em><a href="https://www.linkedin.com/in/alfredo-roccato-2699094/"><em>Alfredo Roccato</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9yxIYgciD1wdO3YO" /><figcaption>Photo by <a href="https://unsplash.com/@topspot?utm_source=medium&amp;utm_medium=referral">Gustavo Torres</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p><a href="https://hub.knime.com/search?q=model%20evaluation">Model evaluation</a> is an important part of a data science project and it’s exactly this part that quantifies how good your model is, how much it has improved from the previous version, how much better it is than your colleague’s model, and how much room for improvement there still is.</p><h4>Classification on Imbalanced Datasets</h4><p>It is not unusual in machine learning applications to deal with imbalanced datasets such as <a href="https://hub.knime.com/search?q=fraud%20detection&amp;type=Workflow">fraud detection</a>, computer network intrusion, medical diagnostics, and many more.</p><p>Data imbalance refers to unequal distribution of classes within a dataset, namely that there are far fewer events in one class in comparison to the others. If, for example we have credit card fraud detection dataset, most of the transactions are not fraudulent and very few can be classed as fraud detections. This underrepresented class is called the minority class, and by convention, the positive class.</p><p>It is recognized that classifiers work well when each class is fairly represented in the training data.</p><p>Therefore if the data are imbalanced, the performance of most standard learning algorithms will be compromised, because their purpose is to maximize the overall accuracy. For a dataset with 99% negative events and 1% positive events, a model could be 99% accurate, predicting all instances as negative, though, being useless. Put in terms of our credit card fraud detection dataset, this would mean that the model would tend to classify fraudulent transactions as legitimate transactions. Not good!</p><p>As a result, overall accuracy is not enough to assess the performance of models trained on imbalanced data. Other statistics, such as <a href="https://en.wikipedia.org/wiki/Cohen%27s_kappa">Cohen’s kappa </a>and <a href="https://en.wikipedia.org/wiki/F1_score">F-measure</a>, should be considered. F-measure captures both the <a href="https://en.wikipedia.org/wiki/Precision_and_recall">precision and recall</a>, while Cohen’s kappa takes into account the a priori distribution of the target classes.</p><p>The ideal classifier should provide high accuracy over the minority class, without compromising on the accuracy for the majority class.</p><h3><strong>Resampling to balance datasets</strong></h3><p>To work around the problem of class imbalance, the rows in the training data are resampled. The basic concept here is to alter the proportions of the classes (a priori distribution) of the training data in order to obtain a classifier that can effectively predict the minority class (the actual fraudulent transactions).</p><h4>Resampling techniques</h4><p><a href="https://en.wikipedia.org/wiki/Oversampling_and_undersampling_in_data_analysis"><strong>Undersampling</strong></a><strong>. </strong>A random sample of events from the majority class is drawn and removed from the training data. A drawback of this technique is that it loses information and potentially discards useful and important data for the learning process.</p><p><a href="https://en.wikipedia.org/wiki/Oversampling_and_undersampling_in_data_analysis"><strong>Oversampling</strong></a><strong>.</strong> Exact copies of events representing the minority class are replicated in the training dataset. However, multiple instances of certain rows can make the classifier too specific, causing overfitting issues.</p><p><a href="https://en.wikipedia.org/wiki/Oversampling_and_undersampling_in_data_analysis#SMOTE"><strong>SMOTE (Synthetic Minority Oversampling Technique)</strong></a><strong>. </strong>“Synthetic” rows are generated and added to the minority class. The artificial records are generated based on the similarity of the minority class events in the feature space.</p><h3>Correcting predicted class probabilities</h3><p>Let’s assume that we train a model on a resampled dataset. The resampling has changed the class distribution of the data from imbalanced to balanced. Now, if we apply the model to the test data and obtain predicted class probabilities, they won’t reflect those of the original data. This is because the model is trained on training data that are not representative of the original data, and thus the results do not generalize into the original or any unseen data. This means that we can use the model for prediction, but the class probabilities are not realistic: we can say whether a transaction is more probably fraudulent or legitimate, but we cannot say how probably it belongs to one of these classes. Sometimes we want to change the classification threshold because we want to take more/less risks, and then the model with the corrected class probabilities that haven’t been corrected wouldn’t work any more.</p><p>After resampling, we have now trained a model on balanced data i.e. that contain an equal number of fraudulent and legitimate transactions, which is luckily not a realistic scenario for any credit card provider and therefore — without correcting the predicted class probabilities — would not be informative about the risk of the transactions in the next weeks and months.</p><p>If the final goal of the analysis is not only to classify based on the highest predicted class probability, but also to get the correct class probabilities for each event, we need to apply a transformation to the obtained results. If we don’t apply the transformation to our model, grocery shopping with a credit card in a supermarket might raise too much interest!</p><p>The following formula [1] shows how to correct the predicted class probabilities for a binary classifier:</p><figure><img alt="Correcting Predicted Class Probabilities in Imbalanced Datasets" src="https://cdn-images-1.medium.com/max/464/0*iaieoZi_IkXIyoNk.png" /></figure><p>For example, if the proportion of the positive class in the original dataset is 1% and after resampling it is 50%, and the predicted positive class probability is 0.95, applying the correction it gives:</p><figure><img alt="Correcting Predicted Class Probabilities in Imbalanced Datasets" src="https://cdn-images-1.medium.com/max/339/0*Vr__ZOalGqPkRAzq.png" /></figure><h3>Example: Fraud detection</h3><p>When we apply a classification model to detect fraudulent transactions, the model has to work reliably on imbalanced data. Although few in number, fraudulent transactions can have remarkable consequences. Therefore, it’s worth checking how much we can improve the performance of the model and its usability in practice by resampling the data and correcting the predicted class probabilities.</p><h3>Evaluating the cost of a classification model</h3><p>In the real world, the performance of a classifier is usually assessed in terms of cost-benefit analysis: correct class predictions bring profit, whereas incorrect class predictions bring cost. In this case, fraudulent transactions predicted as legitimate cost the amount of fraud, and transactions predicted as fraudulent — correctly or incorrectly — bring administrative costs.</p><p>Administrative costs (<em>Adm</em>) are the expected costs of contacting the card holder and replacing the card if the transaction was correctly predicted as fraudulent, or reactivating it if the transaction was legitimate. Here we assume, for simplicity, that the administrative costs for both cases are identical.</p><p>The cost matrix below summarizes the costs assigned to the different classification results. The minority class, “fraudulent”, is defined as the positive class, and “legitimate” is defined as the negative class.</p><figure><img alt="Correcting Predicted Class Probabilities in Imbalanced Datasets" src="https://cdn-images-1.medium.com/max/589/0*2Z3xQdZ9-x5rOKg1.png" /><figcaption>Table 1: The cost matrix that shows the costs assigned to different classification results as obtained by a model for fraud detection. Correctly classified legitimate transactions bring no cost. Fraudulent transactions predicted as legitimate cost the amount of fraud. Transactions predicted as fraudulent bring administrative costs.</figcaption></figure><p>Based on this cost matrix, the total cost of the model is:</p><figure><img alt="Correcting Predicted Class Probabilities in Imbalanced Datasets" src="https://cdn-images-1.medium.com/max/592/0*i39mDNEdYuDOohAG.png" /></figure><p>Finally, the cost of the model will be compared to the amount of fraud. Cost reduction tells how much cost the classification model brings compared to the situation where we don’t use any model:</p><figure><img alt="Correcting Predicted Class Probabilities in Imbalanced Datasets" src="https://cdn-images-1.medium.com/max/416/0*wtm39R24uFTOW_FU.png" /></figure><h3>The workflow</h3><p>In this example we use the “Credit Card Fraud Detection” <a href="https://www.kaggle.com/samkirkiles/credit-card-fraud/data">dataset </a>provided by <a href="http://mlg.ulb.ac.be/">Worldline and the Machine Learning Group </a>of ULB (Université Libre de Bruxelles) on big data mining and fraud detection. The dataset contains 284 807 transactions made by European credit card holders during two days in September 2013. The dataset is highly imbalanced: 0.172 % (492 transactions) were fraudulent and the rest were normal. Other information on the transactions has been transformed into principal components.</p><p>The workflow in Figure 1 shows the overall process of reading the data, partitioning the data into a training and test set, resampling the data, training a classification model, predicting and correcting the class probabilities, and evaluating the cost reduction. We selected SMOTE as the resampling technique and logistic regression as the classification model. Here we estimate administrative costs to be 5 euros.</p><ul><li><a href="https://kni.me/w/0ufkiBeS8F8x6bhW">Download and inspect the Adjusting Class Probabilities after Resampling workflow from the KNIME Hub</a>.</li></ul><p>The workflow provides three different scenarios for the same data:</p><ol><li>training and applying the model using imbalanced data</li><li>training the model on balanced data and applying the model to imbalanced data without correcting the predicted class probabilities</li><li>training the model on balanced data and applying the model to imbalanced data where the predicted class probabilities have been corrected</li></ol><figure><img alt="Corrected Class Probabilities Workflow" src="https://cdn-images-1.medium.com/max/1024/0*ps0ugiUGZxbwaw_D.png" /><figcaption>Figure 1: Workflow that compares three ways of training and applying a classification model using imbalanced data. Firstly, the model training is done on imbalanced data. Secondly, the training set is resampled using SMOTE to make it balanced. Thirdly, the training set is resampled using SMOTE and predicted class probabilities are corrected based on the a priori class distribution of the data. The workflow is available on the <a href="https://kni.me/w/0ufkiBeS8F8x6bhW">KNIME Hub</a>.</figcaption></figure><h4>Estimating the cost for scenario 1 without resampling</h4><p>A logistic regression model provides these results:</p><figure><img alt="Correcting Predicted Class Probabilities in Imbalanced Datasets" src="https://cdn-images-1.medium.com/max/612/0*KdQ0x_q_MCJiRmZL.png" /><figcaption>Table 2: The confusion matrix, class statistics and estimated cost reduction obtained by a fraud detection model that was trained on imbalanced data. The cost reduction is evaluated using the formula in the “Evaluating the cost of a classification model” section.</figcaption></figure><p>The setup in this scenario provides good values for F-measure and Cohen’s Kappa statistics, but a relatively high False Negative Rate (40.82 %). This means that more than 40 % of the fraudulent transactions were not detected by the model — increasing the amount of fraud and therefore the cost of the model. The cost reduction of the model compared to not using any model is 42%.</p><h4>Estimating the cost for scenario 2 with resampling</h4><p>A logistic regression model trained on a balanced training set (oversampled using SMOTE) yields these results:</p><figure><img alt="Correcting Predicted Class Probabilities in Imbalanced Datasets" src="https://cdn-images-1.medium.com/max/610/0*crK3JJo_J0D_XSd3.png" /><figcaption>Table 3: The confusion matrix, class statistics and estimated cost obtained by a fraud detection model that was trained on an oversampled, balanced data.</figcaption></figure><p>The False Negative Rate is very low (12.24 %), which means that almost 90 % of the fraudulent transactions were detected by the model. However, there are a lot of “ <em>false alarms </em>” (391 legitimate transactions predicted as fraud) that increase the administrative costs. However, the cost reduction achieved by training the model on a balanced dataset is 64% — higher than what we could reach without resampling the training data. The same test set was used for both scenarios.</p><h4>Estimating the cost for scenario 3 with resampling and correcting the predicted class probabilities</h4><p>A logistic regression model trained on a balanced training set (oversampled using SMOTE) yields these results when the predicted probabilities have been corrected according to the a priori class distribution of the data:</p><figure><img alt="Correcting Predicted Class Probabilities in Imbalanced Datasets" src="https://cdn-images-1.medium.com/max/598/0*x1ppBeCEqizkj2nK.png" /><figcaption>Table 4: The confusion matrix, class statistics and estimated cost as obtained by a fraud detection model that was trained on an oversampled, balanced data, and where the predicted class probabilities were corrected according to the a priori class distribution.</figcaption></figure><p>As the results for this scenario in Table 4 show, correcting the predicted class probabilities leads to the best model of these three scenarios in terms of the greatest cost reduction.</p><p>In this scenario, where we train a classification model on an oversampled data and correct the predicted class probabilities according to the a priori class distribution in the data, we reach a cost reduction of 75 % compared to not using any model.</p><p>Of course, the cost reduction depends on the value of the administrative costs. Indeed, we tried this by changing the estimated administrative costs and found out that this last scenario can attain cost reduction as long as the administrative costs are 0.80 euros or more.</p><h3>Summary</h3><p>Often, when we train and apply a classification model, the interesting events in the data belong to the minority class and are therefore more difficult to find: fraudulent transactions among the masses of transactions, disease carriers among the healthy people, and so on.</p><p>From the point of view of the performance of a classification algorithm, it’s recommended to make the training data balanced. We can do this by resampling the training data. Now, the training of the model works better, but how about applying it to new data, which we suppose to be imbalanced? This setup leads to biased values for the predicted class probabilities, because the training set does not represent the test set or any new, unseen data.</p><p>Therefore, to obtain an optimal performance of a classification model together with reliable classification results, correcting the predicted class probabilities by the information on the a priori class distribution is recommended. As the use case in this blog post shows, this correction leads to better model performance and concrete profit.</p><p><strong>References</strong></p><ol><li>Marco Saerens, Patrice Latinne, and Christine Decaestecker. Adjusting the outputs of a classifier to new a priori probabilities: a simple procedure. <em>Neural computation </em>14(1):21–41, 2002.</li></ol><p>— — — — -</p><p>As previously published on the KNIME Blog: <a href="https://www.knime.com/blog/correcting-predicted-class-probabilities-in-imbalanced-datasets">https://www.knime.com/blog/correcting-predicted-class-probabilities-in-imbalanced-datasets</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dce2b14a013b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/low-code-for-advanced-data-science/from-modeling-to-scoring-correcting-predicted-class-probabilities-in-imbalanced-datasets-dce2b14a013b">From Modeling to Scoring: Correcting Predicted Class Probabilities in Imbalanced Datasets</a> was originally published in <a href="https://medium.com/low-code-for-advanced-data-science">Low Code for Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>