How many dominant colors?
We have loaded the following image using the imread() function of the image class of matplotlib.

The RGB values are stored in a DataFrame, batman_df. The RGB values have been standardized used the whiten() function, stored in columns, scaled_red, scaled_blue and scaled_green.
Construct an elbow plot with the DataFrame. How many dominant colors are present?
Cet exercice fait partie du cours
Cluster Analysis in Python
Instructions
- Create a list of distortions based on each value in
num_clustersby running thekmeans()function. - Create a DataFrame
elbow_plotwith the lists:num_clustersanddistortions. - Plot the data with
seaborn's.lineplot()method withnum_clusterson the x-axis anddistortionson the y-axis.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
distortions = []
num_clusters = range(1, 7)
# Create a list of distortions from the kmeans function
for i in ____:
cluster_centers, distortion = ____
distortions.append(____)
# Create a DataFrame with two lists, num_clusters and distortions
elbow_plot = pd.DataFrame(____)
# Create a line plot of num_clusters and distortions
sns.lineplot(x=____, y=____, data = elbow_plot)
plt.xticks(num_clusters)
plt.show()