R language Combat K-means clustering and association rules algorithm

Source: Internet
Author: User

1, R language about K-means clustering

The data set format is as follows:

, Hedong Road and Ao Dong Lu & Hedong Road and Poly-Xian Bridge Road, Hedong Road and AO East Road & New Yue Road and Ao Road, Hedong and Ao Dong Lu & Torch Road and Poly-Xian Bridge Road, Hedong Road and Ao Dong Lu & Torch Road and Hui Zhi Qiao Road, Hedong Road and Ao Road & Hui Zhi Qiao and Intellectual Island Road, Xin Yue Road and Ao Dong Road & Torch Road and the Poly-Xian Bridge Road, New Yue Road and Ao Dong Road & Hedong Lu and Poly Xian Bridge Road, New Yue Road and AO East Road & Hedong Rd and Ao Dong Lu, New Yue Road and AO East Street & Wisdom Bridge and Intellectual Island Road, New Yue Road and AO East Road & Torch Road and Wisdom Bridge Road, Hedong Road and the Poly-Xian Bridge Road & New Yue Road and Ao East Road, Hedong Lu and Poly-Xian Bridge Road & Torch Road and Poly-Xian Bridge Road, Hedong Road and Poly-Xian Bridge Road & Hedong Road and Ao Road, Hedong Road and Poly-Xian Bridge Road & Wisdom Bridge and Intellectual Island Road, Hedong Road and the Bridge Road & Torch Road, Torch Road and Hui Zhi Qiao Road & New Yue Road and Ao East Road, Torch Road and Hui Zhi Qiao Road & Torch Road and the Bridge Road, Torch Road and Hui Zhi Qiao Road & Wisdom Bridge and Intellectual Island Road, Torch Road and Wisdom Bridge Road & Hedong Road and the Bridge Road, Torch Road and Hui Zhi Qiao Road & Hedong Road and Ao Road, Hui Zhi Qiao and Intellectual Island Road & New Yue Road and Ao East Road, Wisdom Bridge and Intellectual Island Road & Torch Road and Poly-Xian Bridge Road, Wisdom Bridge and Intellectual Island Road & Torch Road and Wisdom Bridge Road, Wisdom Bridge and Intellectual Island Road & Hedong Road and Ao East Road, Wisdom Bridge and Intellectual Island Road & Hedong Rd and Poly-Xian Bridge Road,
Torch Road and Poly-Xian Bridge Road & New Yue Road and Ao East Road, Torch Road and Poly-Xian Bridge Road & Hedong Lu and Ao Road, Torch Road and Poly-Xian Bridge Road & Hedong Road and Poly-Xian Bridge Road, Torch Road and Poly-Xian Bridge Road & Wisdom Bridge and Intellectual Island Road, Torch Road and the wisdom of Bridge Road & Torch Road Lanru bp9g39,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Lanru b7m827, 1,23,0,1,0,0,2,55,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Lanru Bq3m79, 0,11,0,0,0,0,1,10,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Lanru bu008p, 0,4,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Lanru BW6710, 14,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0 Lanru bs180g, 0,1,0,0,0,0,0,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Lanru b3hu73, 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Code:

Library (FPC)
data<-read.csv (' x.csv ')
df<-data[2:31]
set.seed (252964) 
(Kmeans <-Kmeans ( Na.omit (DF), 
Plotcluster) (Na.omit (DF), Kmeans$cluster)   #作图
kmeans           #表示查看聚类结果
kmeans$ Cluster   #表示查看聚类结果
kmeans$center    #表示查看聚类中心
write.csv (kmeans$cluster, ' 100classes.csv ') # To write the results of a cluster to a file
2. R Language Association Rules

Data set format

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0
0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0
Each column represents a property that indicates the occurrence of this property, and each row represents the number of records

The code is as follows:

Library (arules)
groceries <-read.transactions ("groceries.csv")
Summary (groceries)
</pre><pre code_snippet_id= "1620120" snippet_file_name= "blog_20160322_6_7367204" name= "code" class= "HTML" >/*apriori algorithm */
Frequentsets=eclat (Groceries,parameter=list (support=0.05,maxlen=10)) #求频繁项集
Inspect ( FREQUENTSETS[1:10]) #察看求得的频繁项集
Inspect (sort (frequentsets,by= "support") [1:10]) #根据支持度对求得的频繁项集排序并察看 (equivalent to inspect (Sort (frequentsets) [1:10])
</pre><pre code_snippet_id= "1620120" snippet_file_name= "blog_20160322_8_2841846" name= "code" class= "HTML" >/*eclat algorithm */
<p>rules=apriori (Groceries,parameter=list (support=0.01,confidence=0.01)) #求关联规则 </p><p>summary (rules) #察看求得的关联规则之摘要 </p><p>x=subset (rules,subset=rhs%in% "whole milk" &lift>=1.2) #求所需要的关联规则子集 </p><p>inspect (Sort (x,by= "support") [1:5]) #根据支持度对求得的关联规则子集排序并察看 </p><div>
</div >




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.