【问题标题】:SCUT for balancing multiclass datasetSCUT 用于平衡多类数据集
【发布时间】:2023-04-03 20:35:02
【问题描述】:

我要实现 SCUT 算法来平衡我的多类数据集,我得到了这个错误

1 apply(T, 2, max) 中的错误:dim(X) 必须具有正长度

library(EMCluster, quietly = TRUE)
    library("lattice", lib.loc="C:/Program Files/R/R-3.4.2/library")
    library(grid)
    library(DMwR)
    CoronaryEvent <-data$CoronaryEvent
    class <- unique(CoronaryEvent)
    for(i in 2:length(unique(CoronaryEvent))-1){
      for(j in (i+1):length(unique(CoronaryEvent))){
        print(paste(i,j,sep=","))
        print(paste(class[i],class[j],sep=","))
        coronaryEvent equal to class i and class j
        class_i <- factor(as.factor(class[i]))
        class_j <- factor(as.factor(class[j]))

        a<-data[match(as.character(data$CoronaryEvent), class_i, nomatch = FALSE), ]
        a$CoronaryEvent <-as.factor(class_i)
        b<-data[match(as.character(data$CoronaryEvent), class_j, nomatch = FALSE), ]
        b$CoronaryEvent <-as.factor(class_j)
       D <- rbind(a,b)
       str(D)
      print(nrow(D))
      #oversampling binary dataset (minority class till reach 36 observations)
        m<-36
        if((nrow(a)<m)|(nrow(b)<m)){
          n<-nrow(a)
          perc = as.integer((m/n)*100)
          print(perc)
          newData <- SMOTE(CoronaryEvent ~ .,  D, perc.over = perc,perc.under = 50)
          print("oversampling")
          str(newData)
        }

        #undersampling majority class till 32 observations using EM algorithm
        else if((nrow(a)>m)|(nrow(b)>m)){
        print("undersampling")

        }


      }
    }

下图包含SCUT算法

更多详情见此链接:
https://www.researchgate.net/publication/301453161_SCUT_Multi-Class_Imbalanced_Data_Classification_using_SMOTE_and_Cluster-based_Undersampling

【问题讨论】:

    标签: r


    【解决方案1】:

    这个问题很老,但我刚刚在 CRAN 上发布了一个名为 scutr 的包,它实现了 SCUT。它使用他们在论文中指出的过采样/欠采样方法。如果您想尝试一下,还提供了一些其他重采样方法。该 API 对自定义函数或来自其他包的函数很友好。希望这对发现此问题的其他人有用。

    Link to CRAN page

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 2021-08-24
      • 2019-06-17
      • 2017-11-01
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      相关资源
      最近更新 更多