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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -