请选择 进入手机版 | 继续访问电脑版
楼主: woshishuxuejia
2940 2

[问答] 如何求属性的权重 [推广有奖]

  • 0关注
  • 0粉丝

大专生

88%

还不是VIP/贵宾

-

威望
0
论坛币
493 个
通用积分
0.0014
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1768 点
帖子
68
精华
0
在线时间
64 小时
注册时间
2011-7-7
最后登录
2023-10-23

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
如何用R实现求各个属性的权重?可利用相关性,pca,信息增益等方法。
例如iris数据集中,求下面四个属性的权重,并对权重标准化
萼片宽度
萼片长度
花瓣长度
花瓣宽度

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:相关性 pca 数据集 如何用 R实现 如何

七转乘
DM小菜鸟 发表于 2014-12-10 22:52:27 |显示全部楼层 |坛友微信交流群
给你写了一个,你看看是不是你想要的——

pca

head(iris)

library(psych)

cortest.bartlett(cor(iris[,-5]), n=150)

kmo = function( data ){

   library(MASS)

   X <- cor(as.matrix(data))

   iX <- ginv(X)

   S2 <- diag(diag((iX^-1)))

   AIS <- S2%*%iX%*%S2 #anti-image covariance matrix

   IS <- X+AIS-2*S2 # imagecovariance matrix

   Dai <-sqrt(diag(diag(AIS)))

   IR <-ginv(Dai)%*%IS%*%ginv(Dai) # image correlation matrix

   AIR <-ginv(Dai)%*%AIS%*%ginv(Dai) # anti-image correlation matrix

   a <- apply((AIR -diag(diag(AIR)))^2, 2, sum)

   AA <- sum(a)

   b <- apply((X -diag(nrow(X)))^2, 2, sum)

   BB <- sum(b)

   MSA <- b/(b+a) # indiv.measures of sampling adequacy

   

   AIR <-AIR-diag(nrow(AIR))+diag(MSA) # Examine the anti-image of the

   # correlation matrix. That isthe

   # negative of the partialcorrelations,

   # partialling out all othervariables.

   

   kmo <- BB/(AA+BB) # overallKMO statistic

   

   # Reporting the conclusion

   if (kmo >= 0.00 &&kmo < 0.50){

      test <- 'The KMO testyields a degree of common variance

    unacceptable for FA.'

   } else if (kmo >= 0.50&& kmo < 0.60){

      test <- 'The KMO testyields a degree of common variance miserable.'

   } else if (kmo >= 0.60&& kmo < 0.70){

      test <- 'The KMO testyields a degree of common variance mediocre.'

   } else if (kmo >= 0.70&& kmo < 0.80){

      test <- 'The KMO testyields a degree of common variance middling.'

   } else if (kmo >= 0.80&& kmo < 0.90){

      test <- 'The KMO testyields a degree of common variance meritorious.'

   } else {

      test <- 'The KMO testyields a degree of common variance marvelous.'

   }

   

   ans <- list( overall = kmo,

                report = test,

                individual = MSA,

                AIS = AIS,

                AIR = AIR )

   return(ans)

   

} # end of kmo()

kmo(iris[,-5])

iris.pr<-princomp(iris[,-5],cor=TRUE)

summary(iris.pr,loadings=TRUE)

plot(iris.pr,type="lines")

iris.pr$scores

scale(iris.pr$scores)

啊啊啊,居然写了这么多,必须给我点赞呀~~~


已有 1 人评分经验 学术水平 收起 理由
李会超 + 40 + 2 热心帮助其他会员

总评分: 经验 + 40  学术水平 + 2   查看全部评分

使用道具

谢谢解答啊

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 22:39