我给你最重要的代码示例:
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)
昨天我得到了符合我期望的结果:
enter image description here
但今天,我完全不知道为什么,当我想再次运行这段代码时,出现了一个错误:
ValueError: Shape of passed values is (300, 1), indices imply (300, 2)
完全错误屏幕如下:
enter image description here
print(predictions)
[1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 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 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 1 1 0 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 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 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 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
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 1 1 1 1 1 1 1 1 1 1
我不希望在表中有1或0,我希望在屏幕中有1或0的概率百分比
从下面的源代码来看,在预测结束时的同一个表中,有相同的代码,它可以工作:
https://www.kaggle.com/neisha/heart-disease-prediction-using-logistic-regression