Logistic Regression¶
Faisal Qureshi
faisal.qureshi@ontariotechu.ca
http://vclab.science.ontariotechu.ca
In [1]:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
%matplotlib inline
In [2]:
def sigm(x, th):
"""
Sigmoid function
Parameters:
x -- N times M+1 design matrix. N=1 is also valid.
th -- theta M+1 vector of paratmeters.
Returns:
N-dimensional vector -- contains reponse of the sigmoid function specified by parameters th
at locations specified by x
"""
return 1. / (1. + np.exp( - np.dot(x, th) ))
def softmax(x, th):
"""
Softmax function
Parameters:
x -- N times M+1 design matrix. N=1 is also valid.
th -- M+1 times K vector of paratmeters. K are the number of components
Returns
N times K dimensional vector -- contains reponse of the softmax function specified by parameters th
at locations specified by x
"""
N, _ = x.shape()
M, K = th.shape()
for i in range(K):
sigm(x, th[:,i])
In [ ]: