以下数据集存在类不平衡问题:
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行)。
我需要重新取样我的类,但我不知道在我的模型中包含这个步骤,所以如果您能看一看,并告诉我是否遗漏了某个步骤,或者您是否发现方法中有任何不一致之处,我将非常感激。
对于火车,我使用以下方法进行测试:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=40) X在哪里
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()输出(错?):
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,而不是更高的数据集。
很抱歉发表了这么长的文章,但我认为,为了更好地理解我所采取的方法,应该报告所有的步骤。
发布于 2021-02-17 23:39:03
您的方法没有什么问题,评估报告显示不平衡的数据是正常的。这是因为:
。
https://stackoverflow.com/questions/66244497
复制相似问题