我昨天在这里发布了有关制作文本线性回归模型以预测情绪的信息,我想知道的是在将文本小写,删除任何停用词/标点符号和数字之后,我在某些文本上留下了奇怪的线条功能。
['_______','__________','__________ pros','____________','____________ pros','_____________','_____________ pros','aa','aa waist','ab','abdomen','ability','able','able button','able buy',
我在想这可能是因为标点符号和数字用空格代替了吗?我仍然不确定。
另一个问题是如何针对线性回归正确地构造它?我应该用一列特征来代表每个句子并将其输入网络吗?但是如果矩阵稀疏,我将如何处理?
对不起,仅了解有关文本预处理的更多信息
这是我的清洁步骤:假设这样一句话:“这件可爱的铂金连衣裙是女性化的,非常合身,也易于穿着和舒适!强烈推荐!'
-
小写字母
AllSentences ['Sentence'] = AllSentences ['Sentence']。map(lambda x:x.lower())
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))
-
测试/火车拆分,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)
这为我提供了以上功能名称的输出?