WEKA进行Apriori、FP-Tree、K-means算法测试

1.Apriori算法

(1)数据

动作 战争 
喜剧 爱情 
剧情 动作 犯罪 
剧情 动作 战争 
科幻 灾难 
喜剧 爱情 奇幻 
动作 战争
喜剧 奇幻 
剧情 
剧情

Weka能识别的文件类型是.arff文件,我们需要将已有数据转为.arff格式数据。

@relation movie
@attribute 动作 {False, True}
@attribute 战争 {False, True}
@attribute 喜剧 {False, True}
@attribute 爱情 {False, True}
@attribute 剧情 {False, True}
@attribute 犯罪 {False, True}
@attribute 科幻 {False, True}
@attribute 灾难 {False, True}
@attribute 奇幻 {False, True}

@data
True,True,?,?,?,?,?,?,?
?,?,True,True,?,?,?,?,?
True,?,?,?,True,True,?,?,?
True,?,True,?,True,?,?,?,?
?,?,?,?,?,?,True,True,?
?,?,True,True,?,?,?,?,True
True,True,?,?,?,?,?,?,?
?,?,True,?,?,?,?,?,True
?,?,?,?,True,?,?,?,?
?,?,?,?,True,?,?,?,?

@relation:关系名,可随意起名

@attribute:属性名,后面可跟数据类型或{},{}中需要限定该属性的取值

@data:之后每一行均为一个事务,未知属性值使用?表示;使用稀疏矩阵时需要加{}

(2)导入数据

   

打开weka,点击Explorer

 

   

点击open file,选择刚才所创建的.arff文件。

weka识别出我们的属性和实例。

weka默认情况下使用的编码不支持中文数据,需要进行设置

打开weka安装目录,使用记事本打开RunWeka.ini

将fileEncoding改为utf-8,重新打开weka即可。

打开数据文件后,点击Associate

主要设置三个参数:最小支持度、最小置信度和最大规则数

点start

对应的关联规则显示出来,完成

2.FP-Tree

数据如上

选择与Apriori同样的参数,其他参数不改。点击start,得到与Apriori相同的结果

3.K-means

(1)数据

@relation ActorK-meansData

@attribute 作品数量 numeric
@attribute 获奖次数 numeric
@attribute 粉丝数量 numeric
@attribute 年龄 numeric
%共有25种电影题材
%喜剧 情色 科幻 运动 恐怖 灾难 同性 犯罪 动画 传记 纪录片 惊悚 冒险 奇幻 历史 悬疑 古装 音乐 剧情 短片 武侠 爱情 家庭 战争 动作
@attribute 喜剧 numeric
@attribute 情色 numeric
@attribute 科幻 numeric
@attribute 运动 numeric
@attribute 恐怖 numeric
@attribute 灾难 numeric
@attribute 同性 numeric
@attribute 犯罪 numeric
@attribute 动画 numeric
@attribute 传记 numeric
@attribute 纪录片 numeric
@attribute 惊悚 numeric
@attribute 冒险 numeric
@attribute 奇幻 numeric
@attribute 历史 numeric
@attribute 悬疑 numeric
@attribute 古装 numeric
@attribute 音乐 numeric
@attribute 剧情 numeric
@attribute 短片 numeric
@attribute 武侠 numeric
@attribute 爱情 numeric
@attribute 家庭 numeric
@attribute 战争 numeric
@attribute 动作 numeric

@data
8.7, 3.0, 4.875, 45.0, 3.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 2.0, 0.0, 3.0, 4.0
8.1, 14.0, 18.124, 62.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 1.0, 0.0, 0.0, 7.0, 0.0, 0.0, 2.0, 1.0, 0.0, 5.0
3.6, 4.0, 27.128, 40.0, 5.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 7.0, 1.0, 0.0, 8.0, 1.0, 0.0, 1.0
10.4, 10.0, 4.202, 56.0, 3.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0, 1.0, 0.0, 0.0, 5.0, 0.0, 2.0, 3.0, 0.0, 0.0, 12.0
11.0, 12.0, 29.32, 45.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 2.0, 2.0, 1.0, 0.0, 10.0, 0.0, 0.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

点击start

Cluster
Attribute         0       1       2       3
             (0.26)   (0.5)  (0.15)  (0.08)
============================================
作品数量
  mean       14.7071  7.8479   7.759    7.35
  std. dev.   9.6824  3.7663  1.2696    3.65

获奖次数
  mean        6.7197  4.2627   2.489       6
  std. dev.   4.9309  4.0343  2.5919       6

