asmgx
asmgx

Reputation: 8024

Python comparing results after predictions

I have this dataframe

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

when I run the prediction I get an array which I can not compare to the dataframe

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)

I want to find how many correct results I got

I tried this but got an error

test_y_predictions = round(test_y_predictions)

TypeError: type numpy.ndarray doesn't define round method

How can I compare what I got from prediction and what I have?

Upvotes: 0

Views: 740

Answers (1)

Lê Tư Thành
Lê Tư Thành

Reputation: 1083

I think you need this one.

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.]])

When you want to compare the prediction result with the labels, you can try classification_report

metrics.classification_report(test_y, test_y_predictions)

Upvotes: 2

Related Questions