Mining YouTube Data with Python for Social Media Analysis: Measuring the ALS Ice Bucket Challenge

YouTube has become a crucial platform for social media campaigns and activism. With over 2 billion monthly active users watching 1 billion hours of video per day, YouTube offers a vast dataset for measuring the reach and impact of campaigns [1]. One notable example is the ALS Ice Bucket Challenge, which went viral on YouTube and other social media in 2014, raising over $115 million for ALS research [2].

In this article, we‘ll walk through how to mine data from YouTube using Python and apply AI and machine learning techniques to analyze the effectiveness of the ALS Ice Bucket Challenge social media campaign. We‘ll gather data on Ice Bucket Challenge videos, examine video stats and performance metrics, analyze the sentiment and topics of video titles and comments, and build a model to predict video engagement.

Extracting YouTube Data with Python

The YouTube Data API enables programmatic access to YouTube video data and statistics. To get started, you‘ll need to set up a project in the Google Developers Console and enable the YouTube Data API. Once you have an API key, you can use the Google APIs Client Library for Python to make API requests [3].

First install the Google API client library:

pip install google-api-python-client

Then we can search for videos with the youtube.search().list() method:

from googleapiclient.discovery import build

youtube = build(‘youtube‘, ‘v3‘, developerKey=api_key)

search_response = youtube.search().list(
    q=‘ALS Ice Bucket Challenge‘,
    type=‘video‘,
    part=‘id,snippet‘,
    maxResults=50
).execute()

This retrieves the video IDs and metadata for the top 50 search results related to the ALS Ice Bucket Challenge. We can extract the video IDs and make a follow-up request with youtube.videos().list() to get more detailed statistics:

video_ids = [‘videoId‘] for video in search_response[‘items‘]]

video_response = youtube.videos().list(
    id=‘,‘.join(video_ids),
    part=‘snippet,statistics‘
).execute()

videos = []
for video in video_response[‘items‘]:
    vid_id = video[‘id‘]
    title = video[‘snippet‘][‘title‘]
    view_count = int(video[‘statistics‘].get(‘viewCount‘, 0))
    like_count = int(video[‘statistics‘].get(‘likeCount‘, 0))
    dislike_count = int(video[‘statistics‘].get(‘dislikeCount‘, 0))
    comment_count = int(video[‘statistics‘].get(‘commentCount‘, 0))
    vid_data = [vid_id, title, view_count, like_count, dislike_count, comment_count] 
    videos.append(vid_data)

This retrieves key data points like the view count, like/dislike counts, and number of comments for each video. We can store this data in a list of lists, with each sublist representing one video. To gather a larger dataset, we can use the nextPageToken provided in API responses to retrieve subsequent pages of results.

Analyzing YouTube Data with Pandas

With our YouTube data gathered, we can load it into a Pandas DataFrame for analysis:

import pandas as pd

columns = [‘video_id‘, ‘title‘, ‘view_count‘, ‘like_count‘, ‘dislike_count‘, ‘comment_count‘]
df = pd.DataFrame(videos, columns=columns)

Now we can use Pandas‘ data analysis capabilities to examine the video statistics:

print(df.describe())
       view_count     like_count  dislike_count   comment_count
count  50.000000     50.000000     50.000000       50.00000 
mean   2146351.440   24052.340     644.360         2811.300
std    6697997.315   84220.655     2474.438        8548.079
min     1137.000      84.000        2.000           8.000   
25%     37546.750     552.250      23.000          72.750
50%     156424.000    1643.500     63.000          270.500
75%     816462.250    8618.000     236.500         1938.250
max    38585485.000  476459.000    14495.000       49168.000

This gives us a high-level stats summary, showing that the average Ice Bucket Challenge video in our sample had over 2 million views, 24,000 likes, and 2,800 comments. However, the large standard deviations and differences between mean and median values indicate there are very popular outlier videos skewing the averages. Let‘s look at the top 5 videos by view count:

