abizaregi7 commited on
Commit
e897bdc
Β·
verified Β·
1 Parent(s): e6c787d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -74
app.py CHANGED
@@ -1,16 +1,11 @@
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')
13
- st.title('πŸ“Š DataViz Pro - Dashboard Analisis Data')
14
 
15
  # Upload File
16
  uploaded_file = st.file_uploader("Upload dataset (CSV)", type=['csv'])
@@ -23,75 +18,13 @@ 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")
 
1
  import streamlit as st
2
  import pandas as pd
 
 
 
3
  import ydata_profiling
4
  from streamlit_pandas_profiling import st_profile_report
 
 
5
 
6
  # Judul Aplikasi
7
+ st.set_page_config(page_title='Data Profiling', layout='wide')
8
+ st.title('πŸ“Š Data Profiling - Dashboard Analisis Data')
9
 
10
  # Upload File
11
  uploaded_file = st.file_uploader("Upload dataset (CSV)", type=['csv'])
 
18
  df = load_data(uploaded_file)
19
  st.success("Dataset berhasil diunggah!")
20
 
21
+ # Profiling Data
22
+ st.subheader("πŸ” Profiling Data")
23
+ profile = df.profile_report()
24
+ st_profile_report(profile)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  else:
26
  st.info("Silakan unggah file CSV untuk mulai menganalisis data.")
27
 
28
  # Tambahkan file requirements.txt untuk deploy di Hugging Face
29
  with open("requirements.txt", "w") as f:
30
+ f.write("streamlit\npandas\nydata-profiling\nstreamlit-pandas-profiling")