This repository will not be updated. The repository will be kept available in read-only mode.
In this code pattern, we will use a Jupyter notebook with Watson Studio to glean insights from a vast body of unstructured data. We'll start with data exported from Facebook Analytics. We'll use Watson’s Natural Language Understanding and Visual Recognition to enrich the data.
We'll use the enriched data to answer questions like:
What emotion is most prevalent in the posts with the highest engagement?
What sentiment has the higher engagement score on average?
What are the top keywords, entities or images measured by total reach?
These types of insights are especially beneficial for marketing analysts who are interested in understanding and improving brand perception, product performance, customer satisfaction, and ways to engage their audiences.
It is important to note that this code pattern is meant to be used as a guided experiment, rather than an application with one set output. The standard Facebook Analytics export features text from posts, articles, and thumbnails, along with standard Facebook performance metrics such as likes, shares, and impressions. This unstructured content was then enriched with Watson APIs to extract keywords, entities, sentiment, and emotion.
After the data is enriched with Watson APIs, we'll use the Cognos Dashboard Embedded service to add a dashboard to the project. Using the dashboard you can explore our results and build your own sophisticated visualizations to communicate the insights you've discovered.
This code pattern provides mock Facebook data, a notebook, and comes with several pre-built visualizations to jump start you with uncovering hidden insights.
When the reader has completed this code pattern, they will understand how to:
Follow these steps to setup and run this code pattern. The steps are described in detail below.
Clone the pixiedust-facebook-analysis
repo locally. In a terminal, run the following command:
git clone https://github.com/IBM/pixiedust-facebook-analysis.git
Log into IBM's Watson Studio. Once in, you'll land on the dashboard.
Create a new project by clicking New project +
and then click on Create an empty project
.
Enter a project name.
Choose an existing Object Storage instance or create a new one.
Click Create
.
Upon a successful project creation, you are taken to the project Overview
tab. Take note of the Assets
and Settings
tabs, we'll be using them to associate our project with any external assets (datasets and notebooks) and any IBM cloud services.
Associate the project with Watson services. To create an instance of each service, go to the Settings
tab in the new project and scroll down to Associated Services
. Click Add service
and select Watson
from the drop-down menu. Add the service using the free Lite
plan. Repeat for each of the services used in this pattern:
Once your services are created, copy the credentials and save them for later. You will use them in your Jupyter notebook.
☰
menu, and select Services > My Services
.Manage in IBM Cloud
for each service.API key
and URL
to use in the notebook.Go back to your Watson Studio project by using your browser's back button or use the upper-left ☰
menu, and select Projects
and open your project.
Select the Overview
tab, click Add to project +
on the top right and choose the Notebook
asset type.
Fill in the following information:
From URL
tab. [1]Name
for the notebook and optionally a description. [2]Select runtime
select the Default Python 3.6 Free
option. [3]Notebook URL
provide the following url [4]:https://raw.githubusercontent.com/IBM/pixiedust-facebook-analysis/master/notebooks/pixiedust_facebook_analysis.ipynb
Click the Create notebook
button.
TIP: Your notebook will appear in the
Notebooks
section of theAssets
tab.
Find the notebook cell after 1.5. Add Service Credentials From IBM Cloud for Watson Services
.
Set the API key and URL for each service.
Note: This cell is marked as a
hidden_cell
because it will contain sensitive credentials.
Use Find and Add Data
(look for the 01/00
icon) and its Files
tab. From there you can click browse
and add a .csv
file from your computer.
Note: If you don't have your own data, you can use our example by cloning this git repo. Look in the
data
directory.
Find the notebook cell after 2.1 Load data from Object Storage
. Place your cursor after # **Insert to code > Insert pandas DataFrame**
. Make sure this cell is selected before inserting code.
Using the file that you added above (under the 01/00
Files tab), use the Insert to code
drop-down menu. Select pandas DataFrame
from the drop-down menu.
Note: This cell is marked as a
hidden_cell
because it contains sensitive credentials.
The inserted code includes a generated method with credentials and then calls the generated method to set a variable with a name like df_data_1
. If you do additional inserts, the method can be re-used and the variable will change (e.g. df_data_2
).
Later in the notebook, we set df = df_data_1
. So you might need to fix the variable name df_data_1
to match your inserted code or vice versa.
We want to write the enriched file to the same container that we used above. So now we'll use the same file drop-down to insert credentials. We'll use them later when we write out the enriched CSV file.
After the df
setup, there is a cell to enter the file credentials. Place your cursor after the # insert credentials for file - Change to credentials_1
line. Make sure this cell is selected before inserting credentials.
Use the CSV file's drop-down menu again. This time select Insert Credentials
.
Note: This cell is marked as a
hidden_cell
because it contains sensitive credentials.
The inserted code includes a dictionary with credentials assigned to a variable with a name like credentials_1
. It may have a different name (e.g. credentials_2
). Rename it or reassign it if needed. The notebook code assumes it will be credentials_1
.
When a notebook is executed, what is actually happening is that each code cell in the notebook is executed, in order, from top to bottom.
Each code cell is selectable and is preceded by a tag in the left margin. The tag format is In [x]:
. Depending on the state of the notebook, the x
can be:
*
, this indicates that the cell is currently executing.There are several ways to execute the code cells in your notebook:
Play
button in the toolbar.Cell
menu bar, there are several options available. For example, you can Run All
cells in your notebook, or you can Run All Below
, that will start executing from the first cell under the currently selected cell, and then continue executing all cells that follow.Schedule
button located in the top right section of your notebook panel. Here you can schedule your notebook to be executed once at some future time, or repeatedly at your specified interval.Assets
tab in the your Watson Studio project click on the 01/00
(Find and add data) icon.enriched_example_facebook_data.csv
file and use the 3-dot pull-down to select Add as data asset
.Settings
tab in the new project and scroll down to Associated Services
.Add service
and select Dashboard
from the drop-down menu.Lite
plan.Add to project +
button and select Dashboard
.From file
tab and use the Select file
button to open the file dashboards/dashboard.json
from your local repo.Create
.enriched_example_facebook_data.csv
asset.If you walk through the cells, you will see that we demonstrated how to do the following:
When you try the dashboard, you will see:
The provided dashboard uses four tabs to show four simple charts:
The enriched data contains emotions, sentiment, entities, and keywords that were added using Natural Language Understanding to process the posts, links, and thumbnails. Combining the enrichment with the metrics from Facebook gives us a huge number of options for what we could show on the dashboard. The dashboard editor also allows you great flexibility on how you arrange your dashboard and visualize your data. The example demonstrates the following:
A word-cloud showing the keywords sized by total impressions and using color to show the sentiment
A pie chart showing total reach by emotion
A stacked bar chart showing likes, shares, and comments by post sentiment
A bar chart with a line overlay, showing total impressions and paid impressions by mentioned entity
This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.