Logistic Regression

Overview


Logistic Regression is a regression technique which fits a logistic function to a set of data. It is used primarily to model dichotomous data, that is, data where the response variable can take one of only two values.

The Logistic Function


Logistic Regression in Python


Logistic regressions are available in Python using the numpy package. The following code shows a simple example, using data structured similar to an array of data in Javascript.


The logistic regression method in Python uses numpy arrays as the data inputs. The following code demonstrates creating numpy arrays from Python arrays.


import numpy as np
x = []
y = []
for record in data:
	nrecord = []
	nrecord.append(record['Factor'])
	x.append(nrecord)

	nrecord = []
	nrecord.append(record['Default'])
	y.append(nrecord)
	pass

X = np.array(x)
Y = np.array(y)
					


The following code demonstrates running the regression.


from sklearn import linear_model

clf = linear_model.LogisticRegression()
clf.fit(X,Y)

print(clf.coef_)
print(clf.intercept_)