Fitting the model

We can use either the SGD or second-order methods to fit the logistic regression model to our data. Let us compare the results using SGD; we fit the model using the following command:

>>> log_model_sgd = linear_model.SGDClassifier(alpha=10,loss='log',penalty='l2',n_iter=1000, fit_intercept=False).fit(census_features_train,census_income_train)

Where the parameter log for loss specifies that this is a logistic regression that we are training, and n_iter specifies the number of times we iterate over the training data to perform SGD, alpha represents the weight on the regularization term, and we specify that we do not want to fit the intercept to make comparison to other methods more straightforward (since the method of fitting the ...

Get Mastering Predictive Analytics with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.