使用tfidvectoriser时出现怪异行,可能是由替换为''?

问题描述 投票:0回答:1

我昨天在这里发布了有关制作文本线性回归模型以预测情绪的信息,我想知道的是在将文本小写,删除任何停用词/标点和数字之后,我在某些文本特征上留下了怪异的线条。

     ['_______',


'__________',
 '__________ pros',
 '____________',
 '____________ pros',
 '_____________',
 '_____________ pros',
 'aa',
 'aa waist',
 'ab',
 'abdomen',
 'ability',
 'able',
 'able button',
 'able buy',

我在想这是因为标点符号和数字我用空格代替了吗?我还是不太确定。

另一个问题是如何针对线性回归正确地构造它?我应该用一列特征来代表每个句子并将其输入网络吗?但是如果矩阵稀疏,我将如何处理?

很抱歉,仅了解有关文本预处理的更多信息

这是我的清洁步骤:假设这样一句话:这件可爱的铂金连衣裙既女性化,又合身,易穿,舒适!强烈推荐!'

  1. 小写

    AllSentences ['Sentence'] = AllSentences ['Sentence']。map(lambda x:x.lower())>] >>

    2。删除停用词

  2.   stop = stopwords.words('english')
        AllSentences['Sentences_without_stopwords'] = AllSentences['Sentence'].apply(lambda x: ' '.join([word for word in x.split() if word not in (stop)]))
    

3。删除号码

AllSentences['Sentences_without_stopwords_punc'] = AllSentences['Sentences_without_stopwords'].apply(lambda x: re.sub(r'[^\w\s]', '',x))
AllSentences['Sentences_without_stopwords_punc'] = AllSentences['Sentences_without_stopwords_punc'].apply(lambda x: re.sub(r'\d+', '',x))
  1. 测试/火车拆分,tfidvectorise

    X_train, X_test, y_train, y_test = train_test_split(X, Y, 
     test_size=0.30, random_state=42)
    
       vect_word = TfidfVectorizer(max_features=20000, lowercase=True, 
       analyzer='word',stop_words= 'english',ngram_range=(1,3),dtype=np.float32)
    
    tr_vect = vect_word.fit_transform(X_train)
    ts_vect = vect_word.transform(X_test)
    

    这为我提供了以上功能名称的输出?

我昨天在这里发布了有关制作文本线性回归模型以预测情感的方法,我想知道的是在将文本小写,删除任何停用词/标点和数字之后,我是...

python linear-regression data-science
1个回答
0
投票
[我认为使用TfidfVectorizer是开始进行情感分析的理想起点。为了避免特征向量稀疏,您可能希望从较少的特征开始,然后根据模型的性能逐步提高。您可以在训练时将其设为超参数,并使用GridSearchPipeline为其找到最佳值。请参见该示例here。根据具体情况,可能会使用word embeddings更可靠的实现。但是,这很可能会给您的模型带来更多的复杂性。

字符串中的怪异行是必须在源文本中出现的下划线字符。在清除过程中未清除它们,因为您使用了re.sub(r'[^\w\s]', '',x)从字符串中删除了非单词字符和非空格。下划线是单词字符集('\w')的一部分,因此未清除下划线。

© www.soinside.com 2019 - 2024. All rights reserved.