Sigmoid Function in Python

Its quite important to understand some of basic mathematical fundamentals before jumping directly into machine learning ocean.

Sigmoid Function is one of mathematical function used in various machine learning algorithm ex. Logistic Regression , Neural Network etc.

Usually Sigmoid functions are S shape curved used for predicting binary outputs.

Few examples of sigmoid function are mentioned below.

1. Logistic Function







2. Hyperbolic Tangent







3. Error Function



I am going to attempt to plot first two Sigmoid function using Python and Matlab Plot.

Logistic Function :


import matplotlib.pylab as plt
import numpy as np

def sigmoidFunction(x):
    sigFunction = 1 / (1 + np.exp(-x))
    return sigFunction


rangeX = np.arange(-10, 10, 0.2)
plt.plot(rangeX , sigmoidFunction(rangeX))


#Define Lables 
plt.grid()
plt.title('Sigmoid Function')
plt.xlabel('X Aixis')
plt.ylabel('Y Function (Hypothesis)')
plt.show()



Hyperbolic Tangent :

import matplotlib.pylab as plt
import numpy as np

def sigmoidFunctionHyperbolicTangent(x):
    sigFunction = (np.exp(x) - np.exp(-x)) / ( np.exp(x) + np.exp(-x))
    return sigFunction


rangeX = np.arange(-10, 10, 0.2)
plt.plot(rangeX , sigmoidFunctionHyperbolicTangent(rangeX) , 'r')


#Define Lables 
plt.grid()
plt.title('Sigmoid Function')
plt.xlabel('X Aixis')
plt.ylabel('Y Function (Hypothesis)')
plt.show()


Happy Learning .. !!!

Comments

Popular posts from this blog

JDBC Hive Connection fails : Unable to read HiveServer2 uri from ZooKeeper

Access Kubernetes ConfigMap in Spring Boot Application

Developing Custom Processor in Apache Nifi