拜金主義—你一定要買最貴的車嗎?_第1頁(yè)
拜金主義—你一定要買最貴的車嗎?_第2頁(yè)
拜金主義—你一定要買最貴的車嗎?_第3頁(yè)
拜金主義—你一定要買最貴的車嗎?_第4頁(yè)
拜金主義—你一定要買最貴的車嗎?_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、拜金主義你一定要買最貴的車嗎?1.數(shù)據(jù)準(zhǔn)備使用MASS包里的Cars93數(shù)據(jù)集,該數(shù)據(jù)集由30個(gè)汽車品牌下的93種汽車構(gòu)成93條觀測(cè)。2.數(shù)據(jù)處理將數(shù)據(jù)集導(dǎo)出成excel格式,運(yùn)用SPSS軟件,將除了價(jià)格之外的變量標(biāo)準(zhǔn)化處理,并取出方差貢獻(xiàn)率的前四個(gè)變量,計(jì)算出標(biāo)準(zhǔn)得分后,隨后運(yùn)用價(jià)格和標(biāo)準(zhǔn)得分進(jìn)行聚類分析。3.軟件實(shí)現(xiàn)對(duì)處理后的數(shù)值進(jìn)行聚類分析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)圖三圖四#聚類優(yōu)度#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)圖九圖十總結(jié):據(jù)以上分析可知,聚類結(jié)果可分為三類,第二類為價(jià)格高,性能高的汽車;第一類為價(jià)格中等,性能高的汽車;第三類為價(jià)格低性能低的汽車。以中心聚類結(jié)果為代表來(lái)看,三個(gè)中心點(diǎn)分別為第2個(gè)樣本 謳歌傳奇,價(jià)格為33.9萬(wàn),性能優(yōu)度為0.576;第56個(gè)樣本馬自達(dá) MPV ,價(jià)格19.1萬(wàn),性能優(yōu)度為0.499;第79個(gè)樣本 土星SL,價(jià)格11.1萬(wàn),性能優(yōu)度為負(fù)0.581;由圖八也可以看出以馬自達(dá)MPV為中心點(diǎn)的第一類汽車大多數(shù)性能與第二類相差不大,甚至有一些的性能超過(guò)了第二類的汽車,但是價(jià)格卻便宜了8萬(wàn)到15萬(wàn)不等,而且第二類汽車分布較散,說(shuō)明此類轎車針對(duì)的目標(biāo)客戶不是普通大眾,而是收入較高的群體,且此類轎車的品牌大多為人們所知曉的高端轎車品

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論