导入数据
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
ageinc_df=pd.read_csv(‘w3_ageinc.csv’)
ageinc_df.info()
#两列数据,年龄与收入
ageinc_df.describe()
#现在进行聚类分析
from sklearn import cluster
model=cluster.KMeans(n_clusters=3,random_state=10)
model.fit(ageinc_df[[‘z_income’,‘z_age’]])
#导入sklearn中的cluster
#将群体分成3层
#用标准化的收入与年龄来拟合模型
#将用户分为6层