我有一个类不平衡问题,使用以下数据集:
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行/文本(其中4500个属于类别0,500个属于类别1)。
我需要重新采样我的分类数据,但是我不知道在我的模型中应该包含这一步骤,所以如果您能看一下并告诉我是否缺少某些步骤或者是否存在任何不一致的地方,我将不胜感激。
对于训练和测试,我使用以下内容:
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而不是更高。
对于这篇较长的文章,我很抱歉,但我认为报告所有步骤可以更好地理解我的方法。
oversampled
变量来训练模型。我认为这一行logR_pipeline.fit(df_train['Text'], df_train['Label'])
应该替换为logR_pipeline.fit(oversampled['Text'], oversampled['Label'])
。 - ygorg