情绪分析联合名单

时间:2016-10-05 04:41:05

标签: python arrays scikit-learn

我正在使用scikit-learn python进行情感分析,现在我使用nltk进行词形还原以提高处理速度,例如:

我在nltk处理后得到以下数组:

array([ ['Really', 'a', 'terrible', 'course', u'lecture', u'be', 'so', 'boring', 'i', u'contemplate', 'suicide', 'on', 'numerous', u'occasion', 'and', 'the', 'tutes', u'go', 'for', 'two', u'hour', 'and', u'be', 'completely'], ['Management', 'accounting', u'require', 'sufficient', 'practice', 'to', 'get', 'a', 'hang', 'of', 'Made', 'easier', 'with', 'a', 'great', 'lecturer']], dtype=object)

但是scklearn要求数组是

array([ 'Really a terrible course  lectures were so boring i contemplated suicide on numerous occasions and the tutes went for two hours and were completely ', 'Management accounting requires sufficient practice to get a hang of  Made easier with a great lecturer '],dtype=object)

那么将此数组转换为正确形式的最佳方法是什么?我尝试使用joint list,但结果很奇怪

1 个答案:

答案 0 :(得分:0)

你会这样做:

second_array = [' '.join(each) for each in first_array]

或者,您可以告诉sklearn.CountVectorizer只使用您的令牌:

vect = CountVectorizer(preprocessor=lambda x: x, tokenizer=lambda x: x)
X = vect.fit_transform(first_array)