版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、拜金主义你一定要买最贵的车吗?1.数据准备使用MASS包里的Cars93数据集,该数据集由30个汽车品牌下的93种汽车构成93条观测。2.数据处理将数据集导出成excel格式,运用SPSS软件,将除了价格之外的变量标准化处理,并取出方差贡献率的前四个变量,计算出标准得分后,随后运用价格和标准得分进行聚类分析。3.软件实现对处理后的数值进行聚类分析read.csv(C:/Users/admin/Desktop/cars.csv)Cars93=read.csv(C:/Users/admin/Desktop/cars.csv)View(Cars93)var=Cars93$Namevar=as.cha
2、racter(var)head(var)for(i in 1:93) s(Cars93)i=varihead(Cars93)plot(Cars93$Price,Cars93$Function)C=which(Cars93$Name=奥迪 90)T=which(Cars93$Name=宝马 535i)H=which(Cars93$Name=雪佛兰 Astro)I=which(Cars93$Name=道奇 Spirit)U=which(Cars93$Name=林肯 Continental)M=which.max(Cars93$Price)points(Cars93c(C,T,H,I
3、,U,M),-1,pch=16)legend(Cars93$PriceC-1.2,Cars93$FunctionC,奥迪 90,bty=n,xjust=0,yjust=0.5,cex=0.8)legend(Cars93$PriceT,Cars93$FunctionT,宝马 535i,bty=n,xjust=0.5,cex=0.8)legend(Cars93$PriceH,Cars93$FunctionH,雪佛兰 Astro,bty=n,xjust=0.5,cex=0.8)legend(Cars93$PriceI-1.2,Cars93$FunctionI,道奇 Spirit,bty=n,xjus
4、t=0,yjust=0.5,cex=0.8)legend(Cars93$PriceU,Cars93$FunctionU,林肯 Continental,bty=n,xjust=0.5,yjust=0,cex=0.8)legend(Cars93$PriceM,Cars93$FunctionM,Cars93$FunctionM,bty=n,xjust=1,cex=0.8)图一图二# k-means #fit_km1=kmeans(Cars93,-1,center=3)print(fit_km1)fit_km1$centersfit_km1$totss;fit_km1$tot.withinss;fit
5、_km1$betweenssfit_km1$betweenss+fit_km1$tot.withinssplot(Cars93,-1,pch=(fit_km1$cluster-1)points(fit_km1$centers,pch=8)legend(fit_km1$centers1,1,fit_km1$centers1,2,Center_1,bty=n,xjust=1,yjust=0,cex=0.8)legend(fit_km1$centers2,1-2,fit_km1$centers2,2,Center_2,bty=n,xjust=0,yjust=0,cex=0.8)legend(fit_
6、km1$centers3,1,fit_km1$centers3,2,Center_3,bty=n,xjust=0.5,cex=0.8)for(i in 1:7) var=c(C,T,H,I,U,M)points(Cars93vari,-1,pch=fit_km1$clustervari+14) legend(Cars93$PriceC-1.2,Cars93$FunctionC,奥迪 90,bty=n,xjust=0,yjust=0.5,cex=0.8)legend(Cars93$PriceT,Cars93$FunctionT,宝马 535i,bty=n,xjust=0.5,cex=0.8)le
7、gend(Cars93$PriceH,Cars93$FunctionH,雪佛兰 Astro,bty=n,xjust=0.5,cex=0.8)legend(Cars93$PriceI-1.1,Cars93$FunctionI,道奇 Spirit,bty=n,xjust=0,yjust=0.5,cex=0.8)legend(Cars93$PriceU,Cars93$FunctionU,林肯 Continental,bty=n,xjust=0.5,yjust=0,cex=0.8)legend(Cars93$PriceM,Cars93$FunctionM,Cars93$NameM,bty=n,xjus
8、t=1,cex=0.8)图三图四#聚类优度#result=rep(0,92)for(k in 1:92) fit_km=kmeans(Cars93,-1,center=k) resultk=fit_km$betweenss/fit_km$totssplot(1:92,result,type=b,main=Choosing the Optimal Number of Cluster, xlab=number of cluster: 1 to 67,ylab=betweenss/totss)points(10,result10,pch=16)legend(10,result10,paste(10,
9、sprintf(%.1f%,result10*100),),sep=),bty=n,xjust=0.3,cex=0.8)fit_km2=kmeans(Cars93,-1,center=10)cluster_90=fit_km2$clusterwhich(Cars93$Name=奥迪 90)which(fit_km2$cluster=cluster_90)图五图六# k-Medoids #library(cluster)fit_pam=pam(Cars93,-1,3)print(fit_pam)head(fit_pam$data)fit_pam$callfit_pam1=pam(Cars93,-
10、1,3,keep.data=FALSE)fit_pam1$datafit_pam2=pam(Cars93,-1,3,cluster.only=TRUE)print(fit_pam2)which(fit_km$cluster!=fit_pam$cluster)plot(Cars93,-1,pch=(fit_pam$cluster-1)c1=which(rownames(Cars93)=rownames(fit_pam$medoids)1)c2=which(rownames(Cars93)=rownames(fit_pam$medoids)2)c3=which(rownames(Cars93)=r
11、ownames(fit_pam$medoids)3)for(i in 1:3) var=c(c1,c2,c3)points(Cars93vari,-1,pch=fit_pam$clustervari+14) legend(fit_pam$medoids1,1,fit_pam$medoids1,2,paste(Center_1:,rownames(fit_pam$medoids)1),bty=n,xjust=0.5,yjust=0,cex=0.8)legend(fit_pam$medoids2,1,fit_pam$medoids2,2,paste(Center_2:,rownames(fit_p
12、am$medoids)2),bty=n,xjust=0,yjust=0.5,cex=0.8)legend(fit_pam$medoids3,1,fit_pam$medoids3,2,paste(Center_3:,rownames(fit_pam$medoids)3),bty=n,xjust=0.5,yjust=0,cex=0.8)points(Cars93c(21,23,33),-1,pch=12)legend(Cars93$Price21,Cars93$Function21,克莱斯勒 Concorde,bty=n,xjust=0.5,yjust=0,cex=0.8)legend(Cars9
13、3$Price23-1.2,Cars93$Function23,克莱斯勒 Imperial,bty=n,xjust=0,yjust=0.5,cex=0.8)legend(Cars93$Price33-1.2,Cars93$Function33,福特 Escort,bty=n,xjust=0,yjust=0.5,cex=0.8)图七图八# HC #fit_hc=hclust(dist(Cars93,-1)print(fit_hc)plot(fit_hc)group_k3=cutree(fit_hc,k=3)group_k3table(group_k3)group_h18=cutree(fit_h
14、c,h=18)group_h18table(group_h18)sapply(unique(group_k3),function(g)Cars93$Namegroup_k3=g)plot(fit_hc)rect.hclust(fit_hc,k=4,border=red)rect.hclust(fit_hc,k=3,border=blue)rect.hclust(fit_hc,k=7,which=c(2,6),border=green)图九图十总结:据以上分析可知,聚类结果可分为三类,第二类为价格高,性能高的汽车;第一类为价格中等,性能高的汽车;第三类为价格低性能低的汽车。以中心聚类结果为代表来看,三个中心点分别为第2个样本 讴歌传奇,价格为33.9万,性能优度为0.576;第56个样本马自达 MPV ,价格19.1万,性能优度为0.499;第79个样本 土星SL,价格11.1万,性能优度为负0.581;由图八也可以看出以马自达MPV为中心点的第一类汽车大多数性能与第二类相差不大,甚至有一些的性能超过了第二类的汽车,但是价格却便宜了8万到15万不等,而且第二类汽车分布较散,说明此类轿车针对的目标客户不是普通大众,而是收入较高的群体,且此类轿车的品牌大多为人们所知晓的高端轿车品
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026国智中心诚聘科研人员14人模拟试卷附参考答案详解(典型题)
- 2026四川成都市简阳市融媒体中心招聘编外人员3人考前冲刺试卷附完整答案详解(名校卷)
- 2026贵州数据宝网络科技有限公司招聘备考题库(达标题)附答案详解
- 2026江苏苏影紫金影业有限公司招聘2人模拟试卷及完整答案详解1套
- 2026广东华南师范大学教育集团招聘非事业编制人员2人备考题库含完整答案详解(典优)
- 复方黄杞汤对脾肾两虚型Ⅰ、Ⅱ型MG患者肠道菌群的调节作用分析研究
- 湖北省安全评价行业收费指导意见
- 1530教育班主任安全教育记录
- 幼儿园校车安全教育制度
- 2026年福建厦门市翔安区招聘编外(劳务派遣)人员25人备考题库附参考答案详解(轻巧夺冠)
- 2026湖北恩施州利川市选调市外教师30人笔试题库及参考答案详解【模拟题】
- 2026年西藏自治区拉萨市辅警协警招聘笔试备考题库及答案详解
- 2025-2026学年北京市房山区初一(下)期末考试语文试卷(含答案)
- 2026年中央安全生产考核巡查组问题通报(2026年更新)
- 合同服务终止协议书范本
- 蔬菜大棚现场管理制度
- 剧毒化学品、放射源存放场所治安防范要求内容
- 钻探安全技术操作规程(2020新版)
- 《事业单位财务规则》专题培训
- 气管插管患者急救与护理
- 海南省海上搜救应急预案
评论
0/150
提交评论