R语言ablone数据集数据挖掘预测分析报告_第1页
R语言ablone数据集数据挖掘预测分析报告_第2页
R语言ablone数据集数据挖掘预测分析报告_第3页
R语言ablone数据集数据挖掘预测分析报告_第4页
R语言ablone数据集数据挖掘预测分析报告_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、【原创】定制代写开发r/python/spss/matlab/WEKA/sas/sql/C+/stata/eviews数据挖掘和统计分析可视化调研报告/程序/PPT等/爬虫数据采集服务(附代码数据),咨询QQ:3025393450有问题到百度搜索“大数据部落”就可以了欢迎登陆官网:/teradatR语言ablone数据集数据挖掘预测分析报告介绍数据集描述检测异常值并构建清洁数据集清洁数据分析结论介绍鲍鱼是铁和泛酸的极佳来源,是澳大利亚,美国和东亚地区的营养食品资源和农业。100克鲍鱼每日摄取这些营养素的量超过20。鲍鱼的经济价值与年龄呈正相关。因此,准确检测鲍鱼的年龄对于农民和消费者确定其价格

2、非常重要。然而,目前用来决定年龄的技术是相当昂贵和低效的。农民通常通过显微镜切割贝壳并计数环以估计鲍鱼的年龄。这种复杂的方法增加了成本并限制了它的普及。我们的目标是找出预测戒指的最佳指标,然后找出鲍鱼的年龄。数据集描述数据集描述在这个项目中,数据集Abalone是从UCIMachineLearningRepository(1995)获得的。该数据集包含1995年12月由澳大利亚塔斯马尼亚州主要工业和渔业部海洋研究实验室Taroona记录的4177只鲍鱼的物理测量结果。有9个变量,分别是性别,长度,直径和身高,体重,体重,内脏重量,外壳重量和戒指。随着年龄等于戒指数量,变量戒指与鲍鱼年龄呈线性相

3、关加1.5。检测异常值并构建清洁数据集library(ggplot2)library(plyr)library(nnet)library(MASS)library(gridExtra)#Loadingrequiredpackage:gridlibrary(lattice)library(RColorBrewer)library(xtable)Data=read.csv(abalone.csv)#ImportDataprint(str(Data)#StructureoftheData#data.frame:4177obs.of9variables:#Sex:Factorw/3levelsF,I,

4、M:3313221131.#Length:num0.4550.350.530.440.330.4250.530.5450.4750.55.#Diameter:num0.3650.2650.420.3650.2550.30.4150.4250.370.44.#Height:num0.0950.090.1350.1250.080.0950.150.1250.1250.15.#Whole.weight:num0.5140.2260.6770.5160.205.#Shucked.weight:num0.22450.09950.25650.21550.0895.#Viscera.weight:num0.

5、1010.04850.14150.1140.0395.#Shell.weight:num0.150.070.210.1550.0550.120.330.260.1650.32.#Rings:int157910782016919.#NULL有4种不同的体重衡量标准,即Whole.weight,Shucked.weight,Viscera.weight和Shell.weight。Whole.weight应该是最容易测量的。所以我放弃了所有其他措施。Data=subset(Data,select=-c(Shucked.weight,Viscera.weight,Shell.weight)绘制不同戒指

