我想将SVM输出的概率类转换为logits。
为了得到每个班级的概率
model = svm.SVC(probability=True)
model.fit(X, Y)
results = model.predict_proba(test_data)[0]
# gets a dictionary of {'class_name': probability}
prob_per_class_dictionary = dict(zip(model.classes_, results))
# gets a list of ['most_probable_class', 'second_most_probable_class', ..., 'least_class']
results_ordered_by_probability = map(lambda x: x[0], sorted(zip(model.classes_, results), key=lambda x: x[1], reverse=True))
我想用这些概率做什么?
将概率转换为logits。
为什么?
我想将SVM的结果与神经网络的结果合并。这样就损失了神经网络输出的logits。因此,我正在寻找一种方法来将SVM输出的概率转换为logits,而不是使用相同权重将SVM logits合并到神经网络logits:
SVM logits + neural network logits = overal_logits
overal_probabilities= softmax(overal_logits)
编辑:
是否等于总和logits然后获得概率直接求和除以2的概率?
proba_nn_class_1=[0.8,0.002,0.1,...,0.00002]
proba_SVM_class_1=[0.6,0.1,0.21,...,0.000003]
overall_proba=[(0.8+0.6)/2,(0.002+0.1)/2,(0.1+0.21)/2,..., (0.00002+0.000003)/2 ]
这个过程在数值上等于SVM和NN的总和对数然后通过softmax获得概率吗?
谢谢
def probs_to_logits(probs, is_binary=False):
r"""
Converts a tensor of probabilities into logits. For the binary case,
this denotes the probability of occurrence of the event indexed by `1`.
For the multi-dimensional case, the values along the last dimension
denote the probabilities of occurrence of each of the events.
"""
ps_clamped = clamp_probs(probs)
if is_binary:
return torch.log(ps_clamped) - torch.log1p(-ps_clamped)
return torch.log(ps_clamped)
def clamp_probs(probs):
eps = _finfo(probs).eps
return probs.clamp(min=eps, max=1 - eps)
来自https://github.com/pytorch/pytorch/blob/master/torch/distributions/utils.py#L107