O
O
Oleg Petrov2018-01-10 17:57:51
Python
Oleg Petrov, 2018-01-10 17:57:51

How to understand in what order the probability of an event is given?

I set the model with an example.

import numpy as np
X = np.array() #Тут массив из 3
y = np.array([2, 1, 1, 1])
from sklearn.svm import SVC
clf = SVC(probability=True) #Обязательно задать для расчета вероятностей
clf.fit(X, y)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
    decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
    max_iter=-1, probability=True, random_state=None, shrinking=True,
    tol=0.001, verbose=False)
print(clf.predict()) # И тут массив из 3
print(clf.predict_proba())

I get the answer:
[1] #What class do we attribute the event to
-
#Probability of classes The help specifies: Returns the probability of the sample for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
As I understand predict_proba, the probabilities are sorted as they appear in the attribute class. How can this be understood?
The sequence will be the same as I indicated y?
y = np.array([2, 1, 1, 1]) , i.e.:
2 - 0.47949123%
1 - 0.52050877%

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Olohtonov, 2018-02-20
@Smeilz1

After calling the clf.fit method, the clf.classes_ attribute will be filled with information about the class labels, in the same order that they appear in the output of the clf.predict_proba method.

In [4]: svc = SVC()

In [5]: import numpy as np
   ...: X = np.array() #Тут массив из 3
   ...: y = np.array([2, 1, 1, 1])

In [6]: svc.fit(X, y)
Out[6]: 
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
  decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
  max_iter=-1, probability=False, random_state=None, shrinking=True,
  tol=0.001, verbose=False)

In [7]: svc.classes_
Out[7]: array([1, 2])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question