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

Sum of Squared Errors की गणना और प्लॉट करें

अब, आप 1 से 10 तक अलग-अलग क्लस्टर्स की संख्या के लिए sum of squared errors की गणना करेंगे.

आप पिछले अभ्यास में बनाया गया normalized RFMT डेटा इस्तेमाल करेंगे, जो datamart_rfmt_normalized के रूप में स्टोर है. scikit-learn से KMeans मॉड्यूल भी इम्पोर्ट किया गया है. साथ ही, हमने sum of squared errors स्टोर करने के लिए एक खाली डिक्शनरी sse = {} के रूप में इनिशियलाइज़ की है.

कंसोल में डेटा को बेझिझक एक्सप्लोर करें.

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

Python में Customer Segmentation

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

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

  • k क्लस्टर्स और random_state 1 के साथ KMeans इनिशियलाइज़ करें और normalized डेटासेट पर KMeans फिट करें.
  • sum of squared distances को sse डिक्शनरी के k element में असाइन करें.
  • प्लॉट का टाइटल "The Elbow Method", X-axis लेबल "k", और Y-axis लेबल "SSE" जोड़ें.
  • डिक्शनरी में keys के रूप में स्टोर प्रत्येक k के लिए SSE वैल्यू को प्लॉट करें.

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

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

# Fit KMeans and calculate SSE for each k between 1 and 10
for k in range(1, 11):
  
    # Initialize KMeans with k clusters and fit it 
    kmeans = ____(____=____, ____=1 ).____(datamart_rfmt_normalized)
    
    # Assign sum of squared distances to k element of the sse dictionary
    ____[____] = kmeans.____   

# Add the plot title, x and y axis labels
plt.____('The Elbow Method')
plt.____('____')
plt.____('____')

# Plot SSE values for each k stored as keys in the dictionary
sns.____(x=list(sse.____()), y=list(sse.____()))
plt.show()
कोड संपादित करें और चलाएँ