df.nlargest(5, ‘view_count‘)[[‘title‘, ‘view_count‘]]
title view_count
2 Charlie Sheen Ice Bucket Challenge 38,585,485
5 George W. Bush Takes the ALS Ice Bucket … 9,285,338
11 ALS Ice Bucket Challenge – Cristiano Ronaldo 4,471,686
17 Kermit the Frog Takes ALS Ice Bucket Chal… 4,014,687
34 Dwayne Johnson Takes the ALS Ice Bucket C… 3,235,603

The most popular videos tend to feature celebrities, underlining the importance of influencers and public figures in driving the viral spread of a social media campaign.

We can also analyze the relationship between different video metrics, like the correlation between views and likes/dislikes:

df[[‘view_count‘, ‘like_count‘, ‘dislike_count‘]].corr()
view_count like_count dislike_count
view_count 1.000000 0.981695 0.818071
like_count 0.981695 1.000000 0.833398
dislike_count 0.818071 0.833398 1.000000

Videos views, likes, and dislikes are strongly positively correlated, suggesting more popular videos generate engagement across the board, both positive and negative. We could produce visualizations of these relationships as well.

AI/ML Analysis of YouTube Data

Beyond basic statistics, we can apply more advanced artificial intelligence and machine learning techniques to gain deeper insights from our YouTube data. Some applicable methods include:

  • Sentiment Analysis: Determine whether video titles and comments express a positive, negative, or neutral sentiment toward the campaign. Sentiment scoring models can be trained on labeled text data.

  • Topic Modeling: Discover the main topics and themes in video titles and descriptions using techniques like Latent Dirichlet Allocation (LDA). This can reveal campaign messaging and audience interpretations.

  • Clustering: Group together videos with similar attributes using algorithms like K-Means. Clusters might represent different video types or creator segments that emerged during the campaign.

  • Classification: Train supervised learning models to classify videos based on attributes like title keywords, creator type (influencer/public figure/organization), or content style. This can provide further insight into different video categories.

  • Regression: Build models to predict video engagement metrics (views, likes, comments) based on attributes like title, tags, category, publish time. This can help understand the factors driving a campaign‘s success.

Python provides popular libraries for AI/ML like scikit-learn, TensorFlow, and PyTorch that can be applied to YouTube data. For example, here‘s how we could perform simple sentiment analysis on video titles using the VADER tool in the Natural Language Toolkit (NLTK) library [4]:

from nltk.sentiment.vader import SentimentIntensityAnalyzer

sid = SentimentIntensityAnalyzer()
df[‘title_sentiment‘] = df[‘title‘].apply(lambda title: sid.polarity_scores(title)[‘compound‘])

df.groupby(pd.cut(df[‘title_sentiment‘], bins=3, labels=[‘neg‘, ‘neu‘, ‘pos‘])).size()
neg     2
neu    26 
pos    22
dtype: int64  

The VADER model rates sentiment on a scale from -1 (most negative) to +1 (most positive). We can see that the majority of Ice Bucket Challenge video titles were neutral or positive in tone, with only 2 negatively titled videos. This matches the generally uplifting spirit of the campaign.

We could perform similar analyses of video comments and descriptions, comparing sentiment between video groups. More advanced ML models could be trained specifically on YouTube data for more domain-relevant results.

Another perspective is clustering the videos using features like title words, tags, description length, and performance metrics to identify data-driven commonalities between different clusters of videos:

from sklearn.cluster import KMeans
from sklearn.feature_extraction.text import TfidfVectorizer

vectorizer = TfidfVectorizer(stop_words=‘english‘)
X = vectorizer.fit_transform(df[‘title‘])

k = 5
kmeans = KMeans(n_clusters=k).fit(X)
clusters = kmeans.predict(X)

This extracts TF-IDF weighted keywords from the video titles and clusters them into 5 groups based on title text similarity. We could then examine the most common words and other aggregated attributes in each cluster to characterize different video archetypes.

