In [1]:
# Stochastic Gradient Descent is a fundamental to fit a model
# for regression. There are natural connections between the two
# techniques.
In [2]:
# In regression, we minimized a cost function that penalized
# for bad choices on a continuous scale, but for classification,
# we minimize a cost function that penalizes for two (or more)
# cases.
In [3]:
from sklearn import datasets
X, y = datasets.make_classification()
In [4]:
from sklearn import linear_model
In [5]:
sgd_clf = linear_model.SGDClassifier()
In [6]:
sgd_clf.fit(X, y)
Out[6]:
In [8]:
# the Hinge lost function is: max(0, 1 - ty)
# t is the true classification (+1 for one case, -1 for the other)
# y is the vector of coefficients.
In [9]:
from sklearn.metrics import classification_report
In [10]:
predictions = sgd_clf.predict(X)
print classification_report(predictions, y)
In [ ]: