Update app.py
Browse files
app.py
CHANGED
|
@@ -21,11 +21,14 @@ def load_data():
|
|
| 21 |
df_display = df.drop(columns=[c for c in unnecessary_cols if c in df.columns])
|
| 22 |
return df, df_display
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
model =
|
| 28 |
-
scaler = joblib.load(SCALER_PATH)
|
| 29 |
|
| 30 |
# -------------------------------
|
| 31 |
# 2️⃣ Sayfa ayarları
|
|
@@ -41,22 +44,30 @@ st.subheader("📄 Dataset Preview / Veri Önizleme")
|
|
| 41 |
st.dataframe(df_display.head(10), use_container_width=True)
|
| 42 |
|
| 43 |
# -------------------------------
|
| 44 |
-
# 4️⃣ Görselleştirme
|
| 45 |
# -------------------------------
|
| 46 |
col1, col2 = st.columns(2)
|
| 47 |
|
| 48 |
with col1:
|
| 49 |
st.subheader("📊 Cluster Distribution / Küme Dağılımı")
|
| 50 |
-
st.bar_chart
|
|
|
|
|
|
|
| 51 |
|
| 52 |
with col2:
|
| 53 |
st.subheader("🎯 Feature Analysis / Özellik Analizi")
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
plt.close(fig)
|
| 61 |
|
| 62 |
# -------------------------------
|
|
@@ -101,4 +112,4 @@ st.subheader("🔍 Cluster Characteristics / Küme Özellikleri (Ortalamalar)")
|
|
| 101 |
numeric_only = df.select_dtypes(include=['float64','int64'])
|
| 102 |
if 'cluster' in df.columns:
|
| 103 |
means = numeric_only.groupby(df['cluster']).mean()
|
| 104 |
-
st.dataframe(means, use_container_width=True)
|
|
|
|
| 21 |
df_display = df.drop(columns=[c for c in unnecessary_cols if c in df.columns])
|
| 22 |
return df, df_display
|
| 23 |
|
| 24 |
+
@st.cache_data
|
| 25 |
+
def load_model_scaler():
|
| 26 |
+
model = joblib.load(MODEL_PATH)
|
| 27 |
+
scaler = joblib.load(SCALER_PATH)
|
| 28 |
+
return model, scaler
|
| 29 |
|
| 30 |
+
df, df_display = load_data()
|
| 31 |
+
model, scaler = load_model_scaler()
|
|
|
|
| 32 |
|
| 33 |
# -------------------------------
|
| 34 |
# 2️⃣ Sayfa ayarları
|
|
|
|
| 44 |
st.dataframe(df_display.head(10), use_container_width=True)
|
| 45 |
|
| 46 |
# -------------------------------
|
| 47 |
+
# 4️⃣ Görselleştirme (Titreme önlendi)
|
| 48 |
# -------------------------------
|
| 49 |
col1, col2 = st.columns(2)
|
| 50 |
|
| 51 |
with col1:
|
| 52 |
st.subheader("📊 Cluster Distribution / Küme Dağılımı")
|
| 53 |
+
# Bar chart için st.bar_chart doğrudan kullanıyoruz
|
| 54 |
+
cluster_counts = df['cluster'].value_counts()
|
| 55 |
+
st.bar_chart(cluster_counts)
|
| 56 |
|
| 57 |
with col2:
|
| 58 |
st.subheader("🎯 Feature Analysis / Özellik Analizi")
|
| 59 |
+
# Matplotlib figürünü cache ile tutuyoruz, titremeyi önlüyoruz
|
| 60 |
+
@st.cache_data
|
| 61 |
+
def create_scatter(df):
|
| 62 |
+
fig, ax = plt.subplots(figsize=(8,5))
|
| 63 |
+
scatter = ax.scatter(df['danceability'], df['energy'], c=df['cluster'], cmap='viridis', alpha=0.6)
|
| 64 |
+
ax.set_xlabel("Danceability / Dans Edilebilirlik")
|
| 65 |
+
ax.set_ylabel("Energy / Enerji")
|
| 66 |
+
plt.colorbar(scatter, label="Cluster / Küme")
|
| 67 |
+
return fig
|
| 68 |
+
|
| 69 |
+
fig = create_scatter(df)
|
| 70 |
+
st.pyplot(fig, clear_figure=False)
|
| 71 |
plt.close(fig)
|
| 72 |
|
| 73 |
# -------------------------------
|
|
|
|
| 112 |
numeric_only = df.select_dtypes(include=['float64','int64'])
|
| 113 |
if 'cluster' in df.columns:
|
| 114 |
means = numeric_only.groupby(df['cluster']).mean()
|
| 115 |
+
st.dataframe(means, use_container_width=True)
|