CoolFace
Apppublic

zakish/imdb-sentiment

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
eda.py113 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3import numpy as np4import seaborn as sns5import matplotlib.pyplot as plt6import plotly.express as px7from PIL import Image8import json9 10st.set_page_config(11    page_title='IMDB Sentiment Analysis',12    layout= 'wide',13    initial_sidebar_state= 'expanded'14)15 16 17# Create Run Function18def run():19    # Membuat Title20    st.title('IMDB Sentiment Analysis')21 22    # Subheader23    st.subheader('Made by Zaki')24 25    # Menambahkan gambar26    image = Image.open('growth.jpg')27    st.image(image)28 29    # Menambahkan deskripsi30    st.write('## Introduction')31    st.write(32    '''33    The use of sentiment analysis in natural language processing (NLP) has become increasingly popular in recent years. It is a technique that involves the automatic identification and classification of subjective information present in text data, including opinions, attitudes, emotions, and other related sentiments. In this project, we will be exploring the IMDB movie review dataset, which contains information on reviews of movies, TV shows, and other related content. We will be using an Artificial Neural Network (ANN) model for sentiment analysis in NLP to predict the sentiment of the reviews.34    35    '''36    )37    # Membuat garis lurus38    st.markdown('-'*42)39 40    st.write('## Table')41    # Show DF42    df = pd.read_json('part-06.json')43    st.dataframe(df.head(100))44    45    st.write('## Sentiment Distribution ')46    # plotting47    fig, ax = plt.subplots(figsize=(10,5))48 49    # define sentiment func50    def rating(x):51        if x <= 4:52            return 0 # negative sentiment53        elif x >= 7:54            return 2 # positive sentiment55        else:56            return 1 # neutral sentiment    57    # create sentiment column based on rating values58    df['sentiment'] = df['rating'].apply(lambda x: rating(x))59    df['date'] = pd.to_datetime(df['review_date'], format='%d %B %Y').dt.strftime('%d-%m-%y')60    df['date'] = pd.to_datetime(df['date'])61    df['year'] = df['date'].dt.year62    df.drop('review_date', axis=1, inplace=True)63    fig = px.pie(df, names='sentiment', title='Sentiment Distribution', hole=.5)64    # Display the plot using Streamlit65    st.plotly_chart(fig)66 67 68    st.write('## Review Trend Over The Years')69    # Group the dataframe by year and sentiment and get the count70    df_grouped = df.groupby(['year', 'sentiment']).size().reset_index(name='count')71    # Create a bar chart using Plotly Express72    fig = px.bar(df_grouped, x='year', y='count', color='sentiment', barmode='group',73                title='Sentiment Distribution by Year')74    # Display the bar chart in Streamlit75    st.plotly_chart(fig)76    77    st.write('## Top 10 Movies Reviewed')78    # Create a dropdown for year selection79    year_options = df['year'].unique()80    year_selection = st.selectbox('Select Year', year_options)81    # Filter the dataframe based on the selected year and get the top 10 most reviewed movies82    top10_movies = df[df['year'] == year_selection]['movie'].value_counts().nlargest(10)83    # Create a countplot using Plotly Express for the top 10 most reviewed movies84    fig = px.bar(top10_movies, x=top10_movies.index, y='movie',85                title=f'Top 10 Most Reviewed Movies in {year_selection}')86    # Display the countplot in Streamlit87    st.plotly_chart(fig)88 89    st.write('## Word Distribution In Every Sentiment')90    num_word_review = df['review_detail'].apply(lambda x: len(x.split(' ')))91    fig = px.histogram(df, nbins=30, x=num_word_review, color="sentiment",92                   color_discrete_sequence=px.colors.qualitative.Pastel1,93                   facet_col="sentiment",94                   labels={'x': 'Number of Words', 'y': 'Count'},95                   category_orders={"sentiment": [2, 1, 0]},96                   height=400, width=900)97 98    fig.update_layout(99        font=dict(size=14),100        margin=dict(l=20, r=20, t=60, b=20),101        yaxis_title="Count",102        xaxis_title="Number of Words"103    )104 105    fig.for_each_annotation(lambda a: a.update(text=f"Mean: {np.mean(num_word_review[df.sentiment == int(a.text[-1])]):.2f}<br>Min: {np.min(num_word_review[df.sentiment == int(a.text[-1])])}<br>Max: {np.max(num_word_review[df.sentiment == int(a.text[-1])])}"))106 107    st.plotly_chart(fig)108 109    110 111# calling function112if __name__ == '__main__':113   run()