Data Science Toolbox: How to use Julia with Tableau

R allows Tableau to execute Julia code on the fly
R allows Tableau to execute Julia code on the fly

Michael, a data scientist, who is working for a German railway and logistics company, recently told me during an FATUG Meetup that he loves Tableau’s R and Pyhton integration. As he continued, he raised the raised the question for using functions they have written in Julia. Julia, a high-level dynamic programming language for high-performance numerical analysis, is an integral part of newly developed data strategy in the Michael’s organization.

Tableau, however, does not come with native support for Julia. I didn’t want to keep Michael’s team down and was looking for an alternative way to integrate Julia with Tableau.

This solution is working flawless in a production environment since several months. In this tutorial I’m going to walk you through the installation and connecting Tableau with R and Julia. I will also give you an example of calling a Julia statement from Tableau to calculate the sphere volume.

1. Install Julia and add PATH variable

You can download Julia from julialang.org. Add Julia’s installation path to the PATH environment variable.

2. Install R, XRJulia and RServe

You can download base R from r-project.org. Next, invoke R from the terminal to install the XRJulia and the RServe packages:

> install.packages("XRJulia")
> install.packages("Rserve")

XRJulia provides an interface from R to Julia. RServe is a TCP/IP server which allows Tableau to use facilities of R.

3. Load libraries and start RServe

After packages are successfully installed, we load them and run RServe:

> library(XRJulia)
> library(Rserve)
> Rserve()

Make sure to repeat this step everytime you restart your R session.

4. Connecting Tableau to RServe

Now let’s open the Help menu in Tableau Desktop and choose Settings and Performance >Manage External Service connection to open the External Service Connection dialog box:

TC17 External Service Connection

Enter a server name using a domain or an IP address and specify a port. Port 6311 is the default port used by Rserve. Take a look on my R tutorial to learn more about Tableau’s R integration.

5. Adding Julia code to a Calculated Field

You can invoke Calculated Field functions called SCRIPT_STR, SCRIPT_REAL, SCRIPT_BOOL, and SCRIPT_INT to embed your Julia code in Tableau, such as this simple snippet that calculates sphere volume:

6. Use Calculated Field in Tableau

You can now use your Julia calculation as an alternate Calculated Field in your Tableau worksheet:

Using Julia within calculations in Tableau (click to enlarge)
Using Julia calculations within Tableau (click to enlarge)

Feel free to download the Tableau Packaged Workbook (twbx) here.

Further reading: Mastering Julia

Tableau Conference TC17 Sneak Peek: Integrating Julia for Advanced Analytics

Using Julia within calculations in Tableau (click to enlarge)
Using Julia calculations within Tableau (click to enlarge)

We have already seen some love from Tableau for R and Python, boosting Tableau’s Advanced Analytics capabilities.

So what is the next big thing for our Data Science Rockstars? Julia!

Who is Julia?

JuliaJulia logo is a high-level dynamic programming language introduced in 2012. Designed to address the needs of high-performance numerical analysis its syntax is very similar to MATLAB. If you are used to MATLAB, you will be very quick to get on track with Julia.

Compared to R and Python, Julia is significantly faster (close to C and FORTRAN, see benchmark). Based on Tableau’s R integration, Julia is a fantastic addition to Tableau’s Advanced Analytics stack and to your data science toolbox.

Where can I learn more?

Do you want to learn more about Advanced Analytics and how to leverage Tableau with R, Python and Julia? Meet me at the 2017 Tableau Conferences in London, Berlin or Las Vegas and join my Advanced Analytics sessions:

Will there be an online tutorial?

Yes, of course! I published tutorials for R and Python on this blog. And I will also publish a Julia tutorial soon. Feel free to follow me on Twitter @xlth, and leave me your feedback/suggestions in the comment section below.

Further reading: Mastering Julia

A German translation of this post is published on the official Tableau blog: Tableau Conference On Tour Sneak Peek: Julia-Integration für Advanced Analytics

[Update 11 Oct 2017]: The Julia+Tableau tutorial blog post is now published.

