How to enable Multi-Language Sentiment Analysis with R

Have you seen how easy it is to integrate sentiment analysis in your Tableau dashboard – if your text is in English?

Until now the sentiment package for R only worked with English text. Today, I released version 1.0 of the sentiment package on GitHub that features multi-language support. In order to perform sentiment analysis with German text, just add the parameter language="german" as shown in this example:

Demo showing Multi-Language Sentiment Analysis with English and German text
Demo showing Multi-Language Sentiment Analysis with English and German text

The new code allows you to add any language. So far, I started to prepare German sentiment files. French and Spanish sentiment files are on my to-do list.

R You Ready For Advanced Analytics at #data16

Tableau Conference: "What is Advanced Analytics?"
Tableau Conference: „What is Advanced Analytics?“

The main goal of Advanced Analytics is to help organizations make smarter decisions for better business outcomes.

Only a few years ago, Advanced Analytics was based almost entirely on a complex tool chain and plenty of scripting in Gnuplot, Python and R. Today, Tableau enables us to analyze our data at the speed of thought, to connect to our data sources in seconds, to add dimensions and measures on the canvas by dragging and dropping, and to get insights faster than ever before.

However, R still comes in very handy when we want to enrich Tableau’s Visual Analytics approach with advanced features that enables us to ask questions along the entire Analytics stack:

  1. Descriptive Analytics describes what happened, characterized by traditional business intelligence (BI). E.g. visualizations and dashboards to show profit per store, per product segment, or per region.

  2. Diagnostic Analytics, which is also known as Business Analytics, looks into why something is happening, and is characterized by reports to further „slice and dice“ and drill-down data. It answers the questions raised by Descriptive Analytics, such as why did sales go down in a particular region.

  3. Predictive analytics determines what might happen in future („What might happen?“), and needs larger domain expertise and tool set (i.e. Tableau + R). E.g. regression analysis, and forecasting which product segments are likely to perform better in next quarter.

  4. Prescriptive Analytics identifies the actions required in order to influence particular outcome („What should I do?“). E.g. portfolio optimization, and recommendation engines to answer which customer segment shall be targeted next quarter to improve profitability.

  5. Semantic Analytics examines data or content to identify the meaning („What does it mean?“), and suggests what you are looking for and provides a richer response. E.g. sentiment analysis and Latent Semantic Indexing to understand social media streams.

Do you want to learn more about Advanced Analytics and how to leverage Tableau with R? Meet me at the Tableau Conference in Munich (5-7 July) where I deliver the session „R You Ready For Advanced Analytics“.

"Analytics is essential for any competitive strategy"
„Analytics is essential for any competitive strategy“ (further reading: data science + strategy)

Speaking at Conferences and Company Events

I love to share digital strategies and visions with organizations and startups. I also speak regularly at conferences and company events.

