包不平衡:错误"some of the class attribute(s) not found in dataset"



我想使用过采样代码平衡我的数据与imbalance包。尝试此代码时,它给了我错误:

new_train <- oversample(train, method = "ADASYN")

错误代码

checkDatasetClass(dataset, classAttr) 中的错误:某些类 在数据集中找不到属性

我的数据如下所示:

> head(train)
    case           country   steering     type           group 
1  bad              Europe      LL         AUT             3
2 good              Europe      LL         AUT             2
3 good              Europe      LL         AUT             2
4 good              Europe      LL         SCH             2
5 good              Europe      RL         AUT             2
6 good              Europe      LL         AUT             1
> str(train)
'data.frame':   11479 obs. of  5 variables:
 $ case : Factor w/ 2 levels "bad",..: 1 2 2 2 2 2 2 2 2 2 ...
 $ country: Factor w/ 9 levels "Africa","LatinAmerica",..: 6 6 6 6 6 6 6 6 6 6 ...
 $ steering: Factor w/ 2 levels "LL","RL": 1 1 1 1 2 1 2 1 1 1 ...
 $ type: Factor w/ 2 levels "AUT","SCH": 1 1 1 2 1 1 1 1 1 1 ...
 $ group: Factor w/ 3 levels "1","2","3": 3 2 2 2 2 1 2 3 3 2 ...

我已经删除了 NA

which(is.na(train))
train <- na.omit(train)

指定目标变量。例如:

serhat_simsek <- oversample(train, method = "ADASYN",classAttr = "group")

相关内容

最新更新