Price and Sentiment Analysis: Why is Bitcoin Going Down?

Bitcoin Price and Sentiment Analysis with variable Moving Average: click to open interactive Tableau dashboard with annotations
Bitcoin Price and Sentiment Analysis with variable Moving Average: click to open interactive Tableau dashboard with annotations

Bitcoin has become one of the trendy investment assets in the recent years. Whenever bitcoin prices approach historical highs, every investor should watch the currency closely. Bitcoin rallied by more than 20% in the first days of 2017, crossing the $1000 mark for the first time since November 2013.

As many experienced bitcoin traders will remember, the first $1000 peak was a case of obvious over exuberance. Bitcoin was hot, plenty of money was pouring into it. Bitcoin investors got too excited, causing a price surge. Prices then rebounded and suffered a long-term collapse shortly after.

Moving Average Convergence/Divergence Indicator

Many traders rely on a Moving Average Convergence/Divergence (MACD) indicator. The MACD is a measure of the convergence and divergence between two EMAs (usually 12 and 26 days) and is calculated by subtracting the two of them. The signal line is constructed by creating an EMA (usually 10 days) of the signal line.

The signal line crossing the MACD from above is a buy signal. The signal line crossing the MACD from below is a sell signal. Relying only on momentum-based indicators (such as the MACD) and optimization-based models, however, will most certainly fail to indicate heavy price drops, as the drop in late 2016.

Predicting Fear with Sentiment Analysis

In late 2016 a lot of people began to pour money into bitcoin again. This time because they were worried that stock markets and other assets were due for a drop. For investors, it is essential to figure out whether or not these fears are actually founded. However, such “safe assets” are prone to suffering from bubbles. People get scared, get invested into gold, or bitcoin, then realize that their fears were unfounded. As a result bitcoin prices could plummet.

So how to catch emotions such as fear in advance? Twitter is a valuable source of information and emotion. It certainly influences the stock market and can help to predict the market. Sentiment analysis can lead price movements by up to two days. Negative sentiment, however, is reflected in the market much more than positive sentiment. This is probably because most people tweet positive things about bitcoins most of the time. Even more positive news occurred after breaking the $1000 barrier.

This content is part of the session “Price and Sentiment Analysis: Why is Bitcoin Going Down?” that I deliver at the Frankfurt Bitcoin Colloquium. Have a look on my upcoming sessions!

[Update 14 Jun 2017]: Axis for Moving Average adjusted. Relative Date selector added with last 6 month as default. Screenshot updated.

Feel free to share the Bitcoin Price and Sentiment Analysis dashboard, which is also featured as Viz of the Day on Tableau Public:

TabPy Tutorial: Integrating Python with Tableau for Advanced Analytics

TabPy allows Tableau to execute Python code on the fly
TabPy allows Tableau to execute Python code on the fly

In 2013 Tableau introduced the R Integration, the ability to call R scripts in calculated fields. This opened up possibilities such as K-means clustering, Random Forest models and sentiment analysis. With the release of Tableau 10.2, we can enjoy a new, fancy addition to this feature: the Python Integration through TabPy, the Tableau Python Server.

Python is a widely used general-purpose programming language, popular among academia and industry alike. It provides a wide variety of statistical and machine learning techniques, and is highly extensible. Together, Python and Tableau is the data science dream team to cover any organization’s data analysis needs.

In this tutorial I’m going to walk you through the installation and connecting Tableau with TabPy. I will also give you an example of calling a Python function from Tableau to calculate correlation coefficients for a trellis chart.

1. Install and start Python and TabPy

Start by clicking on the Clone or download button in the upper right corner of the TabPy repository page, downloading the zip file and extracting it.

TabPy download via GitHub web page

Protip: If you are familar with Git, you can download TabPy directly from the repository:

> git clone git://github.com/tableau/TabPy

TabPy download via Git command line interface

Within the TabPy directory, execute setup.sh (or setup.bat if you are on Windows). This script downloads and installs Python, TabPy and all necessary dependencies. After completion, TabPy is starting up and listens on port 9004.

