gpt4 book ai didi

R、DMwR 封装、SMOTE 功能不起作用

转载 作者:行者123 更新时间:2023-12-01 23:52:06 25 4
gpt4 key购买 nike

我需要将 smote-algorithm 应用到数据集,但无法让它工作。

示例:

x <- c(12,13,14,16,20,25,30,50,75,71)
y <- c(0,0,1,1,1,1,1,1,1,1)

frame <- data.frame(x,y)

library(DMwR)

smotedobs <- SMOTE(y~ ., frame, perc.over=300)

这会产生以下错误:

Error in scale.default(T, T[i, ], ranges) : subscript out of bounds
In addition: Warning messages:
1: In FUN(newX[, i], ...) :
no non-missing arguments to max; returning -Inf
2: In FUN(newX[, i], ...) : no non-missing arguments to min; returning Inf

希望得到任何类型的帮助或提示。

最佳答案

SMOTE 在 Win7 32 位操作系统中存在错误,假设参数'form'中的目标变量是数据集中的最后一列,下面的代码将解释

library(DMwR)
data(iris)
# data <- iris[, c(1, 2, 5)] # SMOTE work
data <- iris[, c(2, 5, 1)] # SMOTE bug
data$Species <- factor(ifelse(data$Species == "setosa", "rare", "common"))
head(data)
table(data$Species)
newData <- SMOTE(Species ~., data, perc.over=600, perc.under=100)
table(newData$Species)

它将显示以下消息

Error in colnames<-(*tmp*, value = c("Sepal.Width", "Species", "Sepal.Length" : 'names' attribute [3] must be the same length as the vector [2]

在Win7 64bit下,不会出现顺序问题!!

关于R、DMwR 封装、SMOTE 功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15881358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com