安装DMwR包时出错

时间:2016-10-04 06:24:04

标签: r

您好我从RGUI-3.3.1安装DMwR软件包时收到此错误消息。

Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : 
cannot open the connection
In addition: Warning messages:
1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file
2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) :
cannot open compressed file 'bitops/DESCRIPTION', probable reason 'No such file or directory'

4 个答案:

答案 0 :(得分:1)

方法1:

报告的错误无法打开连接。在Windows中often a firewall problem and is in the Windows R FAQ。通常的第一次尝试应该是运行internet2.dll。在控制台会话中,您可以使用:

setInternet2(TRUE)

NEWS for R version 3.3.1 Patched (2016-09-13 r71247) (仅限Windows)功能 setInternet2() 没有效果,将被删除到期 课程。方法之间的选择 “内部” 和 “WININET” 现在是由 方法 的论点 URL() 和 下载文件() 并且可以设置它们的默认值 通过 选项。开箱即用的默认设置仍然存在 “WININET” (从那时起一直如此 [R 3.2.2)

您使用的是版本3.3.1,这就是它不再工作的原因。

方法2

该错误表明该程序包需要另一个不可用的程序包bitops。该包不在任何依赖项中,但也许其中一个依赖项依次需要它(在这种情况下,它是:ROCR)。

尝试安装:

install.packages("bitops",repos="https://cran.r-project.org/bin/windows/contrib/3.3/bitops_1.0-6.zip",dependencies=TRUE,type="source") 

包DMwR包含abind,zoo,xts,quantmod和ROCR作为导入包。因此,除了安装5个软件包之外,还必须安装DMwR软件包,手动安装这些软件包。

按以下顺序安装包:

 install.packages('abind')
 install.packages('zoo')
 install.packages('xts')
 install.packages('quantmod')
 install.packages('ROCR')
 install.packages("DMwR")
 library("DMwR")

<强> Approach 3

chooseCRANmirror() 

enter image description here   从弹出列表中选择CRAN镜像。然后安装包:

install.packages("bitops")
install.packages("DMwR")

答案 1 :(得分:1)

“DMwR”包已从 CRAN 存储库中删除。 以前可用的版本可以从 archive 获得。

https://CRAN.R-project.org/package=DMwR

您可以使用 CRAN 包中编写的函数。将以下代码复制到新的 RScript 中,运行它并保存以备将来使用。运行此函数后,您应该可以使用您一直尝试使用它的方式。

# ===================================================
# Creating a SMOTE training sample for classification problems
#
# If called with learner=NULL (the default) is does not
# learn any model, simply returning the SMOTEd data set
#
# NOTE: It does not handle NAs!
#
# Examples:
#  ms <- SMOTE(Species ~ .,iris,'setosa',perc.under=400,perc.over=300,
#                learner='svm',gamma=0.001,cost=100)
#  newds <- SMOTE(Species ~ .,iris,'setosa',perc.under=300,k=3,perc.over=400)
#
# L. Torgo, Feb 2010
# ---------------------------------------------------
SMOTE <- function(form,data,
                  perc.over=200,k=5,
                  perc.under=200,
                  learner=NULL,...
                  )
  
  # INPUTS:
  # form a model formula
  # data the original training set (with the unbalanced distribution)
  # minCl  the minority class label
  # per.over/100 is the number of new cases (smoted cases) generated
  #              for each rare case. If perc.over < 100 a single case
  #              is generated uniquely for a randomly selected perc.over
  #              of the rare cases
  # k is the number of neighbours to consider as the pool from where
  #   the new examples are generated
  # perc.under/100 is the number of "normal" cases that are randomly
  #                selected for each smoted case
  # learner the learning system to use.
  # ...  any learning parameters to pass to learner
{

  # the column where the target variable is
  tgt <- which(names(data) == as.character(form[[2]]))
  minCl <- levels(data[,tgt])[which.min(table(data[,tgt]))]
  
  # get the cases of the minority class
  minExs <- which(data[,tgt] == minCl)

  # generate synthetic cases from these minExs
  if (tgt < ncol(data)) {
      cols <- 1:ncol(data)
      cols[c(tgt,ncol(data))] <- cols[c(ncol(data),tgt)]
      data <-  data[,cols]
  }
  newExs <- smote.exs(data[minExs,],ncol(data),perc.over,k)
  if (tgt < ncol(data)) {
      newExs <- newExs[,cols]
      data <- data[,cols]
  }
  
  # get the undersample of the "majority class" examples
  selMaj <- sample((1:NROW(data))[-minExs],
                   as.integer((perc.under/100)*nrow(newExs)),
                   replace=T)

  # the final data set (the undersample+the rare cases+the smoted exs)
  newdataset <- rbind(data[selMaj,],data[minExs,],newExs)

  # learn a model if required
  if (is.null(learner)) return(newdataset)
  else do.call(learner,list(form,newdataset,...))
}



# ===================================================
# Obtain a set of smoted examples for a set of rare cases.
# L. Torgo, Feb 2010
# ---------------------------------------------------
smote.exs <- function(data,tgt,N,k)
  # INPUTS:
  # data are the rare cases (the minority "class" cases)
  # tgt is the name of the target variable
  # N is the percentage of over-sampling to carry out;
  # and k is the number of nearest neighours to use for the generation
  # OUTPUTS:
  # The result of the function is a (N/100)*T set of generated
  # examples with rare values on the target
{
  nomatr <- c()
  T <- matrix(nrow=dim(data)[1],ncol=dim(data)[2]-1)
  for(col in seq.int(dim(T)[2]))
    if (class(data[,col]) %in% c('factor','character')) {
      T[,col] <- as.integer(data[,col])
      nomatr <- c(nomatr,col)
    } else T[,col] <- data[,col]
  
  if (N < 100) { # only a percentage of the T cases will be SMOTEd
    nT <- NROW(T)
    idx <- sample(1:nT,as.integer((N/100)*nT))
    T <- T[idx,]
    N <- 100
  }

  p <- dim(T)[2]
  nT <- dim(T)[1]

  ranges <- apply(T,2,max)-apply(T,2,min)
  
  nexs <-  as.integer(N/100) # this is the number of artificial exs generated
                                        # for each member of T
  new <- matrix(nrow=nexs*nT,ncol=p)    # the new cases

  for(i in 1:nT) {

    # the k NNs of case T[i,]
    xd <- scale(T,T[i,],ranges)
    for(a in nomatr) xd[,a] <- xd[,a]==0
    dd <- drop(xd^2 %*% rep(1, ncol(xd)))
    kNNs <- order(dd)[2:(k+1)]

    for(n in 1:nexs) {
      # select randomly one of the k NNs
      neig <- sample(1:k,1)

      ex <- vector(length=ncol(T))

      # the attribute values of the generated case
      difs <- T[kNNs[neig],]-T[i,]
      new[(i-1)*nexs+n,] <- T[i,]+runif(1)*difs
      for(a in nomatr)
        new[(i-1)*nexs+n,a] <- c(T[kNNs[neig],a],T[i,a])[1+round(runif(1),0)]

    }
  }
  newCases <- data.frame(new)
  for(a in nomatr)
    newCases[,a] <- factor(newCases[,a],levels=1:nlevels(data[,a]),labels=levels(data[,a]))

  newCases[,tgt] <- factor(rep(data[1,tgt],nrow(newCases)),levels=levels(data[,tgt]))
  colnames(newCases) <- colnames(data)
  newCases
}

答案 2 :(得分:0)

原因是软件包“ DMwR ”是在R版本3.4.3下构建的。
因此,该解决方案实际上在标记的答案中进行了详细说明。

因此,简而言之:
只需运行以下脚本即可解决问题!

install.packages('abind')
install.packages('zoo')
install.packages('xts')
install.packages('quantmod')
install.packages('ROCR')
install.packages("DMwR")

library("DMwR")

答案 3 :(得分:-1)

我解决了它手动安装包的问题。

1° 我下载了“DMwR_0.4.1.tar.gz”。 2° 在 R Studio 中,我通过以下命令安装: install.packages("C:/path_example/DMwR_0.4.1.tar.gz", repos=NULL, type="source")

来自巴西的问候。