Selected events (last updated in Jan 2018):

  1. Hyper Kickoff Event: 5th Frankfurt Analytics + Tableau User Group Meetup„, Tableau Office, Frankfurt, 18 January 2018
  2. Smart Mobility: 4th Frankfurt Analytics + Tableau User Group Meetup„, DB Systel Skydeck, Frankfurt, 13 December 2017
  3. Digital Transformation: How to Build an Analytics-Driven Culture„, Executive Talk, Frankfurt School of Finance & Management, Frankfurt, 8 December 2017
  4. Upcoming Features and the Tableau Roadmap„, The Future of Enterprise Analytics, Hilton Frankfurt Airport, Zürich, 6 December 2017
  5. Upcoming Features and the Tableau Roadmap„, The Future of Enterprise Analytics, Lindner Congress Hotel, Zürich, 14 November 2017
  6. Aligning Data Science and Digital Transformation„, Frankfurt Big Data Lab, Goethe-Universität, Frankfurt, 9 November 2017
  7. Upcoming Features and the Tableau Roadmap„, The Future of Enterprise Analytics, Credit Suisse, Zürich, 1 November 2017
  8. Building an Enterprise Big Data & Advanced Analytics Strategy„, Data Driven Banking Forum, Frankfurt, 25 October 2017
  9. Data Science in Mobility and Logistics„, Design the Smart Mobility – ITS Hackathon, Logistik-Initiative Hamburg, Hamburg, 20-21 October 2017
  10. 3rd Frankfurt Analytics + Tableau User Group Meetup„, Capgemini Office, Frankfurt, 17 October 2017
  11. Social Media and the Customer-centric Data Strategy„, Tableau Conference On Tour, Berlin, 12 September 2017
  12. 2nd Frankfurt Analytics + Tableau User Group Meetup„, Tableau Office, Frankfurt, 28 August 2017
  13. Advanced Analytics School„, Accenture Campus, Kronberg, 25 April-3 May 2017
  14. Aligning Data Science and Digital Transformation„, Accenture Tableau Day, Kronberg, 7 April 2017
  15. Neue datenbasierte Geschäftsmodelle und Big Data„, CeBIT 2017, Hanover, 20-24 March 2017
  16. Top 10 Business Intelligence Trends 2017„, Tableau Webinar, Frankfurt, 21 February 2017
  17. Price and Sentiment Analysis: Why is Bitcoin Going Down?„, Frankfurt Bitcoin Colloquium, Goethe-Universität, Frankfurt, 8 February 2017
  18. Data Science in Mobility and Logistics„, DB Open Data Hackathon, Deutsche Bahn mindbox, Berlin, 16-17 December 2016
  19. Industry 4.0: Self Service BI and Predictive Maintenance„, Institut für Business Intelligence (IBI) Symposium, Stuttgart, 17 November 2016
  20. Why are Advanced Analytics essential for your Data Strategy„, DGI-Praxistage, Goethe-Universität, Frankfurt, 10-11 November 2016
  21. Einsatz im Portfoliomanagement, Risikoanalysen & Reporting„, Tableau & Banking Day, Frankfurt, 8 November 2016
  22. 3 Essential Components to Building a Data Strategy„, Telekom Big Data Days, Frankfurt, 23 September 2016
  23. R You Ready For Advanced Analytics„, Tableau Conference On Tour, Munich, 6 July 2016
  24. Boost your Business with Social Media„, Twitter for Business Tweetup, Deutsche Bahn, Frankfurt, 28 June 2016
  25. Insights from Sensor Data (IoT)„, Accenture Analytics Innovation Day, Kronberg, 24 Juni 2016
  26. Financial Analytics with Tableau„, Sparkassen Future Day, Berlin, 12 May 2016
  27. Financial Analytics with Tableau„, Informatica Financial Services Day, Frankfurt, 11 May 2016
  28. Sentiment Analysis in Tableau using R„, Predictive Analytics Meetup, FinTech Incubator, Frankfurt, 28 April 2016
  29. Why is Data Science Important„, DataFest Germany, LMU, Munich, 1-3 April 2016
  30. Echtzeit-Analysen von Maschinendaten und externen Datenquellen„, CeBIT 2016, Hanover, 14-18 March 2016
  31. Analytics for Everyone, Everywhere, Anytime„, Tableau Experience, Munich, 18 November 2015
  32. Big Data Analytics at Capgemini„, Capgemini, Offenbach, 14 November 2014
  33. Intercultural Aspects for Offshore Projects„, Capgemini, Düsseldorf, 25 July 2014
  34. BI Sourcing Project at Deutsche Telekom„, Capgemini, Offenbach, 28 September 2012
  35. Big Data Analytics in High-Energy Physics„, CERN, Geneva, 23 May 2012
  36. The Expanding Universe of Big Data„, CERN, Geneva, 10 March 2011

Attending an event? Check out the Tableau Event Resources page.

How to implement Sentiment Analysis in Tableau using R

Interactive sentiment analysis with Tableau using R
Interactive sentiment analysis with Tableau using R

In my previous post I highlighted Tableau’s text mining capabilities, resulting in fancy visuals such as word clouds:

Today I’d like to follow up on this and show how to implement sentiment analysis in Tableau using Tableau’s R integration. Some of the many uses of social media analytics is sentiment analysis where we evaluate whether posts on a specific issue are positive, neutral, or negative (polarity), and which emotion in predominant.

What do customers like or dislike about your products? How do people perceive your brand compared to last year?

In order to answer such questions in Tableau, we need to install an R package that is capable of performing the sentiment analysis. In the following example we use an extended version of the sentiment package, which was initiated by Timothy P. Jurka.

The sentiment package requires the tm and Rstem packages, so make sure that they are installed properly. Execute these commands in your R console to install sentiment from GitHub (see alternative way to install at the end of this blog post):


install.packages("devtools")
library(devtools)
install_github("aloth/sentiment/sentiment")

The sentiment package offers two functions, which can be easily called from calculated fields in Tableau:

