首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >垃圾邮件分类数据集的重采样

垃圾邮件分类数据集的重采样
EN

Stack Overflow用户
提问于 2021-02-17 14:58:28
回答 1查看 162关注 0票数 4

以下数据集存在类不平衡问题:

代码语言:javascript
复制
Text                             is_it_capital?     is_it_upper?      contains_num?   Label
an example of text                      0                  0               0            0
ANOTHER example of text                 1                  1               0            1
What's happening?Let's talk at 5        1                  0               1            1

和类似的。我有5000行/文本(0级为4500行,1级为500行)。

我需要重新取样我的类,但我不知道在我的模型中包含这个步骤,所以如果您能看一看,并告诉我是否遗漏了某个步骤,或者您是否发现方法中有任何不一致之处,我将非常感激。

对于火车,我使用以下方法进行测试:

代码语言:javascript
复制
X_train, X_test, y_train, y_test  = train_test_split(X, y, test_size=0.25, random_state=40) 

X在哪里

代码语言:javascript
复制
X=df[['Text','is_it_capital?', 'is_it_upper?', 'contains_num?']]
y=df['Label']

df_train= pd.concat([X_train, y_train], axis=1)
df_test = pd.concat([X_test, y_test], axis=1)


# Separating classes

spam = df_train[df_train.Label == 1]
not_spam = df_train[df_train.Label == 0]

# Oversampling  

oversampl = resample(spam,replace=True,n_samples=len(not_spam), random_state=42)

oversampled = pd.concat([not_spam, oversampl])
df_train = oversampled.copy()

输出(错?):

代码语言:javascript
复制
              precision    recall  f1-score   support

         0.0       0.94      0.98      0.96      3600
         1.0       0.76      0.52      0.62       400

    accuracy                           0.93      4000
   macro avg       0.86      0.77      0.80      4000

weighted avg       0.92      0.93      0.93      4000

您认为我的步骤中是否有错误,因为混淆矩阵支持400,而不是更高的数据集。

很抱歉发表了这么长的文章,但我认为,为了更好地理解我所采取的方法,应该报告所有的步骤。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-17 23:39:03

您的方法没有什么问题,评估报告显示不平衡的数据是正常的。这是因为:

  • 只在训练集上进行重采样,以迫使模型更加重视少数类,
  • 在原始不平衡分布的测试集上进行(正确)评价。重采样测试集也是错误的,因为评估必须执行on the true distribution of the data.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66244497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档