a <- c(10,9,8)
b<- c(4,3,2)
c<- c(8,9,10)
a
  1. 10
  2. 9
  3. 8
# 余角相似度
sum(a*b)/sqrt(sum(a^2)*sum(b^2))

0.984682118265774

sum(a*c)/sqrt(sum(a^2)*sum(c^2))

0.983673469387755

x<- rbind(a,b,c)
x
a 10 9 8
b 4 3 2
c 8 9 10
# 欧式距离
dist(x)
          a         b
b 10.392305
c  2.828427 10.770330

newiris <-  iris
newiris$Species <- NULL
head(newiris)
Sepal.Length Sepal.Width Petal.Length Petal.Width
5.1 3.5 1.4 0.2
4.9 3.0 1.4 0.2
4.7 3.2 1.3 0.2
4.6 3.1 1.5 0.2
5.0 3.6 1.4 0.2
5.4 3.9 1.7 0.4
kc <- kmeans(newiris,3)
kc
K-means clustering with 3 clusters of sizes 38, 62, 50Cluster means:Sepal.Length Sepal.Width Petal.Length Petal.Width
1     6.850000    3.073684     5.742105    2.071053
2     5.901613    2.748387     4.393548    1.433871
3     5.006000    3.428000     1.462000    0.246000Clustering vector:[1] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3[38] 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2[75] 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 1 1 1 1 2 1 1 1 1
[112] 1 1 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 2 1
[149] 1 2Within cluster sum of squares by cluster:
[1] 23.87947 39.82097 15.15100(between_SS / total_SS =  88.4 %)Available components:[1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
[6] "betweenss"    "size"         "iter"         "ifault"
table(kc$cluster,iris$Species)
    setosa versicolor virginica1      0          2        362      0         48        143     50          0         0

library(cluster)
med <- pam(iris[,-5],3)
med
Medoids:ID Sepal.Length Sepal.Width Petal.Length Petal.Width
[1,]   8          5.0         3.4          1.5         0.2
[2,]  79          6.0         2.9          4.5         1.5
[3,] 113          6.8         3.0          5.5         2.1
Clustering vector:[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1[38] 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2[75] 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 3 3 3 2 3 3 3 3
[112] 3 3 2 2 3 3 3 3 2 3 2 3 2 3 3 2 2 3 3 3 3 3 2 3 3 3 3 2 3 3 3 2 3 3 3 2 3
[149] 3 2
Objective function:build      swap
0.6709391 0.6542077 Available components:[1] "medoids"    "id.med"     "clustering" "objective"  "isolation" [6] "clusinfo"   "silinfo"    "diss"       "call"       "data"
table(med$cluster,iris$Species)
    setosa versicolor virginica1     50          0         02      0         48        143      0          2        36




library(arules)
Loading required package: MatrixAttaching package: 'arules'The following objects are masked from 'package:base':abbreviate, write
data(Groceries)
Groceries
transactions in sparse format with9835 transactions (rows) and169 items (columns)
summary(Groceries)
transactions as itemMatrix in sparse format with9835 rows (elements/itemsets/transactions) and169 columns (items) and a density of 0.02609146 most frequent items:whole milk other vegetables       rolls/buns             soda 2513             1903             1809             1715 yogurt          (Other) 1372            34055 element (itemset/transaction) length distribution:
sizes1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16
2159 1643 1299 1005  855  645  545  438  350  246  182  117   78   77   55   46 17   18   19   20   21   22   23   24   26   27   28   29   32 29   14   14    9   11    4    6    1    1    1    1    3    1 Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 1.000   2.000   3.000   4.409   6.000  32.000 includes extended item information - examples:labels  level2           level1
1 frankfurter sausage meat and sausage
2     sausage sausage meat and sausage
3  liver loaf sausage meat and sausage
freq = eclat(Groceries,parameter = list(support=0.06,maxlen=10))
Eclatparameter specification:tidLists support minlen maxlen            target   extFALSE    0.06      1     10 frequent itemsets FALSEalgorithmic control:sparse sort verbose7   -2    TRUEAbsolute minimum support count: 590 create itemset ...
set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
sorting and recoding items ... [20 item(s)] done [0.00s].
creating sparse bit matrix ... [20 row(s), 9835 column(s)] done [0.00s].
writing  ... [21 set(s)] done [0.00s].
Creating S4 object  ... done [0.00s].
inspect(freq)
     items                         support    count
[1]  {other vegetables,whole milk} 0.07483477  736
[2]  {whole milk}                  0.25551601 2513
[3]  {other vegetables}            0.19349263 1903
[4]  {rolls/buns}                  0.18393493 1809
[5]  {yogurt}                      0.13950178 1372
[6]  {soda}                        0.17437722 1715
[7]  {root vegetables}             0.10899847 1072
[8]  {tropical fruit}              0.10493137 1032
[9]  {bottled water}               0.11052364 1087
[10] {sausage}                     0.09395018  924
[11] {shopping bags}               0.09852567  969
[12] {citrus fruit}                0.08276563  814
[13] {pastry}                      0.08896797  875
[14] {pip fruit}                   0.07564820  744
[15] {whipped/sour cream}          0.07168277  705
[16] {fruit/vegetable juice}       0.07229283  711
[17] {domestic eggs}               0.06344687  624
[18] {newspapers}                  0.07981698  785
[19] {brown bread}                 0.06487036  638
[20] {bottled beer}                0.08052872  792
[21] {canned beer}                 0.07768175  764
model <- apriori(Groceries,parameter = list(support=0.01,confidence=0.5))
AprioriParameter specification:confidence minval smax arem  aval originalSupport maxtime support minlen0.5    0.1    1 none FALSE            TRUE       5    0.01      1maxlen target   ext10  rules FALSEAlgorithmic control:filter tree heap memopt load sort verbose0.1 TRUE TRUE  FALSE TRUE    2    TRUEAbsolute minimum support count: 98 set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
sorting and recoding items ... [88 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 3 4 done [0.00s].
writing ... [15 rule(s)] done [0.00s].
creating S4 object  ... done [0.00s].
inspect(model)
     lhs                                      rhs                support
[1]  {curd,yogurt}                         => {whole milk}       0.01006609
[2]  {other vegetables,butter}             => {whole milk}       0.01148958
[3]  {other vegetables,domestic eggs}      => {whole milk}       0.01230300
[4]  {yogurt,whipped/sour cream}           => {whole milk}       0.01087951
[5]  {other vegetables,whipped/sour cream} => {whole milk}       0.01464159
[6]  {pip fruit,other vegetables}          => {whole milk}       0.01352313
[7]  {citrus fruit,root vegetables}        => {other vegetables} 0.01037112
[8]  {tropical fruit,root vegetables}      => {other vegetables} 0.01230300
[9]  {tropical fruit,root vegetables}      => {whole milk}       0.01199797
[10] {tropical fruit,yogurt}               => {whole milk}       0.01514997
[11] {root vegetables,yogurt}              => {other vegetables} 0.01291307
[12] {root vegetables,yogurt}              => {whole milk}       0.01453991
[13] {root vegetables,rolls/buns}          => {other vegetables} 0.01220132
[14] {root vegetables,rolls/buns}          => {whole milk}       0.01270971
[15] {other vegetables,yogurt}             => {whole milk}       0.02226741confidence lift     count
[1]  0.5823529  2.279125  99
[2]  0.5736041  2.244885 113
[3]  0.5525114  2.162336 121
[4]  0.5245098  2.052747 107
[5]  0.5070423  1.984385 144
[6]  0.5175097  2.025351 133
[7]  0.5862069  3.029608 102
[8]  0.5845411  3.020999 121
[9]  0.5700483  2.230969 118
[10] 0.5173611  2.024770 149
[11] 0.5000000  2.584078 127
[12] 0.5629921  2.203354 143
[13] 0.5020921  2.594890 120
[14] 0.5230126  2.046888 125
[15] 0.5128806  2.007235 219
inspect(subset(model,subset = rhs%in%"whole milk"&lift>2.2))
    lhs                                 rhs          support    confidence
[1] {curd,yogurt}                    => {whole milk} 0.01006609 0.5823529
[2] {other vegetables,butter}        => {whole milk} 0.01148958 0.5736041
[3] {tropical fruit,root vegetables} => {whole milk} 0.01199797 0.5700483
[4] {root vegetables,yogurt}         => {whole milk} 0.01453991 0.5629921 lift     count
[1] 2.279125  99
[2] 2.244885 113
[3] 2.230969 118
[4] 2.203354 143

R 语言聚类关联规则相关推荐

  1. R语言实现关联规则与推荐算法(学习笔记)

    R语言实现关联规则 笔者前言:以前在网上遇到很多很好的关联规则的案例,最近看到一个更好的,于是便学习一下,写个学习笔记. 推荐算法中 物品-物品用关联规则: 人物-物品用协同过滤: 人-人用社会网络分 ...

  2. R 语言 基于关联规则与聚类分析的消费行为统计

    <金融数据挖掘案例分析> 课程设计报告 题 目: 基于关联规则与聚类分析的消费行为统计 学生姓名: 序号: 学生姓名: 序号: 学生姓名: 序号: 学生姓名: 序号: 指导教师: 信息工程 ...

  3. 基于R语言的关联规则分析项目

    转自http://blog.163.com/dm_team/blog/static/2379750132014891084989/ 摘要 抱着成为一名优秀的数据分析师/数据挖掘师的理想,我们组成了一个 ...

  4. pvrect r语言 聚类_R语言一条命令实现基于样本和距离的聚类分析

    上一篇文章给大家介绍了利用 R语言的 hclust()进行聚类分析的步骤,已经很简单了,但是依然有不少小伙伴来问 "老师,还有更简单的方法吗,最好是一条命令那种",为了满足的大家的 ...

  5. r语言 聚类求和_R语言聚类分析,如何导出将分类结果?

    泻药,本文在数据集上展示了如何来增强Hierarchical Cluster Analysis(更好的可视化和灵敏度分析). 原文链接:R语言鸢尾花iris数据集的层次聚类分析​tecdat.cn 介 ...

  6. python调用R语言,关联规则可视化

    首先当然要配置r语言环境变量什么的 D:\R-3.5.1\bin\x64; D:\R-3.5.1\bin\x64\R.dll; D:\R-3.5.1; D:\ProgramData\Anaconda3 ...

  7. pvrect r语言 聚类_R语言常用统计方法包+机器学习包(名称、简介)

    上期帮大家盘点了一下R中常用的可视化包,这期将简要盘点一下关于统计分析与机器学习的R包,并通过简要介绍包的特点来帮助读者深入理解可视化包. 本文作者为"食物链顶端"学习群中的小伙伴 ...

  8. R语言聚类算法之期望最大化聚类(Expectation Maximization Algorithm)

    1.原理解析: 它将数据集看作一个含有隐性变量的概率模型,并以实现模型最优化,即获取与数据本身性质最契合的聚类方式为目的,通过"反复估计"模型参数找到最优解,同时给出相应的最优类别 ...

  9. R语言聚类算法之密度聚类(Density-based Methods)

    1.原理解析: 1.从数据集中选择一个未处理的样本点 2.以1为圆心,做半径为E的圆,由于圆内圈入点的个数为3,满足密度阈值Minpts,因此称点1为核心对象(黑色实心圆点),且将圈内的4个点形成一个 ...

最新文章

  1. 分布式系统的面试题11
  2. UML中的用例(Use Case)概念分析及实例
  3. 问题集锦(26-29)
  4. Swift 位运算练习
  5. T型加速算法fpga实现思想研究
  6. MATLAB机器学习系列-4函数篇
  7. LAMP环境下动态网站许愿墙的搭建
  8. 不经意传输(oblivious transfer)
  9. 超人气光棍节!现在时间虽然不是2011年11月11日11点11分11秒11毫秒11微秒11纳秒11皮秒11飞秒11阿秒11渺秒11......
  10. Linux内核深入理解定时器和时间管理(3):tick 广播 框架 和 dyntick
  11. java教程win7 64位_win7系统安装64位JAVA的方法
  12. Linux配置手册(五)Linux 配置域名服务器(DNS)
  13. IDEA合并SVN分支代码到主干
  14. 给力大辞典v3.0 免费安装版【包含18部字典词典】
  15. java uniapp旅游微信小程序的开发hbuilderx
  16. Context-Aware Zero-Shot Recognition 论文翻译
  17. 计算机开机后黑屏鼠标显示桌面图标,电脑开机后黑屏怎么解决只显示鼠标
  18. AutoCAD 2019 常用命令速查手册
  19. 分布式配置中心设计——思维导图总结
  20. windows下python运行的方法

热门文章

  1. micropython是啥 知乎_micropython入门教程
  2. 快速广义的形态分量分析 matlab,独立分量分析法降噪技术研究
  3. 版本变迁_冰枪?卢登?大天使?——从发条魔灵的装备变迁看版本变动
  4. phpcms mysql 事务_phpcms某站点MySQL报错注入
  5. Linux Shell脚本编程基础(11)
  6. js-ajax-04
  7. CSS定位网页中的元素
  8. 大白鱼备考云笔记冲刺周期第一天
  9. Android笔记(七十) AlertDialog
  10. hdu 2025 查找最大元素 (水)