2. Connecting Tableau to TabPy

In Tableau 10.2, a connection to TabPy can be added in Help > Settings and Performance > Manage External Service Connection:

Tableau main menu
Tableau main menu

Set port to 9004:

External Service Connection dialogue
External Service Connection dialogue

3. Adding Python code to a Calculated Field

You can invoke Calculated Field functions called SCRIPT_STR, SCRIPT_REAL, SCRIPT_BOOL, and SCRIPT_INT to embed your Python script in Tableau:

Python script within Tableau
Python script within Tableau

4. Use Calculated Field in Tableau

Now you can use your Python calculation as Calculated Field in your Tableau worksheet:

Tableau workbook featuring a Python calculation
Tableau workbook featuring a Python calculation

Feel free to download the Tableau Packaged Workbook (twbx) here.

[Update 3 Jan 2017]: Translated to Japanese by Tomohiro Iwahashi: Tableau + Python 連携 (Tabpy) を使ってみよう!

[Update 30 Mar 2017]: A German translation of this post is published on the official Tableau blog: TabPy Tutorial: Integration von Python mit Tableau für Advanced Analytics

Predictive Maintenance hilft Ihnen Wartungsmaßnahmen effizient zu gestalten

Screenshot
Predictive Maintenance zeigt verbleibende Nutzungsdauer von Aufzügen der Deutschen Bahn: klicken, um interaktives Dashboard zu öffnen

Nicht nur die Fertigungskosten lassen sich mit Predictive Maintenance senken. Auch im Dienstleistungsbereich entsteht durch Vorhersagen enormes Optimierungspotential. Im wesentlichen lassen sich die Fragestellungen, die im Rahmen von Predictive Maintenance gestellt werden, in drei Klassen einteilen:

  • Wie hoch ist die Wahrscheinlichkeit, dass ein Gerät in naher Zukunft ausfällt?
  • Was sind die Ursachen von Ausfällen und welche Instandhaltungsmaßnahmen sollten durchgeführt werden, um diese Probleme zu beheben?
  • Wie lang ist die Nutzungsdauer eines Gerätes?

Ein Beispiel, das die Frage der Nutzungsdauer in den Mittelpunkt rückt, zeigt das Dashboard Predictive Maintenance Deutsche Bahn Elevators. Dieses Dashboard sagt voraus, wie lange Aufzüge noch ohne Wartung auskommen (“Rest of Useful Life”). Mit dem Parameter “Material Wear Off” lässt sich zudem der Grad der Abnutzung beeinflussen.

Die visualisierten Sensordaten erlauben darüber hinaus die Möglichkeit Anomalien zu entdecken. Hier lassen sich mit den Parametern “Primary Sensor” und “Secondary Sensor” verschiedene Kombinationen analysieren. In der “Setting Matrix” werden die verschiedene Einstellungen, die beim Betreiben der Aufzüge angewandt werden zusammengefasst.

Details zu den Aufzügen werden im Tooltip angezeigt. In diesen Tooltips lassen sich darüber hinaus Wartungsaufträge via Twitter triggern:

 

Anstatt auf eine Störung zu reagieren, können Servicetechniker somit auf Vorhersagen zurückgreifen. Damit agieren sie bereits vor einem Ausfall des Aufzugs entsprechend. Techniker sind somit in der Lage einen Aufzug aus der Ferne in den Diagnosemodus zu versetzen und ihn auf einer bestimmten Etage zu parken. All dies führt zu weniger Anfahrtszeiten, gesteigerter Effizienz und geringeren Kosten.

Dieses und weitere Beispiele zeige ich auf meinem Vortrag “Industry 4.0: Self Service BI and Predictive Maintenance“ im Rahmen des IBI Symposium am 17. November 2016 in Stuttgart.

[Update 24 Mar 2017]: Das Predictive Maintenance Dashboard wird außerdem auf der CeBIT 2017 im Rahmen der “neuen datenbasierten Geschäftsmodelle und Big Data bei der DB” vorgestellt: