JERNGOC commited on
Commit
1a2ec06
1 Parent(s): 4df47b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -40,7 +40,7 @@ if uploaded_file is not None:
40
  # 使用保存的 K-means 模型進行聚類
41
  kmeans_labels = kmeans.predict(pca_df)
42
 
43
- # 使用保存的階層式聚類結果
44
  hclust_labels = fcluster(linked, 3, criterion='maxclust')
45
 
46
  # 使用保存的 DBSCAN 模型進行聚類
@@ -49,12 +49,12 @@ if uploaded_file is not None:
49
  # ================== 圖表選擇 ==================
50
  chart_option = st.selectbox(
51
  "選擇要顯示的聚類結果圖表",
52
- ("K-means", "階層式聚類", "DBSCAN")
53
  )
54
 
55
  # ================== 根據選擇顯示對應的圖表 ==================
56
  if chart_option == "K-means":
57
- st.subheader("K-means 聚類結果")
58
  fig_kmeans, ax_kmeans = plt.subplots()
59
  ax_kmeans.scatter(pca_df['PC1'], pca_df['PC2'], c=kmeans_labels, cmap='viridis')
60
  ax_kmeans.set_title('K-means Clustering')
@@ -62,8 +62,8 @@ if uploaded_file is not None:
62
  ax_kmeans.set_ylabel('PC2')
63
  st.pyplot(fig_kmeans)
64
 
65
- elif chart_option == "階層式聚類":
66
- st.subheader("階層式聚類結果")
67
  fig_hclust, ax_hclust = plt.subplots()
68
  ax_hclust.scatter(pca_df['PC1'], pca_df['PC2'], c=hclust_labels, cmap='viridis')
69
  ax_hclust.set_title('Hierarchical Clustering')
@@ -72,7 +72,7 @@ if uploaded_file is not None:
72
  st.pyplot(fig_hclust)
73
 
74
  elif chart_option == "DBSCAN":
75
- st.subheader("DBSCAN 聚類結果")
76
  fig_dbscan, ax_dbscan = plt.subplots()
77
  ax_dbscan.scatter(pca_df['PC1'], pca_df['PC2'], c=dbscan_labels, cmap='viridis')
78
  ax_dbscan.set_title('DBSCAN Clustering')
 
40
  # 使用保存的 K-means 模型進行聚類
41
  kmeans_labels = kmeans.predict(pca_df)
42
 
43
+ # 使用保存的Hierarchical Clustering 階層式聚類結果
44
  hclust_labels = fcluster(linked, 3, criterion='maxclust')
45
 
46
  # 使用保存的 DBSCAN 模型進行聚類
 
49
  # ================== 圖表選擇 ==================
50
  chart_option = st.selectbox(
51
  "選擇要顯示的聚類結果圖表",
52
+ ("K-means", "Hierarchical Clustering", "DBSCAN")
53
  )
54
 
55
  # ================== 根據選擇顯示對應的圖表 ==================
56
  if chart_option == "K-means":
57
+ st.subheader("K-means_聚類結果")
58
  fig_kmeans, ax_kmeans = plt.subplots()
59
  ax_kmeans.scatter(pca_df['PC1'], pca_df['PC2'], c=kmeans_labels, cmap='viridis')
60
  ax_kmeans.set_title('K-means Clustering')
 
62
  ax_kmeans.set_ylabel('PC2')
63
  st.pyplot(fig_kmeans)
64
 
65
+ elif chart_option == "Hierarchical Clustering":
66
+ st.subheader("Hierarchical Clustering_階層式聚類結果")
67
  fig_hclust, ax_hclust = plt.subplots()
68
  ax_hclust.scatter(pca_df['PC1'], pca_df['PC2'], c=hclust_labels, cmap='viridis')
69
  ax_hclust.set_title('Hierarchical Clustering')
 
72
  st.pyplot(fig_hclust)
73
 
74
  elif chart_option == "DBSCAN":
75
+ st.subheader("DBSCAN_聚類結果")
76
  fig_dbscan, ax_dbscan = plt.subplots()
77
  ax_dbscan.scatter(pca_df['PC1'], pca_df['PC2'], c=dbscan_labels, cmap='viridis')
78
  ax_dbscan.set_title('DBSCAN Clustering')