In [1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
In [2]:
from IPython.html.widgets import interact
from matplotlib import pylab as plt
import matplotlib as mpl
import numpy as np
mpl.rcParams['figure.figsize'] = (16, 6)
In [3]:
def sigmoid(*theta):
# Convert to column vector
theta = np.array(theta).reshape(len(theta), 1)
def _sigmoid(x):
# Add 'constant' intercept vector
X = np.hstack([np.ones(x.shape[0]).reshape(x.shape[0], 1), x])
return 1. /( 1. + np.exp(-1 * (X.dot(theta))) )
return _sigmoid
In [4]:
def interactive_sigmoid(intercept=1, slope=1):
h = sigmoid(intercept, slope)
x = np.linspace(-15, 15, 100).reshape(100, 1)
y = h(x)
plt.plot(x, y)
In [5]:
interact(interactive_sigmoid, intercept=(-15., 15., 0.1), slope=(-3., 3., 0.1))
In [ ]: