Predicting who will survive on the Titanic with logistic regression

In this recipe, we will introduce logistic regression, a basic classifier. We will apply these techniques on a Kaggle dataset where the goal is to predict survival on the Titanic based on real data (see http://www.kaggle.com/c/titanic).

Tip

Kaggle (http://www.kaggle.com/competitions) hosts machine learning competitions where anyone can download a dataset, train a model, and test the predictions on the website.

How to do it...

  1. We import the standard packages:
    >>> import numpy as np
        import pandas as pd
        import sklearn
        import sklearn.linear_model as lm
        import sklearn.model_selection as ms
        import matplotlib.pyplot as plt
        %matplotlib inline
  2. We load the training and test datasets with pandas: ...

Get IPython Interactive Computing and Visualization Cookbook - Second Edition 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.