TypeError: unsupported operand type(s) for -: float and NoneType python
TypeError: unsupported operand type(s) for -: float and NoneType python
Judging by what youve provided, and the error this is my conclusion.
The only place you use the -
operand is in the two points
sq_err = (rating- predicted_rating) * (rating - predicted_rating)
because the error states float and NoneType
we can conclude that rating
is type float
and predicted_rating
is NoneType
.
You defined predicted_rating
as:
predicted_rating = simple_nn(person_id, place_id, 5)
So this means that somewhere in your code for the function simple_nn
you are not returning anything. Perhaps if you used conditions you didnt evaluate every end path and the function simply returned.
for example… all of these functions return the None type.
def example1():
pass
def example2():
return
def example3(a = True, b = True):
if not a:
return True
elif not b:
return False
Note in the last example there is a path where neither if case is satisfied,.. thus it could return None
you can also use import division
from _ _ future _ _ import division
it worked for me in same case
TypeError: unsupported operand type(s) for -: float and NoneType python
In my case, I forgot to add
return
to the computed expression in the function definition.
Example:
def drift(y, t): theta*(mu-y) # define OUP drift term
def diffusion(y, t): sigma # define OUP diffusion term
will return the type None when called,
where as,
def drift(y, t): return theta*(mu-y) # define OUP drift term
def diffusion(y, t): return sigma # define OUP diffusion term
will return actual numbers