用于检测欺诈的聚类方法

Python 中的欺诈检测

Charlotte Werger

Data Scientist

聚类:发现在数据中的模式

Python 中的欺诈检测

K-means 聚类:利用到聚类中心的距离

Python 中的欺诈检测

K-means 聚类:利用到聚类中心的距离

Python 中的欺诈检测

K-means 聚类:利用到聚类中心的距离

Python 中的欺诈检测

Python 中的欺诈检测

Python 中的欺诈检测

Python 中的欺诈检测

Python 中的 K-means 聚类

# Import the packages
from sklearn.preprocessing import MinMaxScaler
from sklearn.cluster import KMeans

# Transform and scale your data X = np.array(df).astype(np.float)
scaler = MinMaxScaler() X_scaled = scaler.fit_transform(X)
# Define the k-means model and fit to the data kmeans = KMeans(n_clusters=6, random_state=42).fit(X_scaled)
Python 中的欺诈检测

合适的簇数量

检查簇数量:

  • 轮廓系数法
  • 肘部法
clust = range(1, 10) 
kmeans = [KMeans(n_clusters=i) for i in clust]

score = [kmeans[i].fit(X_scaled).score(X_scaled) for i in range(len(kmeans))]
plt.plot(clust,score) plt.xlabel('Number of Clusters') plt.ylabel('Score') plt.title('Elbow Curve') plt.show()
Python 中的欺诈检测

肘部曲线

Python 中的欺诈检测

Passons à la pratique !

Python 中的欺诈检测

Preparing Video For Download...