Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Judul Aplikasi
|
| 6 |
st.set_page_config(page_title='DataViz Pro', layout='wide')
|
|
@@ -9,40 +15,83 @@ st.title('π DataViz Pro - Dashboard Analisis Data')
|
|
| 9 |
# Upload File
|
| 10 |
uploaded_file = st.file_uploader("Upload dataset (CSV)", type=['csv'])
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if uploaded_file is not None:
|
| 13 |
-
df =
|
| 14 |
st.success("Dataset berhasil diunggah!")
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
st.
|
| 18 |
-
st.write(df.head())
|
| 19 |
-
|
| 20 |
-
# Statistik Data
|
| 21 |
-
st.subheader("Statistik Data")
|
| 22 |
-
st.write(df.describe())
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
chart_type = st.selectbox("Pilih jenis chart", ["Scatter Plot", "Bar Chart", "Line Chart"])
|
| 32 |
|
| 33 |
-
if
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
else:
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
else:
|
| 44 |
st.info("Silakan unggah file CSV untuk mulai menganalisis data.")
|
| 45 |
|
| 46 |
# Tambahkan file requirements.txt untuk deploy di Hugging Face
|
| 47 |
with open("requirements.txt", "w") as f:
|
| 48 |
-
f.write("streamlit\npandas\nplotly")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import ydata_profiling
|
| 7 |
+
from streamlit_pandas_profiling import st_profile_report
|
| 8 |
+
from sklearn.linear_model import LinearRegression
|
| 9 |
+
import numpy as np
|
| 10 |
|
| 11 |
# Judul Aplikasi
|
| 12 |
st.set_page_config(page_title='DataViz Pro', layout='wide')
|
|
|
|
| 15 |
# Upload File
|
| 16 |
uploaded_file = st.file_uploader("Upload dataset (CSV)", type=['csv'])
|
| 17 |
|
| 18 |
+
@st.cache_data
|
| 19 |
+
def load_data(file):
|
| 20 |
+
return pd.read_csv(file)
|
| 21 |
+
|
| 22 |
if uploaded_file is not None:
|
| 23 |
+
df = load_data(uploaded_file)
|
| 24 |
st.success("Dataset berhasil diunggah!")
|
| 25 |
|
| 26 |
+
# Sidebar Navigasi
|
| 27 |
+
page = st.sidebar.radio("Navigasi", ["Profiling Data", "Visualisasi Data", "Analisis Korelasi", "Model Prediksi", "Ekspor Data"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
if page == "Profiling Data":
|
| 30 |
+
st.subheader("π Profiling Data")
|
| 31 |
+
profile = df.profile_report()
|
| 32 |
+
st_profile_report(profile)
|
| 33 |
|
| 34 |
+
elif page == "Visualisasi Data":
|
| 35 |
+
st.subheader("Visualisasi Data")
|
| 36 |
+
numeric_columns = df.select_dtypes(include=['number']).columns.tolist()
|
|
|
|
| 37 |
|
| 38 |
+
if numeric_columns:
|
| 39 |
+
x_axis = st.selectbox("Pilih sumbu X", options=numeric_columns)
|
| 40 |
+
y_axis = st.selectbox("Pilih sumbu Y", options=numeric_columns)
|
| 41 |
+
chart_type = st.selectbox("Pilih jenis chart", ["Scatter Plot", "Bar Chart", "Line Chart", "Histogram", "Pie Chart"])
|
| 42 |
+
|
| 43 |
+
if chart_type == "Scatter Plot":
|
| 44 |
+
fig = px.scatter(df, x=x_axis, y=y_axis, title=f"{chart_type} antara {x_axis} dan {y_axis}")
|
| 45 |
+
elif chart_type == "Bar Chart":
|
| 46 |
+
fig = px.bar(df, x=x_axis, y=y_axis, title=f"{chart_type} antara {x_axis} dan {y_axis}")
|
| 47 |
+
elif chart_type == "Line Chart":
|
| 48 |
+
fig = px.line(df, x=x_axis, y=y_axis, title=f"{chart_type} antara {x_axis} dan {y_axis}")
|
| 49 |
+
elif chart_type == "Histogram":
|
| 50 |
+
fig = px.histogram(df, x=x_axis, title=f"{chart_type} dari {x_axis}")
|
| 51 |
+
else:
|
| 52 |
+
category_col = st.selectbox("Pilih kategori untuk Pie Chart", options=df.select_dtypes(include=['object']).columns)
|
| 53 |
+
fig = px.pie(df, names=category_col, title=f"Distribusi {category_col}")
|
| 54 |
+
|
| 55 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 56 |
else:
|
| 57 |
+
st.warning("Dataset tidak memiliki kolom numerik untuk divisualisasikan.")
|
| 58 |
+
|
| 59 |
+
elif page == "Analisis Korelasi":
|
| 60 |
+
st.subheader("π Korelasi Data")
|
| 61 |
+
corr = df.corr()
|
| 62 |
+
fig, ax = plt.subplots(figsize=(10,6))
|
| 63 |
+
sns.heatmap(corr, annot=True, cmap='coolwarm', fmt='.2f', linewidths=0.5, ax=ax)
|
| 64 |
+
st.pyplot(fig)
|
| 65 |
+
|
| 66 |
+
elif page == "Model Prediksi":
|
| 67 |
+
st.subheader("π€ Model Prediksi (Regresi Linear)")
|
| 68 |
+
target_col = st.selectbox("Pilih kolom target", options=df.select_dtypes(include=['number']).columns)
|
| 69 |
+
feature_col = st.selectbox("Pilih kolom fitur", options=df.select_dtypes(include=['number']).columns)
|
| 70 |
|
| 71 |
+
if target_col and feature_col:
|
| 72 |
+
X = df[[feature_col]].dropna()
|
| 73 |
+
y = df[target_col].dropna()
|
| 74 |
+
|
| 75 |
+
if len(X) == len(y):
|
| 76 |
+
model = LinearRegression()
|
| 77 |
+
model.fit(X, y)
|
| 78 |
+
predictions = model.predict(X)
|
| 79 |
+
|
| 80 |
+
st.write(f"Intercept: {model.intercept_}")
|
| 81 |
+
st.write(f"Koefisien: {model.coef_[0]}")
|
| 82 |
+
|
| 83 |
+
fig = px.scatter(df, x=feature_col, y=target_col, title="Prediksi vs Aktual")
|
| 84 |
+
fig.add_scatter(x=X[feature_col], y=predictions, mode='lines', name='Prediksi', line=dict(color='red'))
|
| 85 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 86 |
+
else:
|
| 87 |
+
st.warning("Pastikan tidak ada nilai yang hilang dalam fitur dan target.")
|
| 88 |
+
|
| 89 |
+
elif page == "Ekspor Data":
|
| 90 |
+
st.subheader("π₯ Unduh Hasil Analisis")
|
| 91 |
+
st.download_button("Download Data CSV", df.to_csv(index=False).encode("utf-8"), "filtered_data.csv", "text/csv")
|
| 92 |
else:
|
| 93 |
st.info("Silakan unggah file CSV untuk mulai menganalisis data.")
|
| 94 |
|
| 95 |
# Tambahkan file requirements.txt untuk deploy di Hugging Face
|
| 96 |
with open("requirements.txt", "w") as f:
|
| 97 |
+
f.write("streamlit\npandas\nplotly\nydata-profiling\nstreamlit-pandas-profiling\nseaborn\nsklearn")
|