k-means clustering का व्यावहारिक इम्प्लीमेंटेशन

Python में Customer Segmentation

Karolis Urbonas

Head of Data Science, Amazon

मुख्य स्टेप्स

  • डेटा प्री-प्रोसेसिंग
  • क्लस्टर्स की संख्या चुनना
  • प्री-प्रोसेस्ड डेटा पर k-means चलाना
  • हर क्लस्टर के औसत RFM मानों का विश्लेषण
Python में Customer Segmentation

डेटा प्री-प्रोसेसिंग

हमने प्री-प्रोसेसिंग पूरी कर ली है और ये दो ऑब्जेक्ट्स हैं:

  • datamart_rfm
  • datamart_normalized
import numpy as np
datamart_log = np.log(datamart_rfm)

from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit(datamart_log)

datamart_normalized = scaler.transform(datamart_log)
Python में Customer Segmentation

क्लस्टर्स की संख्या तय करने के तरीके

  • विज़ुअल तरीके - elbow criterion
  • गणितीय तरीके - silhouette coefficient
  • प्रयोग और व्याख्या
Python में Customer Segmentation

k-means चलाना

# पैकेज इम्पोर्ट करें
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=2, random_state=1)
# प्री-प्रोसेस्ड डेटा पर k-means क्लस्टरिंग चलाएँ
kmeans.fit(datamart_normalized)
# labels_ एट्रिब्यूट से क्लस्टर लेबल निकालें
cluster_labels = kmeans.labels_
Python में Customer Segmentation

हर क्लस्टर के औसत RFM मानों का विश्लेषण

# मूल DataFrame में क्लस्टर लेबल कॉलम बनाएँ
datamart_rfm_k2 = datamart_rfm.assign(Cluster = cluster_labels)
# हर क्लस्टर के औसत RFM मान और साइज निकालें
datamart_rfm_k2.groupby(['Cluster']).agg({
    'Recency': 'mean',
    'Frequency': 'mean',
    'MonetaryValue': ['mean', 'count'],
}).round(0)
Python में Customer Segmentation

हर क्लस्टर के औसत RFM मानों का विश्लेषण

सिंपल 2-क्लस्टर सॉल्यूशन का रिज़ल्ट:

Python में Customer Segmentation

आइए k-means clustering चलाने का अभ्यास करें!

Python में Customer Segmentation

Preparing Video For Download...