SMOTE,Python中文本分类的过采样

2024-10-01 13:43:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个文本分类,我有非常不平衡的数据,比如

Category | Total Records
Cate1    | 950
Cate2    |  40
Cate3    |  10

现在我想对Cate2和Cate3进行过采样,这样它至少有400-500条记录,我更喜欢使用SMOTE而不是随机抽样,代码

^{pr2}$

它不起作用,因为它不能生成样本合成文本,现在当我把它转换成类似向量的时候

count_vect = CountVectorizer(analyzer='word', token_pattern=r'\w{1,}')
count_vect.fit(fewRecords['category'])

# transform the training and validation data using count vectorizer object
xtrain_count =  count_vect.transform(X_train)
ytrain_train =  count_vect.transform(y_train)

当我想在分类后预测真正的类别时,我不确定这是不是正确的方法,以及如何将向量转换为真实文本


Tags: 数据文本count记录分类transformtrain向量