我有一个简单的自然语言处理问题,其中我有一些书面评论,这些评论有简单的二元正面或负面判断。在这种情况下,我能够训练和测试作为独立变量的X的列,这些列包含“词袋”,即稀疏矩阵中的单个词。
from sklearn.feature_extraction.text import CountVectorizercv = CountVectorizer(max_features = 300)#indipendentX = cv.fit_transform(corpus).toarray()#dependenty = dataset.iloc[:, 1].values
…以及因变量y,它由第1列表示,该列的值为0和1(即基本的正面和负面评论)。
如果不是0和1,而是评论可以从1到5星评分,我应该继续使用一个从0到4的值的y变量列吗?换句话说,我想知道如果不是二元的好/坏评论,而是用户在评论后可以给出1到5的评分,模型会有何不同。这种问题在机器学习中被称为什么?
回答:
这只是一个多类分类问题。这里有一个示例代码,你可以从中获得一些想法。你所说的“因变量”被称为类(输入示例所属的类)
label_idx = [unique.index(l) for l in labels] """ labels= class. works for your class is string or so. here labels can be more than two""" label_idx = np.array(label_idx) # just get your class into array vectors = np.array(vecs) # vecs are any vectorised form of your text data clf = LinearSVC() # classifier of your choice clf.fit(vectors, label_idx)