Screenshot 2016-01-31 15.25.24 crop

The function get_polarity returns „positive“, „neutral“, or „negative“:


SCRIPT_STR('
library(sentiment)
get_polarity(.arg1, algorithm = "bayes")
'
, ATTR([Tweet Text]))

The function get_emotion returns „anger“, „disgust“, „fear“, „joy“, „sadness“, „surprise“, or „NA“:


SCRIPT_STR('
library(sentiment)
get_emotion(.arg1, algorithm = "bayes")
'
, ATTR([Tweet Text]))

The sentiment package follows a lexicon based approach and comes with two files emotions_english.csv.gz (source and structure) and subjectivity_english.csv.gz (source and structure). Both files contain word lists in English and are stored in the R package library under /sentiment/data directory.

If text is incorrectly classified, you could easily fix this issue by extending these two files. If your aim is to analyze text other than English, you need to create word lists for the target language. Kindly share them in the comments!

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

Update 11 Aug 2016: If you are having trouble with install_github, try to install directly form this website:


install.packages("Rcpp")
install.packages("https://alexloth.com/utils/sentiment/current/sentiment.zip",repos=NULL)

How to perform Text Mining at the Speed of Thought directly in Tableau

Interactive real-time text mining with Tableau Desktop 9.2
Interactive real-time text mining with Tableau Desktop

Tableau is an incredibly versatile tool, commonly known for its ability to create stunning visualizations. But did you know that with Tableau, you can also perform real-time, interactive text mining? Let’s delve into how we can harness this function to gain rapid insights from our textual data.

Previously, during text mining tasks, you might have found yourself reaching for a scripting language like R, Python, or Ruby, only to feed the results back into Tableau for visualization. This approach has Tableau serving merely as a communications tool to represent insights.

However, wouldn’t it be more convenient and efficient to perform text mining and further analysis directly in Tableau?

While Tableau has some relatively basic text processing functions that can be used for calculated fields, these often fall short when it comes to performing tasks like sentiment analysis, where text needs to be split into tokens. Even Tableau’s beloved R integration does not lend a hand in these scenarios.

The Power of Postgres for Text Mining in Tableau

Faced with these challenges, I decided to harness the power of Postgres‘ built-in string functions for text mining tasks. These functions perform much faster than most scripting languages. For example, I used the function regexp_split_to_table for word count, which takes a piece of text (like a blog post), splits it by a pattern, and returns the tokens as rows:

select
guid
, regexp_split_to_table(lower(post_content), '\s+') as word
, count(1) as word_count
from
alexblog_posts
group by
guid, word

Incorporating Custom SQL into Tableau Visualization

I joined this code snippet as a Custom SQL Query to my Tableau data source, which is connected to the database that is powering my blog:

Join with Custom SQL Query in Tableau applying the Postgres function regexp_split_to_table
Join with Custom SQL Query in Tableau applying the Postgres function regexp_split_to_table

And here we go, I was able to create an interactive word count visualization right in Tableau:

This example can be easily enhanced with data from Google Analytics, or adapted to analyze user comments, survey results, or social media feeds. The possibilities for Custom SQL in Tableau are vast and versatile. Do you have some more fancy ideas for real-time text mining with Tableau? Leave me a comment!

Update (TC Pro Tip): Identifying Twitter Hashtags in Tableau

A simple calculated field in Tableau can help identify words within tweets as hashtags or user references, eliminating the need for another regular expression via a Custom SQL Query:

CASE LEFT([Word], 1)
WHEN "#" THEN "Hash Tag"
WHEN "@" THEN "User Reference"
ELSE "Regular Content"
END

Looking for an example? Feel free to check out the Tweets featuring #tableau Dashboard on Tableau Public and download the Packaged Workbook (twbx):

Tableau dashboard that shows tweets featuring the hashtag #tableau (presented at Tableau Conference)
Tableau dashboard that shows tweets featuring the hashtag #tableau (presented at Tableau Conference)

Any more feedback, ideas, or questions? I hope this post provides you with valuable insights into how to master text mining in Tableau, and I look forward to hearing about your experiences and creative applications. You can find more tutorials like this in my new book Visual Analytics with Tableau (Amazon).

Transparency: This blog contains affiliate links. If you click on them, you will be redirected to the merchant. If you decide to make a purchase, we will receive a small commission. The price does not change for you. Affiliate links have no influence on our writing.