For example, if one cluster tends to have titles mentioning a celebrity name, high view counts, and early publish dates, it might represent the initial wave of influencer challenge videos that sparked the campaign. Another cluster with "how to" titles and longer descriptions might represent tutorial/explainer videos that sustained the trend.

We can also apply supervised machine learning to build models predicting video success. For example, we could train a regression model to predict view count from video attributes:

from sklearn.ensemble import RandomForestRegressor

X = pd.get_dummies(df[[‘like_count‘, ‘dislike_count‘, ‘comment_count‘]])  
y = df[‘view_count‘]

model = RandomForestRegressor()
model.fit(X, y)

print(model.score(X, y))
print(pd.Series(model.feature_importances_, index=X.columns).nlargest(5))

This trains a Random Forest model on the like, dislike, and comment counts to predict view count, one indicator of video popularity. The model‘s coefficient of determination (R^2) score and the feature importances can help gauge how well engagement metrics reflect overall video reach and impact for the campaign. We could optimize this model and compare it to other algorithms to find the best predictor.

The code examples here just scratch the surface of the kinds of AI/ML analyses possible with YouTube data. The key is to focus on methods that align with the goals and KPIs of your specific social media campaign, such as:

  • Sentiment analysis to track audience opinions and reactions
  • Topic modeling to identify the main campaign themes and messages that resonated
  • Clustering to segment videos by creator type, style, or other attributes
  • Classification to categorize videos by stage of the campaign lifecycle
  • Regression to determine the video features most predictive of engagement and influencer

Social media platforms like YouTube generate immense amounts of data that is impossible to fully process manually. AI and machine learning tools enable automatic analysis to uncover meaningful patterns and insights. With a programming language like Python, data science libraries, and the YouTube Data API, you can mine valuable intelligence from YouTube data to evaluate the success and impact of social media campaigns.

Conclusion

The ALS Ice Bucket Challenge was one of the most successful and memorable social media campaigns of all time. In addition to raising $115 million for ALS research, it generated over 17 million videos from participants worldwide [5]. YouTube was a key part of the campaign‘s viral spread.

As this tutorial has shown, Python and the YouTube Data API provide accessible tools for gathering and mining data from YouTube videos at scale. With basic statistics and visualizations in Pandas, you can quickly get a sense of a campaign‘s video footprint and the attributes of top-performing videos.

Artificial intelligence and machine learning techniques enable deeper analysis of the large volume of YouTube data generated by a social media campaign. Key applications include sentiment analysis to gauge public opinion, topic modeling to surface campaign themes, and predictive modeling to forecast video engagement.

This kind of AI-powered YouTube data analysis provides marketers and organizations with a data-driven, empirical perspective on the dynamics and impact of their social media campaigns. It enables measuring the ROI of influencer activations, identifying target audiences, and understanding the elements of viral, engaging content.

The ALS Association was able to quantify the incredible success of the Ice Bucket Challenge using YouTube data. The challenge was the most popular in the US, with Americans posting over 6.3 million videos [5]. On August 29 at the peak of the challenge, the ALS Association received $11.5 million in donations, compared to $32,000 on the same date in 2013 [5].

YouTube Trends also published an analysis of Ice Bucket Challenge videos, finding that over 90 percent of views came from challenge videos uploaded in a single 30-day window [6]. Uploads peaked on August 18th, when YouTube saw more than 2,000 challenge videos posted in a single day [6]. They also notes that celebrities played a key role, with the 20 most viewed Ice Bucket Challenge videos coming from famous participants like Bill Gates, Mark Zuckerberg and Lady Gaga [6].

These examples show how YouTube data tells the story of a social media campaign and enables measuring concrete results. With Python and AI/ML tools, any marketer or organization can mine these kinds of insights from YouTube data for their own campaigns. As video‘s role in the social media landscape continues to grow, YouTube data mining and analysis will become an increasingly valuable skill.

Further Reading:

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Similar Posts