粉丝数量
  mean       12.9352  8.3796  5.8751 15.9365
  std. dev.  11.4766  6.5945  2.3405 13.3835

年龄
  mean       52.1857 39.2941  31.247      38
  std. dev.  10.4549  7.6533    5.29       7

喜剧
  mean        7.8995  3.6442  4.4823       1
  std. dev.   3.0406   2.254  1.1333       1

情色
  mean             0  0.0762       0       0
  std. dev.   0.1961  0.2654  0.1961  0.1961

科幻
  mean        0.5838   0.686       0     0.5
  std. dev.   0.4932  1.1325  0.0001     0.5

运动
  mean        0.1459       0       0     0.5
  std. dev.    0.353  0.2717  0.2717     0.5

恐怖
  mean        0.1459  0.1503  0.2553       0
  std. dev.    0.353  0.3574   0.436  0.3679

灾难
  mean        0.1458       0       0       0
  std. dev.    0.353  0.0058       0  0.1961

同性
  mean        0.1459       0       0       0
  std. dev.    0.353       0  0.1961  0.1961

犯罪
  mean        1.5693  0.9292  1.0068     0.5
  std. dev.   1.7031  0.8194       1     0.5

动画
  mean        1.1674  0.2286  0.2483       0
  std. dev.   1.7363  0.4199   0.432   1.067

传记
  mean             0  0.2287  0.2483       0
  std. dev.   0.0003    0.42   0.432  0.3679

纪录片
  mean             0       0       0       1
  std. dev.   0.2717       0  0.2717       0

惊悚
  mean        0.1102  0.3998       0     0.5
  std. dev.   0.3132   0.835       0     0.5

冒险
  mean        1.7438  0.7639  0.7519     0.5
  std. dev.   1.2845  0.7892  0.4319     0.5

奇幻
  mean        2.2491  2.6321  1.7519     1.5
  std. dev.   1.9095  1.4438  0.8265     0.5

历史
  mean        0.2919  0.3811  0.2483       2
  std. dev.   0.7061  0.4856   0.432  0.0001

悬疑
  mean        0.5481  1.4605  1.2621       1
  std. dev.   0.7345  1.0696   0.839       1

古装
  mean        0.1602  0.9813  0.5036       2
  std. dev.   0.3668  0.7925   0.864       1

音乐
  mean             0       0   0.993       0
  std. dev.   0.0001  0.0067  0.0833  0.3679

剧情
  mean         3.481  5.7936   5.993    10.5
  std. dev.   2.1027  1.3419  1.2234     0.5

短片
  mean         0.146  0.3811  1.4896       0
  std. dev.   0.3532  0.4857  0.5137  0.6469

武侠
  mean        0.0143  0.3737  0.7447       0
  std. dev.   0.1186  0.6217   0.436       0

爱情
  mean        1.5019  4.7735  2.5034     5.5
  std. dev.   0.8893  2.6328     0.5     0.5

家庭
  mean        0.2918  0.0762  0.2483     0.5
  std. dev.   0.4546  0.2654   0.432     0.5

战争
  mean        0.4378  0.5336  0.2481     1.5
  std. dev.    1.059  0.9267  0.4319     0.5

动作
  mean        5.6656   3.365  2.2412       0
  std. dev.   3.0585  3.2237  1.9165  0.0001

这儿显示的是每个簇的簇心各个参数的值以及对应的标准差。

通过这些信息,我们并不能知道每个事务所处的簇。

进一步查看信息

分配图有点抽象,我们直接点击save,此时会保存一个簇分配文件。

 

该文件为.arff文件,其中的实例最后一个属性为该实例所处的簇。

@relation ActorK-meansData_clustered

@attribute Instance_number numeric
@attribute 作品数量 numeric
@attribute 获奖次数 numeric
@attribute 粉丝数量 numeric
@attribute 年龄 numeric
@attribute 喜剧 numeric
@attribute 情色 numeric
@attribute 科幻 numeric
@attribute 运动 numeric
@attribute 恐怖 numeric
@attribute 灾难 numeric
@attribute 同性 numeric
@attribute 犯罪 numeric
@attribute 动画 numeric
@attribute 传记 numeric
@attribute 纪录片 numeric
@attribute 惊悚 numeric
@attribute 冒险 numeric
@attribute 奇幻 numeric
@attribute 历史 numeric
@attribute 悬疑 numeric
@attribute 古装 numeric
@attribute 音乐 numeric
@attribute 剧情 numeric
@attribute 短片 numeric
@attribute 武侠 numeric
@attribute 爱情 numeric
@attribute 家庭 numeric
@attribute 战争 numeric
@attribute 动作 numeric
@attribute Cluster {cluster0,cluster1,cluster2,cluster3}

