0% found this document useful (0 votes)
5 views22 pages

Lab - Data Visualization

The document outlines a lab focused on advanced data visualization techniques using a Facebook dataset, emphasizing univariate, bivariate, and multivariate analyses through various chart types. Key findings include the dominance of photo posts, a peak in user engagement around 2015, and strong correlations between likes and overall reactions. The lab also demonstrates the implementation of interactive visualizations using Plotly, enhancing user engagement and data exploration.

Uploaded by

tempcraze
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views22 pages

Lab - Data Visualization

The document outlines a lab focused on advanced data visualization techniques using a Facebook dataset, emphasizing univariate, bivariate, and multivariate analyses through various chart types. Key findings include the dominance of photo posts, a peak in user engagement around 2015, and strong correlations between likes and overall reactions. The lab also demonstrates the implementation of interactive visualizations using Plotly, enhancing user engagement and data exploration.

Uploaded by

tempcraze
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Lab 24: Data Visualization

Aim: To implement advanced data visualization techniques using the


Facebook dataset, focusing on generating clean, high-impact insights
while adhering to the latest library standards.

1. Univariate Analysis: Bar and Line Charts:

Univariate analysis (single variable) Used to understand the


distribution or trends of a single metric.

 Bar chart - Shows the frequency of different post types. It


reveals that 'photo' and 'video' are the dominant content
formats.
 Line chart - Shows the average reaction trend over time. This
helps identify seasonal peaks in user engagement.
2. Bivariate Analysis: Scatter Plots and Correlations:

Bivariate analysis (two variables) Used to identify relationships or


correlations between two metrics.

 Scatter plot - By plotting num_likes against num_shares, we


can see if popular posts also drive higher virality.
 Correlation heatmap - A matrix that quantifies how reactions
(Loves, Hahas, etc.) relate to each other.
3. Multivariate Analysis: Heat Maps and Bubble Charts:

Multivariate analysis (multiple variables) Used to find deeper


patterns across three or more attributes.

 Bubble chart - We plot num_loves vs. num_wows, using the


size of the bubble for num_shares and color for status_type.
This identifies which content types trigger emotional and viral
responses simultaneously.
4. Box and Whisker Plots for Statistical Analysis:
Statistical analysis

 Box and whisker plot - It is vital to identify "Outliers." By


plotting reactions across status types on a log scale, we can see
the typical performance range and those rare "viral" anomalies
that exceed the whiskers.

1. Write the interpretations and observation in your own words for


visualizations generated in above implementation of [Link].

CODE:

import pandas as pd

import [Link] as plt

import seaborn as sns

import numpy as np

import warnings

[Link]('ignore')

