File size: 2,009 Bytes
54d8c28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b09c7aa
 
54d8c28
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
from PIL import Image
from wordcloud import WordCloud


st.set_page_config(
    page_title = 'Sentiment Analysis',
    layout = 'wide',
    initial_sidebar_state='expanded'
)

def run():

    # title
    st.title( 'Sentiment Prediction')

    # sub header
    st.subheader('Positive, Neutral, Negative')

    # insert image
    image = Image.open('sensi.jpg')
    st.image(image, caption='image from AltextSoft, education purpose only')

    # Deskripsi
    st.write('Exploratory Data from dataset')

    # show data frame
    st.write('The first 10 Data')
    df = pd.read_csv('https://raw.githubusercontent.com/mukhlishr/rasyidi/main/tripadvisor_hotel_reviews.csv')
    st.dataframe(df.head(10))

    # Barplot target columns 
    st.write('###### Rating ')
    fig=plt.figure(figsize=(15,5))
    sns.countplot(x='Rating', data = df)
    st.pyplot(fig)


    def Sentimen(x):
      if  x<= 5 and x>3:
        return 'positive'
      if x== 3:
        return 'neutral'
      if x< 3 and x>=1:
        return 'negative'  
    # Create column 'sentimen'
    df['sentimen'] = df['Rating'].apply(Sentimen)

    # Barplot Sentiment 
    st.write('###### Sentiment of Review ')
    fig=plt.figure(figsize=(15,5))
    sns.countplot(x='sentimen', data = df)
    st.pyplot(fig)

    # Wordcloud
    st.write('###### Word Cloud ')
    def show_wordcloud(data, title = None):
        wordcloud = WordCloud(
        background_color='black',
        max_words=200,
        max_font_size=45, 
        scale=1,
        random_state=1
    ).generate(" ".join(data))
        fig = plt.figure(1, figsize=(15, 15))
        plt.axis('off')
        if title: 
            fig.suptitle(title, fontsize=20)
            fig.subplots_adjust(top=2.3)

        plt.imshow(wordcloud)
        st.pyplot(fig)

    # Wordcloud all
    show_wordcloud(df['Review'].values)
    

if __name__ == '__main__':
    run()