【问题标题】:Python comparing results after predictionsPython比较预测后的结果
【发布时间】:2019-08-06 01:57:26
【问题描述】:

我有这个数据框

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 没有定义 round 方法

我如何比较我从预测中得到的和我拥有的?

【问题讨论】:

  • 为了澄清,您正在尝试将值四舍五入为最接近的整数以获得 0/1 标签,对吗?

标签: python dataframe prediction


【解决方案1】:

我认为你需要这个。

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)

【讨论】:

  • @asmgx,请咨询model.classification_report()
猜你喜欢
  • 2021-11-21
  • 1970-01-01
  • 2021-03-01
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 2014-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多