kitarp
kitarp

Reputation: 51

NumPy log function throws attribute error for int

I am trying to use a log loss function and keep getting the following error-

   AttributeError: log

the line of code that is throwing this error is -

ll = sum(act*sp.log(pred) + sp.subtract(1,act)*sp.log(sp.subtract(1,pred)))

where pred is-

[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0......1]

and act is-

[[0     1]
 [1     1]
 [2     1]
 [3     1]
 [4     1]
 [5     1]
 [6     1]
 [7     1]
 [8     1]
 [9     1]
 .
 .
 .
 [n     1]] 

Can someone help me with this? Completely driven up the wall.

Upvotes: 1

Views: 851

Answers (1)

kitarp
kitarp

Reputation: 51

@WarrenWeckesser's answer helped me-

"As a work-around, replace pred with pred.astype(int) (or pred.astype(float) if the values are floating point) in your expression for ll"

Upvotes: 2

Related Questions