Spaces:
Sleeping
Sleeping
Download eda.py from grcvlrn/Deployment: direct link, hf CLI and curl.
- Browser
- Download file 2.92 kB
-
https://huggingface.co/spaces/grcvlrn/Deployment/resolve/main/eda.py
- Command line
-
hf download hf://spaces/grcvlrn/Deployment/eda.py
-
curl -L -o eda.py https://huggingface.co/spaces/grcvlrn/Deployment/resolve/main/eda.py
2.92 kB
| import streamlit as st | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| import pandas as pd | |
| # Define function to plot sentiment distribution | |
| def payment_counts_distribution(df): | |
| payment_counts = df['default_payment_next_month'].value_counts() | |
| plt.figure(figsize=(8, 6)) | |
| plt.pie(payment_counts, labels=payment_counts.index, autopct='%.0f%%', startangle=140) | |
| plt.title('Payment Distribution') | |
| plt.show() | |
| def limit_balance_distribution(df): | |
| sns.histplot(df['limit_balance'], bins=50, kde=True) | |
| plt.title('Balance Distribution') | |
| plt.xlabel('Balance') | |
| plt.ylabel('Frequency') | |
| plt.show() | |
| def sex_distribution(df): | |
| sex_counts = df['sex'].value_counts() | |
| plt.figure(figsize=(8, 6)) | |
| plt.pie(sex_counts, labels=sex_counts.index, autopct='%.0f%%', startangle=140) | |
| plt.title('Gender Distribution') | |
| plt.show() | |
| def education_level_distribution(df): | |
| edu_counts = df['education_level'].value_counts() | |
| plt.figure(figsize=(8, 6)) | |
| plt.pie(edu_counts, labels=edu_counts.index, autopct='%.0f%%', startangle=140) | |
| plt.title('Education Level Distribution') | |
| plt.show() | |
| def marital_status_distribution(df): | |
| status_counts = df['marital_status'].value_counts() | |
| plt.figure(figsize=(8, 6)) | |
| plt.pie(status_counts, labels=status_counts.index, autopct='%.0f%%', startangle=140) | |
| plt.title('Marital Status Distribution') | |
| plt.show() | |
| def age_distribution(df): | |
| sns.histplot(df['age'], bins=25, kde=True) | |
| plt.title('Age Distribution') | |
| plt.xlabel('Age') | |
| plt.ylabel('Frequency') | |
| plt.show() | |
| st.title("Sentiment Analysis Visualization") | |
| uploaded_file = st.file_uploader("P1G5_Set_1_gracia_valerine", type="csv") | |
| if uploaded_file: | |
| df = pd.read_csv(uploaded_file) | |
| st.write("Data Preview:") | |
| st.write(df.head()) | |
| visualizations = st.multiselect( | |
| "Select visualizations to display", | |
| ["Payment Counts Distribution", "Limit Balance Distribution", "Gender Distribution", | |
| "Education Level Distribution", "Marital Status Distribution", "Age Distribution"] | |
| ) | |
| if "Payment Counts Distribution" in visualizations: | |
| st.subheader("Payment Counts Distribution") | |
| payment_counts_distribution(df) | |
| if "Limit Balance Distribution" in visualizations: | |
| st.subheader("Limit Balance Distribution") | |
| limit_balance_distribution(df) | |
| if "Gender Distribution" in visualizations: | |
| st.subheader("Gender Distribution") | |
| sex_distribution(df) | |
| if "Education Level Distribution" in visualizations: | |
| st.subheader("Education Level Distribution") | |
| education_level_distribution(df) | |
| if "Marital Status Distribution" in visualizations: | |
| st.subheader("Marital Status Distribution") | |
| marital_status_distribution(df) | |
| if "Age Distribution" in visualizations: | |
| st.subheader("Age Distribution") | |
| age_distribution(df) |