Tryfonas commited on
Commit
c2c9bcb
·
verified ·
1 Parent(s): 0e2c35a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. BDS24_Weekly_Assignments/app.py +4 -4
BDS24_Weekly_Assignments/app.py CHANGED
@@ -380,14 +380,14 @@ elif page == "KMeans Clustering & Recommendations":
380
  # Visualize the clustering results at different iterations
381
  max_iters = [1, 2, 5, 6, 8, 10] # Different iterations you want to visualize
382
 
383
- # Increase the figure size for better visibility
384
- plt.figure(figsize=(15, 55)) # Adjusted the figsize to make plots larger
385
  for i, max_iter in enumerate(max_iters, start=1):
386
  kmeans = KMeans(n_clusters=optimal_clusters, random_state=42, max_iter=max_iter)
387
  df_original['cluster'] = kmeans.fit_predict(df_pca)
388
 
389
  # Plotting the clusters
390
- plt.subplot(6, 1, i) # Changed the layout to 3 rows x 2 columns for larger plots
391
  sns.scatterplot(x=df_pca[:, 0], y=df_pca[:, 1], hue=df_original['cluster'], palette='viridis', s=100)
392
 
393
  # Plotting the centroids
@@ -405,7 +405,7 @@ elif page == "KMeans Clustering & Recommendations":
405
  plt.tight_layout()
406
  st.pyplot(plt.gcf())
407
 
408
- # New Input: Select a cluster and display top 10 data points
409
  st.subheader("Explore a Cluster")
410
  selected_cluster = st.selectbox("Select a Cluster", options=sorted(df_original['cluster'].unique()))
411
 
 
380
  # Visualize the clustering results at different iterations
381
  max_iters = [1, 2, 5, 6, 8, 10] # Different iterations you want to visualize
382
 
383
+
384
+ plt.figure(figsize=(15, 55))
385
  for i, max_iter in enumerate(max_iters, start=1):
386
  kmeans = KMeans(n_clusters=optimal_clusters, random_state=42, max_iter=max_iter)
387
  df_original['cluster'] = kmeans.fit_predict(df_pca)
388
 
389
  # Plotting the clusters
390
+ plt.subplot(6, 1, i)
391
  sns.scatterplot(x=df_pca[:, 0], y=df_pca[:, 1], hue=df_original['cluster'], palette='viridis', s=100)
392
 
393
  # Plotting the centroids
 
405
  plt.tight_layout()
406
  st.pyplot(plt.gcf())
407
 
408
+ # Select a cluster and display top 10 data points
409
  st.subheader("Explore a Cluster")
410
  selected_cluster = st.selectbox("Select a Cluster", options=sorted(df_original['cluster'].unique()))
411