我正在使用 LinerSVC 技术对文本进行分类,但我想获得与每个预测相关的预测置信度。
这就是我现在所拥有的:
train_set = self.read_training_files()
count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform([e[0] for e in train_set])
tfidf_transformer = TfidfTransformer()
X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
clf = LinearSVC(C=1).fit(X_train_tfidf, [e[1] for e in train_set])
_ = text_clf.fit([e[0] for e in train_set], [e[1] for e in train_set])
foods = list(self.get_foods())
lenfoods = len(foods)
i = 0
for food in foods:
fd = self.get_modified_food(food)
food_desc = fd['fields']['title'].replace(',', '').lower()
X_new_counts = count_vect.transform([food_desc])
X_new_tfidf = tfidf_transformer.transform(X_new_counts)
predicted = clf.predict(X_new_tfidf)
变量“predicted”将包含不包括置信水平的预测类别编号。我一直在这里阅读源代码,但我没有找到合适的属性来执行此操作。