Book Image

Beginning Data Science with Python and Jupyter

By : Alex Galea
Book Image

Beginning Data Science with Python and Jupyter

By: Alex Galea

Overview of this book

Get to grips with the skills you need for entry-level data science in this hands-on Python and Jupyter course. You'll learn about some of the most commonly used libraries that are part of the Anaconda distribution, and then explore machine learning models with real datasets to give you the skills and exposure you need for the real world. We'll finish up by showing you how easy it can be to scrape and gather your own data from the open web, so that you can apply your new skills in an actionable context.
Table of Contents (7 chapters)

Preface

Data science is becoming increasingly popular as industries continue to value its importance. Recent advancements in open source sofware have made this discipline accessible to a wide range of people. In this book, we show how Jupyter Notebooks can be used with Python for various data science applications. Aside from being an ideal "virtual playground" for data exploration, Jupyter Notebooks are equally suitable for creating reproducible data processing pipelines, visualizations, and prediction models. By using Python with Jupyter Notebooks, many challenges presented by data science become simple to conceptualize and implement. This is achieved by leveraging Python libraries, which offer abstractions to the more complicated underlying algorithms. The result is that data science becomes very approachable for beginners. Furthermore, the Python ecosystem is very strong and is growing with each passing year. As such, students who wish to continue learning about the topics covered in this book will fnd excellent resources to do so.

By the end of this book, you will be equipped to analyse data using Python and use Jupyter notebooks effectively.

What This Book Covers

Lesson 1, Jupyter Fundamentals, covers the fundamentals of data analysis in Jupyter. We will start with usage instructions and features of Jupyter such as magic functions and tab completion. We will then transition to data science specific material. We will run an exploratory analysis in a live Jupyter Notebook. We will use visual assists such as scatter plots, histograms, and violin plots to deepen our understanding of the data. We will also perform simple predictive modeling.

Lesson 2, Data Cleaning and Advanced Machine Learning, shows how predictive models can be trained in Jupyter Notebooks. We will talk about how to plan a machine learning strategy. This lesson also explains the machine learning terminology such as supervised learning, unsupervised learning, classification, and regression. We will discuss methods for preprocessing data using scikit-learn and pandas.

Lesson 3, Web Scraping and Interactive Visualizations, explains how to scrap web page tables and then use interactive visualizations to study the data. We will start by looking at how HTTP requests work, focusing on GET requests and their response status codes. Then, we will go into the Jupyter Notebook and make HTTP requests with Python using the Requests library. We will see how Jupyter can be used to render HTML in the notebook, along with actual web pages that can be interacted with. After making requests, we will see how Beautiful Soup can be used to parse text from the HTML, and used this library to scrape tabular data.

What You Need for This Book

This book will require the following minimum hardware requirements:

  • Processor: Intel i5 (or equivalent)

  • Memory: 8GB RAM

  • Hard disk: 10 GB

  • An internet connection

Throughout this book, we will be using Python and Jupyter Notebook to run our code. Additionally, Anaconda environment is needed to run Python and Jupyter notebook. Please ensure you have the following installed on your machine:

  • Python 3.5+

  • Anaconda 4.3+

Python libraries included with Anaconda installation:

  • matplotlib 2.1.0+

  • ipython 6.1.0+

  • requests 2.18.4+

  • beautifulsoup4 4.6.0+

  • numpy 1.13.1+

  • pandas 0.20.3+

  • scikit-learn 0.19.0+

  • seaborn 0.8.0+

  • bokeh 0.12.10+

Python libraries that require manual installation:

  • mlxtend

  • version_information

  • ipython-sql

  • pdir2

  • graphviz

Installation and Setup

Before you start with this book, we'll install Anaconda environment which consists of Python and Jupyter Notebook.

Installing Anaconda

  1. Visit https://www.anaconda.com/download/ in your browser.

  2. Click on Windows, Mac, or Linux, depending on the OS you are working on.

  3. Next, click on the Download option. Make sure you download the latest version (3.6).

  4. Open the installer afer download.

  5. Follow the steps in the installer and that's it! Your Anaconda distribution is ready.ix

Updating Jupyter and Installing Dependencies

  1. Search for Anaconda Prompt and open it.

  2. Type the following commands to update conda and Jupyter:

    #Update conda
    conda update conda
    #Update Jupyter
    conda update jupyter
    #install packages
    conda install numpy
    conda install pandas
    conda install statsmodels
    conda install matplotlib
    conda install seaborn
  3. To open Jupyter Notebook from Anaconda Prompt, use the following command:

    jupyter notebook

Who This Book is for

This book will be most applicable to professionals and students interested in data analysis. The topics covered are relevant to a variety of job descriptions across a large range of industries. For the best experience, you should have knowledge of programming fundamentals and some experience with Python. In particular, having some familiarity with Python libraries such as Pandas, matplotlib, and scikit-learn will be useful.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words and Python language keywords in text are shown as follows: "With the newly created blank Notebook, click in the top cell and type print('hello world')"

Folder names, filenames, file extensions, pathnames, include file names in text are shown as follows: "The header file boost/asio.hpp includes most of the types and functions required for using the Asio library".

A block of code is set as follows:

y = df['MEDV'].copy()
del df['MEDV']
df = pd.concat((y, df), axis=1)

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on New in the upper-right corner and select a kernel from the drop-down menu."

Important new programming terms are shown in bold. Conceptual terms are shown in italics.

Note

Important additional details about a topic appear like this, as in a sidebar.

Note

Important notes, tips, and tricks appear like this.

Reader Feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer Support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the Example Code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.