- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含大约 130000 条记录的数据集。记录分为两类目标变量,0和1。1只占总比例的0.09%。
我在 Windows 10 上的 R-3.5.1 中运行我的分析。我使用 SMOTE 算法来处理这个不平衡的数据集。
我使用下面的代码来处理不平衡的数据集
library(DMwR)
data_code$target=as.factor(data_code$target) #Converted to factor as
# SMOTE works with factor data type
smoted_data <- SMOTE(target~., data_code, perc.over=100)
但是在执行代码之后,我看到 0 的计数是 212,1 也是 212,这大大减少了我的样本量。你能建议我如何在不改变我的情况下使用 SMOTE 处理这个不平衡的数据集吗数据大小
最佳答案
您需要尝试使用函数中的两个可用参数:perc.over
和 perc.under
。
根据 doc来自 SMOTE
:
The parameters perc.over and perc.under control the amount of over-sampling of the minority class and under-sampling of the majority classes, respectively.
所以:
perc.over will tipically be a number above 100. With this type of values, for each case in the orginal data set belonging to the minority class, perc.over/100 new examples of that class will be created
我看不到你的数据,但是,如果你的少数类有 100 个案例并且 perc.over=100
,该算法将从该类中生成 100/100 = 1 个新案例。
The parameter perc.under controls the proportion of cases of the majority class that will be randomly selected for the final "balanced" data set. This proportion is calculated with respect to the number of newly generated minority class cases.
因此,例如 perc.under=100
的值将从原始数据的多数类中选择与为少数类生成的相同数量的观察值。
在我们的示例中,只生成了 1 个新案例,因此它只会添加另一个案例,从而产生一个包含 2 个案例的新数据集。
我建议为 perc.over
使用 100 以上的值,为 perc.under
使用更高的值(默认值为 100 和 200)。
请记住,您要在少数类中添加不真实的新观察结果,我会尽量控制这些。
数值示例:
set.seed(123)
data <- data.frame(var1 = sample(50),
var2 = sample(50),
out = as.factor(rbinom(50, 1, prob=0.1)))
table(data$out)
# 0 1
# 43 7 # 50 rows total (original data)
smote_data <- DMwR::SMOTE(out ~ var1, data, perc.over = 200, perc.under = 400)
table(smote_data$out)
# 0 1
# 56 21 # 77 rows total (smote data)
关于r - r 中的 SMOTE 显着减少了样本量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54625093/
在imblearn , smote.fit_sample() 和 smote.fit_resample() 之间有什么区别,我们什么时候应该使用一个而不是另一个? 最佳答案 fit_sample 替换
鉴于我有一个类不平衡问题,我正在应用 SMOTE(DMwR 包)。但是,我有三个类(class)结果而不是两个。 该函数正确地对少数类进行了过采样,但我没有遵循多数/中间类的行为(即,所有类别都包含不
我刚刚使用 DMwR 包中包含的 Smote 在数据集中完成了过采样。 我的数据集由两个类组成。原始分布是 12 vs 62。因此,我编写了此过采样代码: newData <- SMOTE(Score
我刚刚使用 DMwR 包中包含的 Smote 在数据集中完成了过采样。 我的数据集由两个类组成。原始分布是 12 vs 62。因此,我编写了此过采样代码: newData <- SMOTE(Score
我正在使用 SMOTE 函数对稀疏数据集进行过采样,其中包含大约 98% 的 0 和 2% 的 1。我使用了以下代码 from imblearn.over_sampling import SMOTE
我正在尝试在 Python 中使用 imblearn 包中的 SMOTE,但我的数据有很多缺失值,并且出现以下错误: ValueError: Input contains NaN, infinity
我有一个不平衡的数据集,其中包含一个分类因变量和连续且分类的特征变量。我知道 DMwR 包中的 SMOTE 函数只能处理连续的特征。是否有可以像 Chawla 描述的那样处理分类和连续特征的包 in
我想我在下面的代码中遗漏了一些东西。 from sklearn.model_selection import train_test_split from imblearn.over_sampling
我正在尝试使用 SMOTE 来处理二进制分类中的不平衡类数据,我所知道的是:如果我们使用,例如 sm = SMOTE(ratio = 1.0, random_state=10) Before Over
我正在做文本分类,并且我有非常不平衡的数据,例如 Category | Total Records Cate1 | 950 Cate2 | 40 Cate3 | 10 现在我想对
我正在 Weka 中研究一个二元分类问题,数据集高度不平衡(一个类别 90%,另一个类别 10%)。我首先将 SMOTE ( http://www.cs.cmu.edu/afs/cs/project/
我正在尝试使用带有 SMOTE 的 FilteredClassifier 在 WEKA 上运行 5 倍交叉验证。 据我所知,我应该在每个 CV 折叠中应用 SMOTE 以获得我的 CV 错误。 有谁有
我有一个多类数据集,我想对其使用 SMOTE,但我面临着 ValueError: "sampling_strategy" can be a float only when the type oftar
我想用 2 个类进行分类。当我在没有 SMOTE 的情况下进行分类时我得到(10 次交叉验证的平均值): Precision Recall f-1 0,6409509
我有一个包含大约 130000 条记录的数据集。记录分为两类目标变量,0和1。1只占总比例的0.09%。 我在 Windows 10 上的 R-3.5.1 中运行我的分析。我使用 SMOTE 算法来处
我正在尝试按如下方式实现逻辑回归: 但是我无法得到好的预测,因为我的类输出 1 在我的数据中代表性不足。因此,我正在尝试将 SMOTE 算法应用于我的训练集以获得更好的结果。但是我收到消息错误: Er
我正在使用 Keras 和 Bert (HuggingFace) 构建多类文本分类模型,但我的数据集非常不平衡。我使用了 Sklearn 的 SMOTE 来为欠平衡类生成额外的样本(我总共有 45 个
我想同时应用交叉验证和过采样。 我从这段代码中得到以下错误: from sklearn.pipeline import Pipeline, make_pipeline imba_pipeline =
我需要将 smote-algorithm 应用到数据集,但无法让它工作。 示例: x <- c(12,13,14,16,20,25,30,50,75,71) y <- c(0,0,1,1,1,1,1,
我有一个不平衡的数据集,当我尝试使用 SMOTEENN 来平衡他时,多数类的数量减少了一半 我尝试使用提供的所有选项更改“sampling_strategy”参数,但没有帮助 from imblear
我是一名优秀的程序员,十分优秀!