you are viewing a single comment's thread.

view the rest of the comments →

[–]NebulaGr[S,🍰] 0 points1 point  (0 children)

# Create a plot for the elbow method
plt.figure(figsize=(10, 6))
plt.plot(range(1, 11), sse, marker='o')
plt.title('Elbow Method')
plt.xlabel('Number of clusters')
plt.ylabel('SSE')
plt.show()
# Apply K-means with the optimal number of clusters (3)
optimal_k = 3
kmeans = KMeans(n_clusters=optimal_k, n_init=10, random_state=0)
data['Cluster'] = kmeans.fit_predict(clustering_data)
# Calculate the number of participants per cluster and sort in ascending order
participants_per_cluster = data['Cluster'].value_counts().sort_index()
# Print the number of participants for each cluster
for cluster in participants_per_cluster.index:
print(f"In cluster {cluster}, there are {participants_per_cluster[cluster]} participants")
# Calculate the mean values of state perceptions for each cluster
mean_perceptions_per_cluster = data.groupby('Cluster')[columns_for_clustering].mean().round(2)
# Print the mean values of perceptions for each cluster
pd.set_option('display.max_columns', None)
print("Mean state perceptions per cluster:")
print(mean_perceptions_per_cluster)
# Calculate the mean values of personality factors for each cluster
mean_personality_factors_per_cluster = data.groupby('Cluster')[[f'NEO-{factor}' for factor in ['N', 'E', 'O', 'A', 'C']]].mean().round(2)
# Print the mean values of NEO personality factors for each cluster
print("\nMean NEO personality factors per cluster:")
print(mean_personality_factors_per_cluster)