以下操作涉及Python scikit-learn中的Logistic回归
我给您最重要的代码示例:
predictions = logistic_regression.predict(X_test)
prediction=logistic_regression.predict_proba(X_test)[:,:]
prediction=pd.DataFrame(data=predictions,
columns=['Prob of Bad credit (0)','Prob of Good credit (1)'])
prediction.head(10)
并且昨天我得到的这段代码的结果符合我的期望:(不是相同的表标题,而是相同的结果)
但是今天,我绝对不知道为什么,当我想再次运行此代码时,出现错误:
ValueError: Shape of passed values is (300, 1), indices imply (300, 2)
昨天有可能工作,而今天没有工作?我能做什么 ?屏幕下方显示完整错误:
预测样本是这样的:
print(predictions)
[1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 0 11 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 01 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 11 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1]
并且我不想在表中有1或0,而我希望屏幕的示例中的概率为1或0
我认为发生错误是因为预测只有一列,并且您有两个列名称:
prediction=pd.DataFrame(data=predictions,
columns=['Prob of Bad credit (0)','Prob of Good credit (1)'])
也许您可以尝试:
prediction=pd.DataFrame(data=np.transpose(np.hstack((predictions, 1-predictions))),
columns=['Prob of Bad credit (0)','Prob of Good credit (1)'])