<?xml version="1.0" encoding="UTF-8"?>
<rss version='2.0' 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">
  <channel>
    <title>The Data Team @ The Data Lab</title>
    <description>&amp;nbsp;
Unlocking value from data
&amp;nbsp; 
Check out our sister blog: [_The Data Lab on Medium_](https://medium.com/the-data-lab)</description>
    <link>https://thedatateam.silvrback.com/feed</link>
    <atom:link href="https://thedatateam.silvrback.com/feed" rel="self" type="application/rss+xml"/>
    <category domain="thedatateam.silvrback.com">Content Management/Blog</category>
    <language>en-us</language>
      <pubDate>Thu, 09 May 2019 11:31:31 +0100</pubDate>
    <managingEditor>datascienceteam@thedatalab.com (The Data Team @ The Data Lab)</managingEditor>
      <item>
        <guid>https://thedatateam.silvrback.com/using-shiny-for-interactive-displays-of-health-data-the-scottish-burden-of-diseases#47110</guid>
          <pubDate>Thu, 09 May 2019 11:31:31 +0100</pubDate>
        <link>https://thedatateam.silvrback.com/using-shiny-for-interactive-displays-of-health-data-the-scottish-burden-of-diseases</link>
        <title>Using Shiny for interactive displays of health data: The Scottish Burden of Diseases</title>
        <description></description>
        <content:encoded><![CDATA[<p>The Accelerator programme run by <a href="https://www.thedatalab.com/">The Data Lab</a> between 19 April 2018 - 06 September 2018 was a Scottish Government collaborative project, open to employees of the Scottish Government, the Information Services Division, the National Records of Scotland and Registers of Scotland. Employees applying to take part had a background in statistics, economics, operational research and social research, and sought to improve their data skills across a variety of areas.</p>

<p>For instance, I mentored one of the applicants as part of this initiative - Maite Thrower (Senior Analyst from Public Health Intelligence, ISD within NHS / National Services Scotland), and supported her in her journey to learn R and Shiny in order to create insightful visalisations for the <a href="https://www.scotpho.org.uk/comparative-health/burden-of-disease/overview">Burden of disease in Scotland</a>, including over 100 conditions and injuries. Previously, the complex Scottish Burden of Disease data had been visualised using <a href="https://www.scotpho.org.uk/media/1733/sbod2016-overview-report-sept18.pdf#page=9">static graphs</a>, hence it was essential to transition to more powerful interactive visualisations via <a href="https://www.shinyapps.io/">Shiny</a>.</p>

<p>To understand this data, we need to focus on two key concepts / measures: the <strong>years lost of life</strong> (an estimate for how the extent to which someone’s life may have been cut short, due to an existing condition), and the <strong>years lived with disability</strong> (an estimate for how long a person has lived with the consequences of a condition). These measures are considered to be influenced by factors such as age, gender and the level of <a href="https://www2.gov.scot/Topics/Statistics/SIMD">deprivation in the area of living</a> - all ideally implemented as inputs in a Shiny app (but please see below for a similar solution implemented for the <a href="https://vizhub.healthdata.org/gbd-compare/"><em>Global</em> Burden of Disease data</a>, from The Institute for Health Metrics and Evaluation).</p>

<p><img alt="Silvrback blog image" class="sb_float_center" src="https://silvrback.s3.amazonaws.com/uploads/fd19f23c-df8e-4609-8e99-fe577cc44a4e/GlobalBurdenOfDisease.png" /></p>

<p>Maite describes her experience as participant in the Accelerator programme:</p>

<blockquote>
<p>I wanted to develop an interactive data visualisation for the Scottish Burden of diseases to present our results and design modern visualizations with the aim to reach a higher audience and increase the number of users that refer to our statistics and graphics in their reports and websites. […] Originally, I was going to produce a static tree map and one visualization but I managed, with the direction of the mentor from The Data Lab, to move to a higher level and produce the Shiny app. Public Health Scotland has agreed to fund further development of the interactive visualisation and to publish it in the <a href="https://www.scotpho.org.uk/">ScotPHO website</a>. I have also been presenting the results of the program to other teams in <a href="https://www.isdscotland.org/">ISD</a>.</p>
</blockquote>

<p>For my part, I really enjoyed working with Maite and seeing her progress over time, from the initial planning stages of the Accelerator programme, to when Maite was able to deliver a comprehensive interactive visualisation for the Scottish Burden of Diseases data, using R Shiny.</p>

<p>Maite’s interactive Shiny solution will be deployed soon - updates to follow. For the time being, you can access the mentorship material used throughout the Accelerator programme freely in the following GitHub repo:</p>

<blockquote>
<p>Constantinescu, A.C. (2018, August). Exploring the Scottish Burden of Diseases Data using R Shiny [R script]. Edinburgh, Scotland: The Data Lab Innovation Centre. Retrieved [Month] [Day], [Year], from <a href="https://github.com/TheDataLabScotland/Public_ScotGovAccelerator_2018">https://github.com/TheDataLabScotland/Public_ScotGovAccelerator_2018</a></p>
</blockquote>
]]></content:encoded>
      </item>
      <item>
        <guid>https://thedatateam.silvrback.com/tips-for-creating-interactive-visualisations-with-shiny#47104</guid>
          <pubDate>Wed, 08 May 2019 15:47:08 +0100</pubDate>
        <link>https://thedatateam.silvrback.com/tips-for-creating-interactive-visualisations-with-shiny</link>
        <title>Four tips for creating interactive visualisations with Shiny</title>
        <description></description>
        <content:encoded><![CDATA[<p>I’ve recently presented a toy Shiny app at the <a href="https://www.meetup.com/meetup-group-vBHbCmgh/events/259694171/">Edinburgh Data Visualization Meetup</a> to demonstrate how Shiny can be used to explore data interactively.</p>

<p>In my code-assisted walkthrough, I began by discussing the data used: a set of records detailing customer purchases made on Black Friday (i.e., each customer was given a unique ID, which was repeated in long format in the case of multiple purchases). Both the customers and the items purchased are described along various dimensions (e.g., customer city type, or item category etc.). You can find more details about this dataset on Kaggle <a href="https://www.kaggle.com/mehdidag/black-friday">here</a>.</p>

<p>After a basic set of data manipulations using <code>data.table</code> in R (see code below for details), the data was ready to be visualised with <code>ggplot2</code>. It is at this stage that I can share my first tip for designing Shiny apps:</p>

<h1 id="tip-1">Tip #1</h1>

<p>Consider starting with a simple, <strong>static visualisation</strong> (rather than building your Shiny app directly). This strategy helps to streamline the design process and deal with any potential problems one at a time. Starting with a static plot can also help to identify the best visualisation that can highlight the particular relationships you are trying to show in your data.</p>
<div class="highlight"><pre><span></span><span class="kn">library</span><span class="p">(</span> data.table <span class="p">)</span>
<span class="kn">library</span><span class="p">(</span> ggplot2 <span class="p">)</span>
<span class="kn">library</span><span class="p">(</span> viridis <span class="p">)</span>

BFsales <span class="o">&lt;-</span> fread<span class="p">(</span> <span class="s">&quot;BlackFriday.csv&quot;</span> <span class="p">)</span>

BFsales<span class="p">[</span> <span class="p">,</span> User_ID <span class="o">:=</span> <span class="kp">as.factor</span><span class="p">(</span> User_ID <span class="p">)</span> <span class="p">]</span>
BFsales<span class="p">[</span> <span class="p">,</span> Product_ID <span class="o">:=</span> <span class="kp">as.factor</span><span class="p">(</span> Product_ID <span class="p">)</span> <span class="p">]</span>
BFsales<span class="p">[</span> <span class="p">,</span> Occupation <span class="o">:=</span> <span class="kp">as.factor</span><span class="p">(</span> Occupation <span class="p">)</span> <span class="p">]</span>
BFsales<span class="p">[</span> <span class="p">,</span> Gender <span class="o">:=</span> <span class="kp">as.factor</span><span class="p">(</span> Gender <span class="p">)</span> <span class="p">]</span>
<span class="kp">levels</span><span class="p">(</span> BFsales<span class="o">$</span>Gender <span class="p">)</span> <span class="o">&lt;-</span> <span class="kt">c</span><span class="p">(</span> <span class="s">&quot;Female&quot;</span><span class="p">,</span> <span class="s">&quot;Male&quot;</span> <span class="p">)</span>

BFsales<span class="p">[</span> <span class="p">,</span> Stay_In_Current_City_Years <span class="o">:=</span> <span class="kp">ordered</span><span class="p">(</span> Stay_In_Current_City_Years<span class="p">,</span> levels <span class="o">=</span> <span class="kp">sort</span><span class="p">(</span> <span class="kp">unique</span><span class="p">(</span> Stay_In_Current_City_Years <span class="p">)</span> <span class="p">)</span> <span class="p">)</span> <span class="p">]</span>

BFsales<span class="p">[</span> <span class="p">,</span> Marital_Status <span class="o">:=</span> <span class="kp">factor</span><span class="p">(</span> Marital_Status <span class="p">)</span> <span class="p">]</span>
<span class="kp">levels</span><span class="p">(</span> BFsales<span class="o">$</span>Marital_Status <span class="p">)</span> <span class="o">&lt;-</span> <span class="kt">c</span><span class="p">(</span> <span class="s">&quot;Married&quot;</span><span class="p">,</span> <span class="s">&quot;Single&quot;</span> <span class="p">)</span>

BFsales<span class="p">[</span> <span class="p">,</span> Product_Category_1 <span class="o">:=</span> <span class="kp">as.factor</span><span class="p">(</span> Product_Category_1 <span class="p">)</span> <span class="p">]</span>
BFsales<span class="p">[</span> <span class="p">,</span> Product_Category_2 <span class="o">:=</span> <span class="kp">as.factor</span><span class="p">(</span> Product_Category_2 <span class="p">)</span> <span class="p">]</span>
BFsales<span class="p">[</span> <span class="p">,</span> Product_Category_3 <span class="o">:=</span> <span class="kp">as.factor</span><span class="p">(</span> Product_Category_3 <span class="p">)</span> <span class="p">]</span>

BFsales<span class="p">[</span> <span class="p">,</span> Age <span class="o">:=</span> <span class="kp">ifelse</span><span class="p">(</span> Age <span class="o">==</span> <span class="s">&quot;0-17&quot;</span><span class="p">,</span> <span class="s">&quot;Under 17&quot;</span><span class="p">,</span> Age <span class="p">)</span> <span class="p">]</span>
BFsales<span class="p">[</span> <span class="p">,</span> Age <span class="o">:=</span> <span class="kp">ifelse</span><span class="p">(</span> Age <span class="o">==</span> <span class="s">&quot;55+&quot;</span><span class="p">,</span> <span class="s">&quot;Over 55&quot;</span><span class="p">,</span> Age <span class="p">)</span> <span class="p">]</span>
BFsales<span class="p">[</span> <span class="p">,</span> Age <span class="o">:=</span> <span class="kp">ordered</span><span class="p">(</span> Age<span class="p">,</span> levels <span class="o">=</span> <span class="kt">c</span><span class="p">(</span> <span class="s">&quot;Under 17&quot;</span><span class="p">,</span> <span class="s">&quot;18-25&quot;</span><span class="p">,</span> <span class="s">&quot;26-35&quot;</span><span class="p">,</span>  <span class="s">&quot;36-45&quot;</span><span class="p">,</span> <span class="s">&quot;46-50&quot;</span><span class="p">,</span> <span class="s">&quot;51-55&quot;</span><span class="p">,</span> <span class="s">&quot;Over 55&quot;</span> <span class="p">)</span> <span class="p">)</span> <span class="p">]</span>


<span class="c1"># How much did *individuals* spend on average depending on city category and age?</span>
purchase_by_age_agr <span class="o">&lt;-</span> aggregate<span class="p">(</span> Purchase <span class="o">~</span> User_ID <span class="o">+</span> Age <span class="o">+</span> City_Category<span class="p">,</span> data <span class="o">=</span> BFsales<span class="p">,</span> FUN <span class="o">=</span> sum <span class="p">)</span>
purchase_by_age_agr <span class="o">&lt;-</span> aggregate<span class="p">(</span> Purchase <span class="o">~</span> Age <span class="o">+</span> City_Category<span class="p">,</span> data <span class="o">=</span> purchase_by_age_agr<span class="p">,</span> FUN <span class="o">=</span> mean <span class="p">)</span>

ggplot<span class="p">(</span> purchase_by_age_agr<span class="p">,</span> 
        aes<span class="p">(</span> x <span class="o">=</span> City_Category<span class="p">,</span> y <span class="o">=</span> Purchase<span class="p">,</span> group <span class="o">=</span> Age<span class="p">,</span> color <span class="o">=</span> Age <span class="p">)</span> <span class="p">)</span> <span class="o">+</span> 
  geom_point<span class="p">(</span> size <span class="o">=</span> <span class="m">2.5</span> <span class="p">)</span> <span class="o">+</span>
  geom_line<span class="p">(</span> lwd <span class="o">=</span> <span class="m">1.5</span> <span class="p">)</span> <span class="o">+</span>
  scale_color_viridis_d<span class="p">(</span> direction <span class="o">=</span> <span class="m">-1</span><span class="p">,</span> begin <span class="o">=</span> <span class="m">0.20</span><span class="p">,</span> end <span class="o">=</span> <span class="m">0.85</span><span class="p">,</span> option <span class="o">=</span> <span class="s">&quot;B&quot;</span> <span class="p">)</span> <span class="o">+</span>
  labs<span class="p">(</span> x <span class="o">=</span> <span class="s">&quot;City category&quot;</span><span class="p">,</span>
        color <span class="o">=</span> <span class="s">&quot;Age band&quot;</span> <span class="p">)</span> <span class="o">+</span>
  ggtitle<span class="p">(</span> <span class="s">&quot;Average spend according to customer age and city type&quot;</span><span class="p">,</span>
           subtitle <span class="o">=</span> <span class="s">&quot;- Add note here -&quot;</span> <span class="p">)</span>
</pre></div>
<p>Following the R code above, this is the plot you would get:</p>

<p><img alt="Silvrback blog image" class="sb_float_center" src="https://silvrback.s3.amazonaws.com/uploads/120ff562-0927-4457-96f8-604e48398062/StaticVisualisation.png" /></p>

<p>After creating this static prototype, we can now start thinking about how to generalise it and integrate elements of interactivity (input menus) via Shiny. This would help us to investigate questions such as whether the product category affects the relationship shown, or whether customers’ marital status, gender, or occupation have any influence as well? Tackling questions such as these with Shiny is a more powerful and elegant option, relative to generating large numbers of individual plots for each such scenario.</p>

<p>So, how can we move to Shiny from here? I won’t go into the details here (which I have done instead at the <a href="https://www.meetup.com/meetup-group-vBHbCmgh/events/259694171/">meetup</a>), since several great tutorials are already available - notably <a href="https://deanattali.com/blog/building-shiny-apps-tutorial/">Dean Attali’s</a>. You can also check out other important resources / documentation pages, e.g., the RStudio tutorials <a href="http://rstudio.github.io/shiny/tutorial/">here</a> and <a href="https://shiny.rstudio.com/articles">here</a>. You can also have a look at the Shiny <a href="https://shiny.rstudio.com/gallery/">app gallery</a> to get inspiration and choose a format that suits your needs.</p>

<h1 id="tip-2">Tip #2</h1>

<ul>
<li>Think about the initial state of the app: should the view contain full data? If so, make sure the default options for the inputs cover <strong>all</strong> the options that exist in your data (e.g., a menu for selecting binary gender should have both checkboxes ticked by default, but users can later opt for looking at a single gender if they so wish). A less obvious case is when missing values exist: these would be filtered out automatically by input menus with specific options, but is this something you want handled in this way?</li>
</ul>

<h1 id="tip-3">Tip #3</h1>

<ul>
<li>How should the app handle multiple connected sessions? It might be a good idea to have larger data objects / constants visible across all connected sessions for efficiency. It is worth thinking about this in more detail and setting up your app according to <a href="http://rstudio.github.io/shiny/tutorial/#scoping">Scoping guidance</a>.</li>
</ul>

<h1 id="tip-4">Tip #4</h1>

<ul>
<li>Make sure you are setting up the correct dependencies between reactive layers in your Shiny app: to make full use of Shiny’s clever reactive system, you need to pay special attention to setting up the correct links between objects. A great post on <a href="https://shiny.rstudio.com/articles/execution-scheduling.html">Execution scheduling</a> will go a long way towards clarifying this.</li>
</ul>

<p>If you are curious about Black Friday sales, you can see the Shiny app in action below (click the image to visit the app):</p>

<p><a href="https://thedatalab.shinyapps.io/BlackFridayShinyApp/"><img alt="Silvrback blog image" class="sb_float_center" src="https://silvrback.s3.amazonaws.com/uploads/88f40adf-26ae-4f97-965b-dce3c4562bfc/BlackFridayAppPreview.png" /></a></p>

<p>The code controlling the app’s behaviour can be found on GitHub <a href="https://github.com/TheDataLabScotland/BlackFridayShinyApp/blob/master/app.R">here</a>.</p>

<h1 id="further-practice">Further practice</h1>

<p>If you like, feel free to build on my <a href="https://github.com/TheDataLabScotland/BlackFridayShinyApp/blob/master/app.R">example</a> further. I’ve left out various menus that could still be included. So as practice, you could:</p>

<ul>
<li>Tweak the UI to include suitable inputs for:

<ul>
<li>Occupation</li>
<li>Marital status</li>
<li>Product category 2 or 3 (careful about handling missing data here)</li>
</ul></li>
<li>Update the server function to use these newly-added inputs!</li>
</ul>
]]></content:encoded>
      </item>
      <item>
        <guid>https://thedatateam.silvrback.com/interactive-intelligence#47002</guid>
          <pubDate>Mon, 22 Apr 2019 12:25:39 +0100</pubDate>
        <link>https://thedatateam.silvrback.com/interactive-intelligence</link>
        <title>Interactive Intelligence</title>
        <description>Human-In-The-Loop Intelligence</description>
        <content:encoded><![CDATA[<p>Artificial Intelligence and Machine Learning has captured a large share of academic and industry attention during recent years, both in terms of new capabilities and the implications to society. Many state-of-the-art techniques are able to provide important capabilities for different fields, yet we are far from creating artificial general intelligence. Human-In-The-Loop (HITL) is a branch of Artificial Intelligence (AI) where natural (human) and Artificial (machine) intelligence combine to create more accurate AI algorithms. In such systems, humans are involved in every stage of the algorithm’s output by creating a feedback loop from training to testing stages resulting in a more accurate model. This approach is a blend of supervised learning (using labelled training data) and active learning (interacting with users for feedback).</p>

<p>Recent advances in the field of AI have given rise to techniques such as active learning and co-operative learning . The back bone of any machine learning algorithm is data, and usually these datasets are unlabelled (e.g. Images). In the training stage, a human is required to label this dataset (the output, e.g. cat or dog) manually. This data is then fed to the machine learning model to train; this is referred to as supervised learning. In this technique the algorithms learn from labelled data to then predict unseen cases. Using what we already know we can go deeper and create more sophisticated techniques to uncover other insights and features that exist in the training dataset with the goal of getting more accurate and automated results.</p>

<p>As can be seen in the graph below, in the cases when the AI classifier is not confident about its output the need for human intervention arises which in turn leads to a more accurate output.</p>

<p><img alt="Silvrback blog image " src="https://silvrback.s3.amazonaws.com/uploads/a8b75655-e84c-4c4a-bec6-bd189a841bdc/humaintheloop.png" /></p>

<p>In the testing and evaluation phase, humans’ and machines’ expertise are combined by allowing the human to correct any inaccurate results that has been produced. Specifically, the human in this case will correct the labels that the machine was not able to spot with a high accuracy (i.e. classified a dog for a cat). The same approach is carried out by the human when the machine is overly confident about a wrong prediction. In each iteration the performance of the algorithm will increase allowing the path towards automated lifelong learning by mitigating the need for future human intervention. At the end of such work the results are then sent to a domain expert to make decisions that enables bigger impact. For example, in a hospital, images of tumours could be assessed by the model, comparing new images with all previous records and once the output is produced it could then be sent to a cancer expert to further classify and feedback to the model.</p>

<p>Allowing HITL will significantly change the way business workflows are carried out at scale by creating a pipeline that includes data collection, model training, testing, deployment and maintenance. However, much work on roles and definitions of HITL is needed to create an impactful Machine Learning ecosystem. Knowing what the most efficient ways are to incorporate human-machine know-how will require hybrid processes in order to enable future paths for automated systems which extend beyond Machine Learning workflows to other fields such as robotics. This is a very exciting time to be involved in this field as industry and academia are pushing the limits further every day.</p>
]]></content:encoded>
      </item>
  </channel>
</rss>