python - sklearn decision_function with 2 or more classes -
i have model based on linearsvc, , have variable number of classes. decision function has different output cases classes == 2 , classes > 2:
decision_function(x)
...
returns: array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes) :
confidence scores per (sample, class) combination. in binary case, confidence score self.classes_[1] >0 means class predicted.
i transform output in case of classes == 2 same format in other cases. can go ahead , mirror entries @ 0?
probabilities = model.decision_function(x) if len(probabilities[0]) == 1: probabilities = [(-p, p) p in probabilities] from understanding of svms, should correct. sklearn doesn't else it.
negative probabilities don't make sense, want 1 - p. also, need create ndarray, not list of pairs:
prob2 = np.zeros((len(probabilities), 2)) prob2[:,0] = 1 - probabilities prob2[:,1] = probabilities
Comments
Post a Comment