शुरू करेंमुफ़्त में शुरू करें

कितने डॉमिनेंट रंग?

हमने matplotlib की image क्लास के imread() फंक्शन से नीचे दी गई इमेज लोड की है.

RGB वैल्यूज़ एक DataFrame batman_df में स्टोर हैं. इन RGB वैल्यूज़ को whiten() फंक्शन से स्टैंडर्डाइज़ किया गया है, और वे scaled_red, scaled_blue और scaled_green कॉलम्स में हैं.

इस DataFrame के साथ एक elbow plot बनाइए. कितने डॉमिनेंट रंग मौजूद हैं?

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में क्लस्टर विश्लेषण

पाठ्यक्रम देखें

अभ्यास निर्देश

  • num_clusters की हर वैल्यू पर kmeans() फंक्शन चलाकर distortions की एक लिस्ट बनाएँ.
  • लिस्ट्स num_clusters और distortions के साथ एक DataFrame elbow_plot बनाएँ.
  • seaborn की .lineplot() मेथड से प्लॉट बनाइए, जिसमें x-axis पर num_clusters और y-axis पर distortions हों.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

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()
कोड संपादित करें और चलाएँ