@data
0,8.7,3,4.875,45,3,0,1,0,0,1,0,1,0,0,0,0,0,2,0,0,0,0,4,0,0,2,0,3,4,cluster2
1,8.1,14,18.124,62,6,0,0,0,0,0,1,0,1,0,0,0,1,0,2,1,0,0,7,0,0,2,1,0,5,cluster3
2,3.6,4,27.128,40,5,1,0,0,0,0,0,1,0,1,0,0,0,1,0,1,1,0,7,1,0,8,1,0,1,cluster3
3,10.4,10,4.202,56,3,0,1,0,0,0,0,2,0,1,0,1,2,3,1,1,0,0,5,0,2,3,0,0,12,cluster1
4,11,12,29.32,45,2,0,1,0,0,0,0,1,0,0,1,1,0,1,2,2,1,0,10,0,0,5,0,1,0,cluster3
5,7.3,4,4.466,46,1,0,4,0,1,0,0,2,0,0,0,3,1,1,1,2,0,0,4,0,0,2,0,1,7,cluster1
6,12.4,5,37.569,57,10,0,1,1,0,0,0,0,2,0,0,0,2,6,0,0,0,0,2,0,0,3,1,0,3,cluster2
7,13.5,7,9.996,38,2,0,2,0,0,0,0,0,1,0,0,0,0,3,1,1,0,0,6,1,0,1,0,2,6,cluster2
8,13.2,14,8.364,33,4,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,9,0,1,8,0,0,2,cluster3
9,28.2,13,12.947,58,5,0,0,0,0,0,0,5,0,0,0,0,4,1,0,2,0,0,5,0,0,1,0,0,9,cluster2
10,30.7,8,8.486,65,11,0,1,0,0,0,0,3,5,0,0,0,3,2,0,0,0,0,3,1,0,1,0,0,11,cluster2
11,11.7,8,18.223,43,6,0,0,0,0,0,0,0,0,0,0,0,2,4,0,0,1,0,6,0,1,3,0,0,3,cluster2
12,4.4,1,4.798,37,1,0,0,0,0,0,0,2,0,0,0,0,0,2,1,4,1,0,7,1,0,8,0,0,4,cluster3
13,9,0,2.828,27,4,0,0,0,0,0,0,2,0,1,0,0,1,1,1,1,0,1,7,2,0,2,1,0,0,cluster3
14,7.9,4,9.179,27,3,0,0,0,1,0,0,0,1,0,0,0,1,2,0,0,0,1,7,1,1,3,0,0,1,cluster2
15,3.7,0,2.553,31,0,0,0,1,0,0,0,0,0,0,1,0,1,2,2,0,3,0,11,0,0,6,1,2,0,cluster0
16,8.5,6,6.704,40,6,0,0,0,0,0,0,2,0,0,0,0,0,1,0,2,0,1,6,1,1,3,0,1,3,cluster2
17,8,3,2.545,35,10,0,0,0,0,0,0,1,0,0,0,1,1,4,0,1,0,0,3,0,0,0,0,0,6,cluster2
18,3.2,0,4.533,35,8,0,1,0,0,0,0,0,0,0,0,1,0,2,0,1,2,0,6,0,1,9,0,0,0,cluster3
19,5.3,2,3.351,30,5,0,0,0,0,0,0,1,1,0,0,0,1,5,0,2,1,0,5,0,0,5,0,0,0,cluster3
20,5.5,1,5.841,31,2,0,0,0,1,0,0,2,0,0,0,0,1,2,0,3,1,0,5,0,0,3,0,0,1,cluster3
21,10.4,1,8.838,51,3,0,0,0,0,0,0,1,0,0,0,0,0,1,0,1,1,0,6,1,0,3,0,3,2,cluster2
22,11,2,3.043,41,5,0,0,0,0,0,0,0,1,1,0,0,2,4,0,2,3,0,6,0,0,6,0,0,2,cluster3
23,5.7,0,4.791,31,5,0,0,0,0,0,0,0,0,0,0,0,1,3,0,2,2,1,4,2,1,2,0,0,5,cluster3
24,2.8,2,8.475,31,1,0,0,0,0,0,0,1,0,0,0,0,1,5,1,1,1,0,4,1,0,4,0,1,3,cluster3
25,5.5,0,2.939,40,11,0,1,0,1,0,0,1,0,0,0,0,1,1,0,0,1,0,0,0,0,1,0,0,2,cluster2

ok,完工。

  • 2
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值