【发布时间】:2018-02-27 18:05:33
【问题描述】:
我正在使用RandomForestClassifier 运行一些模拟以在 2 个类别之间进行分类,并且我正在使用以下函数进行调试:
def predict_proba(self, X):
print(X.shape)
pred = self.clf.predict_proba(X)
print(pred.shape)
pred = pred.T[1]
print(pred.shape)
return pred
这个例程运行了几次,因为我已经拆分了我的数据,并且我得到了我上面编码的打印.shape 例程的以下输出。
(62, 93)
(62, 2)
(62,)
(62, 93)
(62, 2)
(62,)
(62, 93)
(62, 2)
(62,)
(62, 93)
(62, 1)
IndexError: index 1 is out of bounds for axis 0 with size 1
我的问题是为什么prediction_proba(X) 大多数时候输出(62, 2) 的形状(如预期的那样)而其他时间输出(62, 1) 的形状?
编辑
我想我理解了,似乎分类器只训练了一个类别,因为我没有使用 Stratified KFold 或类似的东西。
【问题讨论】:
-
这与数据的形状有关
标签: python scikit-learn random-forest