Building the models
In this section, we'll build three types of classifiers and assess their performance: a logistic regression classifier, a random forest, and a neural network.
Logistic regression
We discussed the intuition behind and basics of logistic regression models in Chapter 3, Machine Learning Foundations. To build a model on our training set, we use the following code:
from sklearn.linear_model import LogisticRegression clfs = [LogisticRegression()] for clf in clfs: clf.fit(X_train, y_train.ravel()) print(type(clf)) print('Training accuracy: ' + str(clf.score(X_train, y_train))) print('Validation accuracy: ' + str(clf.score(X_test, y_test))) coefs = { 'column': [X_train_cols[i] for i in range(len(X_train_cols))], 'coef': [clf.coef_[0,i] for i in range(len(X_train_cols))] } df_coefs = pd.DataFrame(coefs) print(df_coefs.sort_values('coef', axis=0, ascending=False))
Prior to the for
loop, we import the LogisticRegression
class and set...