Gaining Insights
Lesson 1 of 1
  1. 1
    In this unit, we’ll be adding the code that will analyze the Twitter data we retrieve from Twitter users. At the moment, however, our Celebrity Match application can be tough to read or unders…
  2. 2
    The analyze() function we just created will return the results from the Personality Insight (PI) API in JSON format. Whenever we use the analyze() function, we’ll need to parse and flatten the JS…
  3. 3
    The flatten() function flattens the results from a user and store the results in a dictionary . The next step is to write a function that can compare two dictionaries (the user’s and the celebrity…
  4. 4
    With all of our functionality in place, we now need two Twitter users to compare. We’ll manually enter the Twitter usernames by creating empty variables that you can fill in, like so: user_handle…
  5. 5
    Now that we have two Twitter usernames, we can use the analyze() function that we created earlier to retrieve some data from Twitter, like so: user_result = analyze(user_handle) celebrity_result =…
  6. 6
    Now let’s use the two functions we added earlier to format our results. First, we’ll use the flatten() function to flatten the JSON structure that the analyze() function returns, like so: #First,…
  7. 7
    Finally, to view the results, we’ll have to sort them and then display the top 5 traits from the sorted results. These will be the top 5 traits you share with the celebrity you selected for the ap…
  8. 8
    Congratulations! You built a fully functional, Watson-powered application that does the following: Queries the Twitter API Queries the Watson Personality Insights API * Compares two bodies of …