How would I implement this in python?
1 / (1 + e^-(-6.78+(0.04*age)))
I'm not sure about the e
part of the formula. Here's image:
How would I implement this in python?
1 / (1 + e^-(-6.78+(0.04*age)))
I'm not sure about the e
part of the formula. Here's image:
The function you're using is known as the sigmoid function. You can build a function that will calculate every sigmoid of x.
In order to use e^(x) you can use the numpy function exp as shown in the example.
import numpy as np
def sigmoid(x):
return 1/(1+np.exp(-x))
if __name__ == '__main__':
age = 15
result = sigmoid(-6.78+(0.04*age))
print(result)
Use math.e
:
import math
1 / (1+ math.e-(-6.78+(0.04*age)))