
无监督学习
|
261
size loan_amnt annual_inc revol_bal open_acc dti revol_util
1 7355 10467.65 51134.87 11523.31 7.48 15.78 77.73
2 5309 10363.43 53523.09 6038.26 8.68 11.32 30.70
3 3713 25894.07 116185.91 32797.67 12.41 16.22 66.14
4 6294 13361.61 55596.65 16375.27 14.25 24.23 59.61
在
Python
中,可以使用
scikit-learn
中的
StandardScaler
方法。
inverse_transform
方法
可以将簇中心点转换回初始的数量级:
scaler = preprocessing.StandardScaler()
df0 = scaler.fit_transform(df * 1.0)
kmeans = KMeans(n_clusters=4, random_state=1).fit(df0)
counts = Counter(kmeans.labels_)
centers = pd.DataFrame(scaler.inverse_transform(kmeans.cluster_centers_),
columns=columns)
centers['size'] = [counts[i] for i in range(4)] ...