scikit-learn中的predict_proba输出

时间:2021-07-04 23:56:08

Suppose I have a data sample having two classes labeled 0 and 1. When I run output = clf.predict_proba(X_input), each row in output consists of 2 columns corresponding to probability of each class.

假设我有一个数据样本有两个标记为0和1的类。当我运行output = clf.predict_proba(X_input)时,输出中的每一行由2列组成,对应于每个类的概率。

Does the first column represent probability of class 0 or 1? The predict_proba method of GradientBoostingClassier says:

第一列是否代表0级或1级的概率? GradientBoostingClassier的predict_proba方法说:

"The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_."

“输入样本的类概率。类的顺序对应于属性classes_中的顺序。”

Does that mean that whichever, 0 or 1, is the first element of the data sample corresponds to the first column in the output of predict_proba?

这是否意味着数据样本的第一个元素中的哪一个,0或1对应于predict_proba输出中的第一列?

1 个解决方案

#1


3  

Generally a classifier will have an attribute named classes_ this will be populated upon fitting and store the classes. The order of the predict_proba method output will be the same as the order in this attribute.

通常,分类器将具有名为classes_的属性,这将在拟合和存储类时填充。 predict_proba方法输出的顺序将与此属性中的顺序相同。

For example:

nb = MultinomialNM()
nb.fit(some_gender_data)
nb.classes_
array(['F', 'M'], dtype='<U1')

As far as I know all of the classifiers in sklearn have this attribute once fit.

据我所知,sklearn中的所有分类器都具有此属性。

#1


3  

Generally a classifier will have an attribute named classes_ this will be populated upon fitting and store the classes. The order of the predict_proba method output will be the same as the order in this attribute.

通常,分类器将具有名为classes_的属性,这将在拟合和存储类时填充。 predict_proba方法输出的顺序将与此属性中的顺序相同。

For example:

nb = MultinomialNM()
nb.fit(some_gender_data)
nb.classes_
array(['F', 'M'], dtype='<U1')

As far as I know all of the classifiers in sklearn have this attribute once fit.

据我所知,sklearn中的所有分类器都具有此属性。