6、的鲍鱼数量。ggplot(Data,aes(x=Rings,fill=Sex)+geom_bar(binwidth=1,color=blue,origin=min(Data$Rings),position=identity)+scale_x_continuous(name=Rings,breaks=seq(0,30,by=2)+theme(axis.text.x=element_text(angle=90)+scale_fill_brewer(Location,type=qual,palette=3)+ylab(Numberofabalone)ggtitle(Numberofabalonewi

7、thdifferentRings)+facet_wrap(Sex,ncol=3)NumberofabalonewithdifferentRings6uoesCTB0alquJnN从上面的图表中,我们可以看到戒指的范围是从1到29,这可能太多以至于无法衡量。实际上,人们可能不需要这么详细的类别。因此,我们将小于6环(14.5岁)的鲍鱼进行分组,相应地表明年轻,成年和老年鲍鱼,将它们标记为1,2,3。Age=c(rep(0,nrow(Data)for(iin1:nrow(Data)if(Datai,$Rings=7&Datai,$Rings13)Agei=3gData=cbind(Data,Age

8、)粗略地绘制图表,并获得关于数据的小尝试ggplot(gData,aes(x=Height,y=factor(Rings),colour=factor(Sex)+geom_jitter(position=position_jitter(width=0.3)+geom_point()+ggtitle(OriginalData:HeightvsRings)+scale_colour_brewer(typeseq,palette=Set1)OriginalData:HeightvsRings2726-25-24factdrtSeiMl-*-Jn一J-22222t2D19lB171615ld.13_从

9、上面的图表我们可以看到女性中有一些轮廓。我想摆脱他们。jData=subset(gData,Height0.4)ggplot(jData,aes(x=Height,y=factor(Rings),colour=factor(Sex)+geom_jitter(position=position_jitter(width=0.1)+geom_point()+ggtitle(ReducedData:HeightvsRings)+scale_colour_brewer(type=seq,palette=Set1)【原创】定制代写开发r/python/spss/matlab/WEKA/sas/sql/C

10、+/stata/eviews数据挖掘和统计分析可视化调研报告/程序/PPT等/爬虫数据采集服务(附代码数据),咨询QQ:3025393450有问题到百度搜索“大数据部落”就可以了欢迎登陆官网:/teradat【原创】定制代写开发r/python/spss/matlab/WEKA/sas/sql/C+/stata/eviews数据挖掘和统计分析可视化调研报告/程序/PPT等/爬虫数据采集服务(附代码数据),咨询QQ:3025393450有问题到百度搜索“大数据部落”就可以了欢迎登陆官网:/teradat【原创】定制代写开发r/python/spss/matlab/WEKA/sas/sql/C+/

11、stata/eviews数据挖掘和统计分析告/程序/PPT等/爬虫数据采集服务(附代码数据),咨询QQ:3025393450有问题到百度搜索“大数据部落”就可以了欢迎登陆官网:/teradat可视化调研报ReducedData:HeightvsRings29-=1000,sousinggamwithformula:ys(x,bs=cs).Usemethod=xtochangethesmoothingmethod.2wnoie.wfiightggplot(Data,aes(x=Length,y=Height)+geom_point(aes(colour=Rings)+scale_colour_g

12、radient(low=purple)+stat_smooth(colour=red)+ggtitle(LengthvsHeight)#geom_smooth:method=autoandsizeoflargestgroupis=1000,sousinggamwithformula:ys(x,bs=cs).Usemethod=xtochangethesmoothingmethod.ID;匚石LengthvsHeight04Lengmggplot(Data,aes(x=Length,y=Diameter)+geom_point(aes(colour=Rings)+scale_colour_gra

13、dient(low=purple)+stat_smooth(colour=red)+ggtitle(LengthvsDiameter)#geom_smooth:method=autoandsizeoflargestgroupis=1000,sousinggamwithformula:ys(x,bs=cs).Usemethod=xtochangethesmoothingmethod.LengthveDiameter从上图可以明显看出,长度,高度和直径是相对线性相关的。事实上,认为鲍鱼越大它们越重,所以我想检查它是否完全相关Whole.weight和Volume之间是很自然的。构建体积和Whole

14、.weight数据集yData=ddply(Data,Sex+Age,summarize,Volume=Length*Diameter*Height,Whole.weight=Whole.weight.Rings=Rings)绘制点和回归线cols-c(Linear=#f04546.Cubic=#3591dl)ggplot(data=yData,aes(x=Whole.weight,y=Volume)+geom_smooth(method=lm,aes(colour=Linear),lwd=1)+geom_smooth(method=lm,formula=ypoly(x,3),aes(colo

15、ur=Cubic),lwd=1)+geom_point(alpha=1/10,colour=purple)+scale_colour_manual(TypeofRegression,values=cols)+ggtitle(VolumevsWhole.weight)+coord_flip()+scale_y_continuous(name=Volume,breaks=seq(0,0.15,by=0.03)【原创】定制代写开发r/python/spss/matlab/WEKA/sas/sql/C+/stata/eviews数据挖掘和告/程序/PPT等/爬虫数据采集服务(附代码数据),咨询QQ:3

16、025393450有问题到百度搜索“大数据部落”就可以了欢迎登陆官网:/teradat统计分析可视化调研报【原创】定制代写开发r/python/spss/matlab/WEKA/sas/sql/C+/stata/eviews数据挖掘和统计分析可视告/程序/PPT等/爬虫数据采集服务(附代码数据),咨询QQ:3025393450有问题到百度搜索“大数据部落”就可以了欢迎登陆官网:/teradat化调研报VolumevsWhole.weightTypeofRegreBsicinCutoK-Linear(1.03O.d6volume0.090.从上图可以看出,立方回归和线性回归在开始时几乎是相同的,

17、但当体积较大时分歧很大,这意味着体积和整体重量对于小鲍鱼高度相关。为什么不使用Whole.weight来预测鲍鱼的戒指?计算不同性别的Whole.weight的均值和方差。with(Data,do.call(rbind,tapply(Whole.weight,Sex,function(x)c(M=mean(x),SD=sd(x)#MSD#F1.04690.4303#I0.43140.2863#M0.99070.4697看起来F和M比我重。这是否意味着我的团队没有大戒指?ggplot(data=Data,aes(x=Rings,group=Sex,colour=Sex)+geom_density

18、()+ggtitle(DensityofRingsofeachSex)ir10囲Rings0.15-DensityofRingsofeachSex10性别我的鲍鱼比F和M组的年轻,但它确实有性别I的旧鲍鱼。colourggplot(data=Data,aes(x=factor(Age),y=Whole.weight)+geom_boxplot(outlier.=purple,outlier.size=3,aes(fill=Sex)+facet_wrap(Sex,ncol=3)+ggtitle(Whole.weightvsAgefordifferentSex)+xlab(Age)Whole.we

19、ightv&AgefordifferentSexSex申L1i与M和F相比,似乎鲍鱼与性别的重量更轻。拟合多国回归模型logit-multinom(AgeWhole.weight,data=yData)#weights:9(4variable)#initialvalue4586.706305#iter10value2099.141042#finalvalue2088.269847#convergedsummary(logit)#Call:#multinom(formula=AgeWhole.weight,data=yData)#Coefficients:#(Intercept)Whole.we

20、ight【原创】定制代写开发r/python/spss/matlab/WEKA/sas/sql/C+/stata/eviews数据挖掘和统计分析可视化调研报告/程序/PPT等/爬虫数据采集服务(附代码数据),咨询QQ:3025393450有问题到百度搜索“大数据部落”就可以了欢迎登陆官网:/teradat【原创】定制代写开发r/python/spss/matlab/WEKA/sas/sql/C+/stata/eviews数据挖掘和统计分析可视化调研报告/程序/PPT等/爬虫数据采集服务(附代码数据),咨询QQ:3025393450有问题到百度搜索“大数据部落”就可以了欢迎登陆官网:/terad

21、at#21.8269.362#3-4.90010.551#Std.Errors:#(Intercept)Whole.weight#20.13530.4488#30.17810.4600#ResidualDeviance:4177#AIC:4185pp=fitted(logit)pred-predict(logit)table(pred,Data$Age)#pred123#12681080#21803127489#3021用上面的信息构建一个新的数据集。newdata=with(yData,data.frame(Weight=Whole.weight,Sex=Sex,Pred_Prob=pp,A

22、ge=Age,Pred_Age=pred)head(newdata)#WeightSexPred_Prob.1Pred_Prob.2Pred_Prob.3AgePred_Age#10.0800F0.73650.25070.0127611#20.1400F0.61360.36640.0200211#30.1885F0.50130.47140.0272811#40.2405F0.38110.58300.0359012#50.2750F0.30780.65050.0417312#60.1700F0.54480.43080.0243911ggplot(newdata,aes(x=Pred_Age,y=

23、Age,colour=factor(Pred_Age=Age)+geom_point(position=jitter)+scale_colour_manual(AgeGroup,values=c(2,3),labels=c(WongClassification,RightClassification)+ggtitle(Classification)Classification2尸red_AgeAgeGroupWangClassirtiGalionRKjhlCnasfirlicaliiori绘制不同年龄组的预测概率cols-c(Young=blue,Adult=#f04546.Old=green

24、)ggplot(newdata,aes(x=Weight)+geom_line(aes(y=Pred_Prob.l,colour=Young)+geom_line(aes(y=Pred_Prob.2,colour=Adult)+geom_line(aes(y=Pred_Prob.3,colour=Old)+ylab(PredictedProbability)+facet_wrap(Sex,ncol=3)+scale_colour_manual(AgeGroup,values=cols)+ggtitle(PredictedProbability)三oPBV一?rL从图表中我们可以看出,Young

25、组的预测应该是好的,但是当体重很重时,很难区分老人和成人。似乎更多的性别我鲍鱼是错误分类为青年和成人组,但更多的性别鲍鱼被误分类为旧摸索。而最大的问题是老组。其中一个原因可能是我们采用多国回归中的变量线性组合。如何使用线性判别分析?只使用Whole.weightLDA1=lda(AgeWhole.weight,yData)predl=predict(LDAl)$classnewdataL1=with(yData,data.frame(Weight=Whole.weight,Sex=Sex,Age=Age,Pred_Age1=pred1)Data_misL1=subset(newdataL1,A

26、ge!=Pred_Age1)使用Whole.weight和Volume。LDA2=lda(Age.,yData)pred2=predict(LDA2)$classnewdataL2=with(yData,data.frame(Weight=Whole.weight,Sex=Sex,Age=Age,Pred_Age2=pred2)Data_misL2=subset(newdataL2,Age!=Pred_Age2)绘制图表:p1=ggplot(Data_misL1,aes(x=Age,fill=Sex)+geom_bar(binwidth=1/2,color=darkgrey)+ylab(Num

27、berofmis-classfieddata)+ggtitle(UsingWhole.weightonly)+theme(axis.text.x=element_text(angle=90)+scale_fill_brewer(Sex,type=qual,palette=3)p2=ggplot(Data_misL2,aes(x=Age,fill=Sex)+geom_bar(binwidth=1/2,color=darkgrey)+ylab(Numberofmis-classfieddata)+ggtitle(UsingWhole.weight&Volume)+theme(axis.text.x

28、=element_text(angle=90)+scale_fill_brewer(Sex,type=qual,palette=3)grid.arrange(p1,p2,main=MisClassifiedDataforDifferentSex_LDA)slnpPBUWBBVG一EQJBquunHUsingWhoe.woightonly通过以上分析,我们发现尽管Whole.weight与Volume有高度相关性,但Volume对分类问题有显着影响。这是否意味着Volume对分类更重要?只使用音量LDA3=lda(AgeVolume,yData)pred3=predict(LDA3)$class

29、newdataL3=with(yData,data.frame(Weight=Whole.weight,Sex=Sex,Age=Age,Pred_Age3=pred3)Data_misL3=subset(newdataL3,Age!=Pred_Age3)绘制图表:ggplot(newdataL2,aes(x=Pred_Age2,y=Age,colour=factor(Pred_Age2=Age)+geom_point(position=jitter)+scale_colour_manual(AgeGroup,values=c(2,3),labels=c(WongClassification,R

30、ightClassification)+ggtitle(ClassificationusingWhole.weight&Volume)AgeGroupWangClaaairticaloonRjt|h1Cnasfli&aliori2Pred_Age2Clas&ificatianusingWhole.weight&Volumeggplot(newdataL3,aes(x=Pred_Age3,y=Age,colour=factor(Pred_Age3=Age)+geom_point(position=jitter)+scale_colour_manual(AgeGroup,values=c(2,3)

31、,labels=c(WongClassification,RightClassification)+ggtitle(ClassificationUsingVolume)ClassificationUsingVolumePred_Agti3AgeGroupWangClassirtiGalionRjgpirtCnasrli&aliiori答案是不。分别使用Volume和Whole.weight不会给出好的分类。几乎没有结论:使用LDA可以更有效地对数据进行分类,然后进行多国回归。可以肯定的是,使用Whole.weight和Volume的观察结果,我们已经可以很好地将鲍鱼分类到不同的年龄组。那么,哪

32、个变量更重要,长度,直径,高度还是Whole.weight?我们现在不想考虑卷,因为这个措施不能直接获得。所以我们会回到上面四个容易测量的变量。记录每个变量的最小值和最大值的新数据框。jData-ddply(Data,Sex+Rings,function(x)jLevels-c(min,max)Length=range(x$Length)Height=range(x$Height)Diameter=range(x$Diameter)Whole.weight=range(x$Whole.weight)return(data.frame(Length,Height,Diameter,Whole.w

33、eight,stat=jLevels)绘制图表p_Height=ggplot(jData,aes(x=Rings,y=Height,group=stat,colour=stat)+geom_line()+geom_point()+facet_wrap(Sex,ncol=3)+ggtitle(Height:MinvsMin)+theme(legend.position=none)p_Length=ggplot(jData,aes(x=Rings,y=Length,group=stat,colour=stat)+geom_line()+geom_point()+facet_wrap(Sex,nco

34、l=3)+ggtitle(Length:MinvsMax)+theme(legend.position=none)p_Diameter=ggplot(jData,aes(x=Rings,y=Diameter,group=stat,colour=stat)+geom_line()+geom_point()+facet_wrap(Sex,ncol=3)+ggtitle(Diameter:MinvsMax)+theme(legend.position=none)p_Whole.weight=ggplot(jData,aes(x=Rings,y=Whole.weight,group=stat,colo

35、ur=stat)+geom_line()+geom_point()+facet_wrap(Sex,ncol=3)+ggtitle(Whole.weight:MinvsMax)tmp-ggplot_gtable(ggplot_build(p_Whole.weight)leg-which(sapply(tmp$grobs,function(x)x$name)=guide-box)legend-tmp$grobsleggrid.arrange(arrangeGrob(p_Whole.weight+theme(legend.position=none),p_Length,p_Height,p_Diam

36、eter)Whole.weight:MinvsMax二IHO10203DO2DanTO203DRingsLength:MinvsMaxRingsHeight:MinvsMinFIM左詈HsyInRlDameter:MinvsMaxFIM-Io42o.o.o.巨EQ!如尝试xyplot中的类似事情px_Height=xyplot(HeightRings|Sex,jData,group=stat,auto.key=list(columns=x=0.35,y=0.85,corner=c(0,1),type=c(p,l),par.settings=list(superpose.line=list(co

37、l=c(red,blue),superpose.symbol=list(col=c(red,blue),grid=h)grid.arrange(arrangeGrob(pHeight+xlab(),pxHeight)从上图可以看出,Whole.weight和Height分享了相似的范围趋势,而Length和Diameter分享了相似的范围趋势。这是否意味着Whole.weight与高度更紧密相关,并且Length与Diameter更相关?回归。jFun-function(x)name=c()Coefs=c()for(iin1:4)temp=c()temp-rbind(temp,as.numer

38、ic(coef(lm(x,i+1Rings,x)Coefs=rbind(Coefs,temp)name=rbind(name,names(xi+1)return(data.frame(Intercept=Coefs,1,Slope=Coefs,2,Variable=name)jCoefs-ddply(Data,Sex,jFun)foo-ddply(jCoefs,Variable,function(x)lerange-c(which.min(x$Intercept),which.max(x$Intercept)cbind(xlerange,c(Variable,Sex,Intercept,Slo

39、pe),stat=c(min_slope,max_slope)foo=xtable(foo)print(foo,type=html,include.rownames=FALSE)变量性别截距坡统计直径世0.130.02min_slope直径F0.390.01max_slope高度世0.040.01min_slope高度F0.120.00max_slope长度世0.190.03min_slope长度F0.510.01max_slopeWhole.weigh0.0min_slopet世0.198Whole.weighF0.640.0max_slopet4从上表可以看出,性别我对所有变量都有min_slope,对于所有变量我们都有max_slope。绘制高度的回归线ggplot(subset(Data,Sex%in%c(F,I),aes(x=Rings,y=Height)+facet_wrap(Sex,ncol=2)+geom_smooth(method=lm,colour=purple)+geom_point(aes(colour=factor(Age)+ggtitle(Max_

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论