Tuesday, January 21, 2020

How to use sigmoid activation function in python in basic neural nets.


The sigmoid function is defined as sigmoid(x) = 1/(1+e-x). If the score is defined by 4x1 + 5x2 - 9 = score, then which of the following points has exactly a 50% probability of being blue or red? (Choose all that are correct.)
  1.  (1,1)
  2. (2,4)
  3.  (5,-5)
  4.  (-4,5)

First, we construct a linear function to add the weights and bias term. Then, we use activation function to return the scores to probabilities. Sigmoid function returns values between 0 and 1.

fig1: sigmoid function
from math import e
#Equation: 4x1+5x2-9=score
#weights are 4,5 and bias is -9, find the sigmoid(x) = 1/(1+e-x).

features=[(1,1),(2,4),(5,-5),(-4,5)]
def linear_func(features):
   
for x in features:
        score=
4*x[0]+ 5*x[1]-9
       
y = 1 / (1 + e - score)
       
print("X",x,score,y)
 #call the function
linear_func(features)






No comments:

Post a Comment