O'Reilly logo

IPython Interactive Computing and Visualization Cookbook - Second Edition by Cyrille Rossant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required