Python 比较预测后的结果
Python comparing results after predictions
我有这个数据框
test_y
Out[55]:
Results
47302 0
65704 0
63472 1
47247 1
5674 0
5405 1
65501 0
14418 1
18521 1
7631 1
1221 0
23915 1
10548 0
18698 1
46644 0
56585 1
50018 0
54615 1
22613 1
当我 运行 预测时,我得到一个无法与数据帧进行比较的数组
test_y_predictions = model.predict(test_X)
test_y_predictions
Out[57]:
array([[0.49395287],
[0.26348412],
[0.6578461 ],
...,
[0.74228203],
[0.4677609 ],
[0.6267687 ]], dtype=float32)
我想知道我得到了多少正确的结果
我试过了,但出现错误
test_y_predictions = round(test_y_predictions)
TypeError: type numpy.ndarray doesn't define round method
我如何比较我从预测中得到的和我拥有的?
我想你需要这个。
test_y_predictions.round()
>>> a=np.array([[0.49395287],
[0.26348412],
[0.6578461 ],
[0.74228203],
[0.4677609 ],
[0.6267687 ]])
>>> a.round()
array([[0.],
[0.],
[1.],
[1.],
[0.],
[1.]])
当您想将预测结果与标签进行比较时,可以尝试classification_report
metrics.classification_report(test_y, test_y_predictions)
我有这个数据框
test_y
Out[55]:
Results
47302 0
65704 0
63472 1
47247 1
5674 0
5405 1
65501 0
14418 1
18521 1
7631 1
1221 0
23915 1
10548 0
18698 1
46644 0
56585 1
50018 0
54615 1
22613 1
当我 运行 预测时,我得到一个无法与数据帧进行比较的数组
test_y_predictions = model.predict(test_X)
test_y_predictions
Out[57]:
array([[0.49395287],
[0.26348412],
[0.6578461 ],
...,
[0.74228203],
[0.4677609 ],
[0.6267687 ]], dtype=float32)
我想知道我得到了多少正确的结果
我试过了,但出现错误
test_y_predictions = round(test_y_predictions)
TypeError: type numpy.ndarray doesn't define round method
我如何比较我从预测中得到的和我拥有的?
我想你需要这个。
test_y_predictions.round()
>>> a=np.array([[0.49395287],
[0.26348412],
[0.6578461 ],
[0.74228203],
[0.4677609 ],
[0.6267687 ]])
>>> a.round()
array([[0.],
[0.],
[1.],
[1.],
[0.],
[1.]])
当您想将预测结果与标签进行比较时,可以尝试classification_report
metrics.classification_report(test_y, test_y_predictions)