我看到了许多教程和机器学习项目,每个人都选择了y_prob的第二列。我想问选择第二栏的原因是什么?我们可以选择第一列还是在每一列上做一条风险曲线?
y_prob = LR.predict_proba(x_test_bc)
y_prob = pd.DataFrame(y_prob)
y_prob = y_prob.iloc[:,1] # this is the line in question发布于 2022-09-04 12:44:37
正如正式文件中提到的
所有类的返回概率估计都是由类的标签排序的。
Logistic回归的例子大多使用2标签目标变量,标签主要是0和1.如果是这样的话,那么predict_proba()分别返回标签0和label 1的概率数组。标签的顺序被许多人假定为[label_0, label_1] (因为0的自然顺序,然后是1),如果阳性样本需要注意,则分析第二元素,即predict_proba()数组的索引1(这恰好是标签1E 219的概率)。
但是,如果假设的标签顺序没有得到分类器的遵守,这不是安全的方法。
正确方式
LR分类器的classes_属性返回标签的顺序。使用此属性查找标签的正确索引,并在概率数组中使用此索引。
例如:
lr_classifier = LogisticRegression().fit(X_train, y_train)
# Lets say positive sample is labelled as 1
label_1 = 1
# Find the index of positive label i.e. label = 1
idx_label_1 = list(lr_classifier.classes_).index(label_1)
# This above index in predict_proba()
lr_classifier.predict_proba(X_test)[:, idx_label_1]https://stackoverflow.com/questions/73599116
复制相似问题