我有22465个测试文档,我将它们分为88个不同的主题。我正在使用predict_proba来获取前5个预测主题。那么如何打印这5个主题的精确度呢?
为了准确起见,这就是我正在做的:
model1 = LogisticRegression()
model1 = model1.fit(matrix, labels)
y_train_pred = model1.predict_log_proba(matrix_test)
order=np.argsort(y_train_pred, axis=1)
print(order[:,-5:]) #gives top 5 probabilities
n=model1.classes_[order[:, -5:]]为了准确起见
z=0
for x, y in zip(label_tmp_test, n):
if x in y:
z=z+1
print(z)
print(z/22465) #This gives me the accuracy by considering top 5 topics如何以相同的方式找到前5个主题的精确度?Scikit指标拒绝使用
q=model1.predict(mat_tmp_test)
print(metrics.precision_score(n, q))发布于 2016-03-20 20:31:28
在您的方法中,精度几乎是相同的-您只需关注特定的标签(因为精度是每个标签的度量),假设您计算标签L的精度:
TP = 0.
FP = 0.
for x, y in zip(label_tmp_test, n):
if x == L: # this is the label we are interested in
if L in y: # correct prediction is among selected ones
TP = TP + 1 # we get one more true positive instance
else: # this is some other label
if L in y: # if we predicted that this is a particular label
FP = FP + 1 # we have created another false positive
print(TP / (TP + FP))现在,如果你需要“一般”精度-你通常会平均每个标签的精度。出于显而易见的原因,您需要大量标签才能使这类措施有意义。
https://stackoverflow.com/questions/36110603
复制相似问题