df = pd.read_csv('C:\\Users\\Thira Patel\\OneDrive\\Desktop\\Big
Data lab\\[Link]')

df['status_published'] = pd.to_datetime(df['status_published'])

sns.set_theme(style="whitegrid")
print("Generating plots...")

# 1. Bar Chart (Univriate)

[Link](figsize=(10, 6))

[Link](data=df, x='status_type', hue='status_type',

palette='viridis', legend=False)

[Link]('Distribution of Status Types')

[Link]()

# 2. Line Chart (Trend)

[Link](figsize=(12, 6))

try:

df_monthly = df.set_index('status_published')['num_reactions'] \

.resample('ME').mean().reset_index()

except:

df_monthly = df.set_index('status_published')['num_reactions'] \

.resample('M').mean().reset_index()
[Link](data=df_monthly,

x='status_published',

y='num_reactions',

marker='o')

[Link]('Average Reactions Over Time')

[Link]()

# 3. Scatter Plot (Bivariate)

[Link](figsize=(10, 6))

[Link](data=df,

x='num_likes',

y='num_shares',

alpha=0.5,

color='orange')

[Link]('Likes vs Shares')

[Link]()
# 4. Heatmap (Correlation)

[Link](figsize=(12, 8))

numeric_cols = df.select_dtypes(include=[[Link]])

corr_matrix = numeric_cols.corr()

[Link](corr_matrix, annot=True, cmap='coolwarm')

[Link]('Correlation Heatmap')

[Link]()

# 5. Bubble Chart (Multivariate)

[Link](figsize=(12, 8))

sample_df = [Link](n=500, random_state=42)

[Link](data=sample_df,

x='num_loves',

y='num_wows',

size='num_shares',

hue='status_type',

sizes=(20, 500),

alpha=0.6)
[Link]('Loves vs Wows (Bubble Chart)')

[Link](bbox_to_anchor=(1.05, 1))

[Link]()

# 6. Box Plot (Statistical)

[Link](figsize=(12, 6))

[Link](data=df,

x='status_type',

y='num_reactions',

hue='status_type',

palette='pastel',

legend=False)

[Link]('log')

[Link]('Reactions by Status Type')

[Link]()
OUTPUTS:

Bar Chart:

Line Chart:
Scatter Plot:
Heatmap Correlation:
Bubble Chart:

Box Plot:
OBSERVATIONS:

1. Bar Chart:

The bar chart indicates that photo posts make up the largest portion
of content, having the highest frequency among all categories. Video
posts follow next, while status updates and link posts appear only
rarely. This suggests that users tend to prefer sharing visual content,
particularly photos, over other formats.

2. Line Chart:

The line chart illustrates that user reactions were minimal during the
initial years. Engagement rises sharply between 2014 and 2015,
reaching its highest point. After this peak, there is a decline, followed
by a period of relatively stable but lower interaction levels. This
pattern reflects a temporary spike in activity before it settled.

3. Scatter Plot:

The scatter plot reveals a generally positive association between likes


and shares, although the relationship is not strictly linear. Posts with
fewer likes usually have fewer shares, while those with higher likes
often receive more shares. However, there are exceptions where
posts gain many likes but are not widely shared, indicating that likes
alone do not always lead to virality.
4. Heatmap:

The heatmap highlights a very strong correlation between the


number of likes and total reactions, showing that likes significantly
influence overall engagement. There is also a strong connection
between shares and love reactions, while other reaction types
display moderate relationships. Overall, likes remain the dominant
factor in user engagement.

5. Bubble Chart:

The bubble chart shows that most posts are concentrated near lower
values of loves and wows, forming a cluster close to the origin. A
small number of posts stand out with higher values and larger
bubbles, representing greater shares and stronger engagement. The
variation in colours suggests that certain types of content, especially
photos and videos, generate more emotional responses and sharing
activity.

6. Box Plot:

The box plot demonstrates that video posts typically have a higher
median number of reactions compared to other content types like
photos. Numerous outliers are present across all categories,
indicating that some posts achieve exceptionally high engagement.
The wide distribution shows that while most posts receive moderate
reactions, a few become highly popular or viral.

2. Implement interactive visualizations using “Plotly”.

CODE:

import pandas as pd

import [Link] as px

import numpy as np

# Load dataset

df = pd.read_csv('[Link]')

df['status_published'] = pd.to_datetime(df['status_published'])

print("Generating interactive Plotly graphs...")

# --- 1. Interactive Bar Chart (Univariate) ---

fig1 = [Link](df,

x='status_type',

color='status_type',

title='Interactive: Distribution of Status Types')


[Link]()

# --- 2. Interactive Line Chart (Univariate Trend) ---

df_monthly = df.set_index('status_published')['num_reactions'] \

.resample('ME').mean().reset_index()

fig2 = [Link](df_monthly,

x='status_published',

y='num_reactions',

title='Interactive: Average Reactions Over Time',

markers=True)

[Link]()

# --- 3. Interactive Scatter Plot (Bivariate) ---

fig3 = [Link](df,

x='num_likes',

y='num_shares',

color='status_type',

size='num_reactions',

hover_data=['num_comments'],

title='Interactive: Likes vs Shares')


[Link]()

# --- 4. Interactive Heatmap (Correlation) ---

numeric_cols = df.select_dtypes(include=[[Link]])

corr_matrix = numeric_cols.corr()

fig4 = [Link](corr_matrix,

text_auto=True,

color_continuous_scale='RdBu',

title='Interactive: Correlation Heatmap')

[Link]()

# --- 5. Interactive Bubble Chart (Multivariate) ---

sample_df = [Link](n=500, random_state=42)

fig5 = [Link](sample_df,

x='num_loves',

y='num_wows',

size='num_shares',

color='status_type',

hover_data=['num_likes'],
title='Interactive: Loves vs Wows (Bubble Chart)')

[Link]()

# --- 6. Interactive Box Plot (Statistical Analysis) ---

fig6 = [Link](df,

x='status_type',

y='num_reactions',

color='status_type',

title='Interactive: Reactions by Status Type (Log Scale)')

fig6.update_yaxes(type='log') # Apply log scale

[Link]()

OUTPUT:

Bar Chart:
Line Chart:
Scatter Plot:

Heatmap Correlation:
Bubble Chart:

Box Plot:
OBSERVATIONS:

1. Bar Chart:

The interactive bar chart highlights that photo posts make up the
majority of the dataset, with counts exceeding 4200. Video posts
rank second, while status updates and link posts appear far less
frequently. The hover feature allows users to view exact values,
making comparisons clearer and more accurate. This reinforces the
idea that users strongly prefer visual content, particularly photos.

2. Line Chart:

The line chart shows that user engagement remained quite low
before 2013, after which it started to rise steadily. A significant peak
occurs around 2015, where reactions go beyond 2500. Following this
peak, engagement drops and eventually stabilizes at a lower level.
Interactivity helps pinpoint exact time periods and values, revealing a
clear trend of growth, peak, and normalization.

3. Scatter Plot:
The scatter plot demonstrates a positive but uneven relationship
between likes and shares. Most points are clustered at lower values,
indicating that the majority of posts receive limited engagement.
However, a few points stand out with very high likes and shares,
representing viral content. With hover details, additional metrics like
comments and reactions can be observed, showing that highly liked
posts often attract broader interaction.

4. Heatmap:

The heatmap emphasizes the relationships between different


variables. A very strong correlation exists between likes and total
reactions (approximately 0.99), indicating that likes play a major role
in overall engagement. Shares and love reactions also show a strong
connection (around 0.82). The use of colour intensity makes it easy
to distinguish between strong and weak correlations, improving
interpretability over raw numerical data.

5. Bubble Chart:

The bubble chart reveals that most posts have low counts of loves
and wows, clustered near the origin. A small number of posts stand
out with higher values and larger bubbles, reflecting more shares and
stronger engagement. Colour variations suggest that certain types of
content, particularly videos, tend to evoke stronger emotional
responses. Hover functionality provides detailed insights into
individual post-performance.

6. Box Plot:
The box plot indicates that video and status posts generally achieve
higher median reactions compared to photo and link posts.
Numerous outliers are visible, especially among photo posts, with
some reaching very high reaction counts (above 4000). The use of a
logarithmic scale helps in visualizing the wide range of values
effectively. This suggests that while most posts receive moderate
engagement, a few gain exceptionally high popularity.

CONCLUSION:

Interactive visualizations created using Plotly make it easier to


explore and understand data. They allow users to examine values in
detail, identify trends, and uncover relationships more efficiently
than static charts.

You might also like