Spaces:
Sleeping
Sleeping
File size: 5,646 Bytes
8eee676 08e4fd7 f0ef461 08e4fd7 f0ef461 eafd889 7b5faa8 eafd889 b32df0d eafd889 f0ef461 eafd889 b0125cf eafd889 f0ef461 eafd889 f0ef461 345bbc9 f0ef461 eafd889 f0ef461 eafd889 32d4be4 f67763c 32d4be4 f67763c 32d4be4 f67763c 32d4be4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | '''
Achmad Dhani
Objective: Creating a page for NLP Exploratory Data Analysis
'''
import streamlit as st
import pandas as pd
from PIL import Image
import plotly.express as px
def run():
'''
Function for EDA page
'''
st.title('Exploration Data Analysis Section')
# ============================= Showing Data ==========================
df = pd.read_csv('Emotion_classify_Data.csv')
horizontal_radio_css = """<style>div.row-widget.stRadio > div{flex-direction:row;}</style>"""
st.markdown(horizontal_radio_css, unsafe_allow_html=True)
data_show = st.radio("**Viewing Options**", ['Top 10 Entries', 'Bottom 10 Entries'])
if data_show == 'Top 10 Entries':
st.table(df.head(10))
else:
st.table(df.tail(10))
# ============================= Simple Analysis ========================
eda=pd.read_csv('eda.csv')
# basic summary analysis
emotion_counts = eda['Emotion'].value_counts()
eda['Comment Length'] = eda['Comment'].apply(len)
eda['Word Count'] = eda['Comment'].apply(lambda x: len(x.split()))
# emotion distribution
fig_emotions = px.bar(emotion_counts,
x=emotion_counts.index,
y=emotion_counts.values,
labels={'x': 'Emotion', 'y': 'Count'},
title='Distribution of Emotions')
fig_emotions.update_traces(marker_line_width=1, marker_line_color='black')
fig_emotions.update_layout(xaxis_title='Emotions', yaxis_title='Count', width=700)
# comment distribution
fig_comment_length = px.histogram(eda,
x='Comment Length',
nbins=30,
marginal='box',
title='Distribution of Comment Length')
fig_comment_length.update_traces(marker_line_width=1, marker_line_color='black')
fig_comment_length.update_layout(xaxis_title='Length of Comment', yaxis_title='Count', width=700, bargap=0)
# word count distribution
fig_word_count = px.histogram(eda,
x='Word Count',
nbins=30,
marginal='box',
title='Distribution of Word Count')
fig_word_count.update_traces(marker_line_width=1, marker_line_color='black')
fig_word_count.update_layout(xaxis_title='Word Count', yaxis_title='Count', width=700)
# Display the figures in Streamlit
st.plotly_chart(fig_emotions)
st.plotly_chart(fig_comment_length)
st.plotly_chart(fig_word_count)
with st.expander('Explanation'):
st.caption(
'''
The visualization above shows:
- The dataset has a balance target class which are `anger, joy, and fear`
- The distribution of comment length skewed to the right with the majority of the data is within `30 to 130` comment length
- The outliers are the comment lengths that is above `244`
- The same goes to the word count, the distribution is skewed to the right with the majority of the data is within the range of `5 to 30` word count
- This gives insight about how expressive the people are in the dataset. Most people quite concise but there are a few who's very expressive and open about what they feel.
'''
)
# ============================= Joy Word Cloud ==================================
st.subheader('Joy Word Cloud')
image1 = Image.open('joy_wordcloud.png')
st.image(image1, caption='Figure 1 Joy Emotion Word Cloud', width=700)
# explaination
with st.expander('Explanation'):
st.caption(
'''
The Joy word cloud highlights commonly used words associated with feelings of joy, such as `life, good, day, something, going, and well`, indicating that these terms are often expressed when people describe joyful experiences.
'''
)
# ============================= Anger Word Cloud =====================================
st.subheader('Anger Word Cloud')
image2 = Image.open('anger_wordcloud.png')
st.image(image2, caption='Figure 2 Anger Emotion Word Cloud', width=700)
# explaination
with st.expander('Explanation'):
st.caption(
'''
The Anger word cloud highlights commonly used words associated with feelings of anger, such as would, even, way, think, angry, indicating that these terms mostly expressed when people are angry. Anger is a special case where, words like would and even is an auxiliary verb, which indicates a mood or tense.
'''
)
# =============================== Fear Word Cloud ====================================
st.subheader('Fear Word Cloud')
image3 = Image.open('fear_wordcloud.png')
st.image(image3, caption='Figure 3 Fear Emotion Word Cloud', width=700)
# explaination
with st.expander('Explanation'):
st.caption(
'''
The Fear word cloud highlights commonly used words associated with feelings of fear, such as `still, bit, strange, think`, indicating that these terms are often expressed when people describing or more accurately worriness and anxiousness. This is justified since fear in the context of fear of the unknown is believe to cause worriness and anxiousness on a person. Fear is a broad emotion that can be more interpreted two ways, fear of the unknown that cause anxiety or being scared/teriffied and giving goosebumps.
'''
) |