- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 49955 个
- 通用积分
- 79.3687
- 学术水平
- 253 点
- 热心指数
- 300 点
- 信用等级
- 208 点
- 经验
- 41518 点
- 帖子
- 3256
- 精华
- 14
- 在线时间
- 766 小时
- 注册时间
- 2006-5-4
- 最后登录
- 2022-11-6
|
- Example 9-2. k-means example, in Python
- import h2o
- h2o.init()
- tfidf = h2o.import_file("./datasets/movie.tfidf.csv")
- from h2o.estimators.K-means import H2OKMeansEstimator
- m = H2OKMeansEstimator(k=5, standardize=False, init="PlusPlus")
- m.train(x=range(1,564), training_frame=tfidf)
- #Get the group that each movie is in
- p = m.predict(tfidf)
- #Join that to our movie names, then download it
- d = tfidf[0].cbind(p).as_data_frame()
- d.columns = ["movie","group"]
- #Iterate through and print each group
- for ix, g in d.groupby("group"):
- print "---",ix,"---"
- print ', '.join(g["movie"])
复制代码
|
|