Python RandomForestClassifier可以用于文本标签和数值吗?

Python RandomForestClassifier可以用于文本标签和数值吗?,python,scikit-learn,classification,random-forest,Python,Scikit Learn,Classification,Random Forest,我在网上看到过一些例子,其中RandomForestClassifier用于训练数值和测试数值。同样,我也看到了RandomForestClassifier被用于训练标记数据和测试标记数据。所有这些对我来说都有意义。我现在正在潜入NLP,我正在查看一个包含大量语言(所有客户评论)和客户在网站上发布的评分计数的数据集。我试图在评论栏做一些情绪分析,看看我是否能预测积极的、中立的或消极的情绪。这是正确的方法吗?有没有更好的方法来解决这样的问题 下面是我正在测试的代码 from sklearn.fea

我在网上看到过一些例子,其中RandomForestClassifier用于训练数值和测试数值。同样,我也看到了RandomForestClassifier被用于训练标记数据和测试标记数据。所有这些对我来说都有意义。我现在正在潜入NLP,我正在查看一个包含大量语言(所有客户评论)和客户在网站上发布的评分计数的数据集。我试图在评论栏做一些情绪分析,看看我是否能预测积极的、中立的或消极的情绪。这是正确的方法吗?有没有更好的方法来解决这样的问题

下面是我正在测试的代码

from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer (max_features=2500, min_df=7, max_df=0.8, stop_words=stopwords.words('english'))
processed_features = vectorizer.fit_transform(wd_list).toarray()


# split into traing set and test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(wd_list, labels, test_size=0.2, random_state=0)


# we need to train the model
from sklearn.ensemble import RandomForestClassifier
text_classifier = RandomForestClassifier(n_estimators=200, random_state=0)
text_classifier.fit(X_train, y_train)
在最后一行代码中,我得到以下错误:

ValueError: could not convert string to float: 'i love smell cleanser scent wipes seems different'

你的错误丢失了。我不知道我怎么会错过。好的,我刚刚更新了我的原始帖子,我在那里显示了错误。sklearn分类器不能处理除数值数据以外的任何列。在您发布的代码中,您使用tfidfvectorizer将文本数据正确地转换为数字,但随后尝试将分类器与未转换的数据相匹配。您应该传入
processed\u功能
而不是
wd\u列表