Beginning Data Analysis with Python And Jupyter - Alex Galea - E-Book

Beginning Data Analysis with Python And Jupyter E-Book

Alex Galea

0,0
11,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Use powerful industry-standard tools to unlock new, actionable insight from your existing data

Key Features

  • Get up and running with the Jupyter ecosystem and some example datasets
  • Learn about key machine learning concepts like SVM, KNN classifiers and Random Forests
  • Discover how you can use web scraping to gather and parse your own bespoke datasets

Book Description

Getting started with data science doesn’t have to be an uphill battle. This step-by-step guide is ideal for beginners who know a little Python and are looking for a quick, fast-paced introduction.

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 start with understanding the basics of Jupyter and its standard features. You'll be analyzing an example of a data analytics report. After analyzing a data analytics report, next step is to implement multiple classification algorithms. We’ll then show 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. Finish up by learning to visualize these data interactively.

What you will learn

  • Identify potential areas of investigation and perform exploratory data analysis
  • Plan a machine learning classification strategy and train classification models
  • Use validation curves and dimensionality reduction to tune and enhance your models
  • Scrape tabular data from web pages and transform it into Pandas DataFrames
  • Create interactive, web-friendly visualizations to clearly communicate your findings

Who this book is for

This course is ideal for professionals with a variety of job descriptions across large range of industries, given the rising popularity and accessibility of data science. You'll need some prior experience with Python, with any prior work with libraries like Pandas, Matplotlib and Pandas providing you a useful head start.

Alex Galea has been professionally practicing data analytics since graduating with a Master’s degree in Physics from the University of Guelph, Canada. He developed a keen interest in Python while researching quantum gases as part of his graduate studies. Alex is currently doing web data analytics, where Python continues to play a key role in his work. He is a frequent blogger about data-centric projects that involve Python and Jupyter Notebooks.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 173

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Beginning Data Analysis with Python and Jupyter
Why Subscribe?
PacktPub.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
What This Book Covers
What You Need for This Book
Installation and Setup
Installing Anaconda
Updating Jupyter and Installing Dependencies
Who This Book is for
Conventions
Reader Feedback
Customer Support
Downloading the Example Code
Errata
Piracy
Questions
1. Jupyter Fundamentals
Lesson Objectives
Basic Functionality and Features
Subtopic A: What is a Jupyter Notebook and Why is it Useful?
Subtopic B: Navigating the Platform
Introducing Jupyter Notebooks
Subtopic C: Jupyter Features
Explore some of Jupyter's most useful features
Converting a Jupyter Notebook to a Python Script
Subtopic D: Python Libraries
Import the external libraries and set up the plotting environment
Our First Analysis - The Boston Housing Dataset
Subtopic A: Loading the Data into Jupyter Using a Pandas DataFrame
Load the Boston housing dataset
Subtopic B: Data Exploration
Explore the Boston housing dataset
Subtopic C: Introduction to Predictive Analytics with Jupyter Notebooks
Linear models with Seaborn and scikit-learn
Activity B: Building a Third-Order Polynomial Model
Subtopic D: Using Categorical Features for Segmentation Analysis
Create categorical fields from continuous variables and make segmented visualizations
Summary
2. Data Cleaning and Advanced Machine Learning
Preparing to Train a Predictive Model
Subtopic A: Determining a Plan for Predictive Analytics
Subtopic B: Preprocessing Data for Machine Learning
Explore data preprocessing tools and methods
Activity A: Preparing to Train a Predictive Model for the Employee-Retention Problem
Training Classification Models
Subtopic A: Introduction to Classification Algorithms
Training two-feature classification models with scikit-learn
The plot_decision_regions Function
Training k-nearest neighbors for our model
Training a Random Forest
Subtopic B: Assessing Models with k-Fold Cross-Validation and Validation Curves
Using k-fold cross validation and validation curves in Python with scikit-learn
Subtopic C: Dimensionality Reduction Techniques
Training a predictive model for the employee retention problem
Summary
3. Web Scraping and Interactive Visualizations
Lesson Objectives
Scraping Web Page Data
Subtopic A: Introduction to HTTP Requests
Subtopic B: Making HTTP Requests in the Jupyter Notebook
Handling HTTP requests with Python in a Jupyter Notebook
Subtopic C: Parsing HTML in the Jupyter Notebook
Parsing HTML with Python in a Jupyter Notebook
Activity A: Web Scraping with Jupyter Notebooks
Interactive Visualizations
Subtopic A: Building a DataFrame to Store and Organize Data
Building and merging Pandas DataFrames
Subtopic B: Introduction to Bokeh
Introduction to interactive visualizations with Bokeh
Activity B: Exploring Data with Interactive Visualizations
Summary
Index

Beginning Data Analysis with Python and Jupyter

Beginning Data Analysis with Python and Jupyter

Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Acquisition Editor: Aditya Date

Content Development Editor: Murtaza Haamid

Production Coordinator: Vishal Pawar

First published: May 2018

Production reference: 1310518

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78953-202-9

www.packtpub.com

mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why Subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionalsLearn better with Skill Plans built especially for youGet a free eBook or video every monthMapt is fully searchableCopy and paste, print, and bookmark content

PacktPub.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.

Contributors

About the author

Alex Galea has been professionally practicing data analytics since graduating with a Master's degree in Physics from the University of Guelph, Canada. He developed a keen interest in Python while researching quantum gases as part of his graduate studies. Alex is currently doing web data analytics, where Python continues to play a key role in his work. He is a frequent blogger about data-centric projects that involve Python and Jupyter Notebooks.

About the reviewer

Elie Kawerk likes to solve problems using the analytical skills he has accumulated over the years. He uses the data science process, including statistical methods and machine learning, to extract insights from data and get value out of it.

His formal training is in computational physics. He used to simulate atomic and molecular physics phenomena with the help of supercomputers using the good old FORTRAN language; this involved a lot of linear algebra and quantum physics equations.

You can find out more about Elie on his LinkedIn profile (https://www.linkedin.com/in/elie-kawerk-data-scientist/).

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

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 RAMHard disk: 10 GBAn 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:

mlxtendversion_informationipython-sqlpdir2graphviz

Installation and Setup

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

Installing Anaconda

Visit https://www.anaconda.com/download/ in your browser.Click on Windows, Mac, or Linux, depending on the OS you are working on.Next, click on the Download option. Make sure you download the latest version (3.6).Open the installer afer download.Follow the steps in the installer and that's it! Your Anaconda distribution is ready.ix

Updating Jupyter and Installing Dependencies

Search for Anaconda Prompt and open it.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
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.

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 <[email protected]>, 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 <[email protected]> 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 <[email protected]>, and we will do our best to address the problem.

Chapter 1. Jupyter Fundamentals

Jupyter Notebooks are one of the most important tools for data scientists using Python. This is because they're an ideal environment for developing reproducible data analysis pipelines. Data can be loaded, transformed, and modeled all inside a single Notebook, where it's quick and easy to test out code and explore ideas along the way. Furthermore, all of this can be documented "inline" using formatted text, so you can make notes for yourself or even produce a structured report.

Other comparable platforms - for example, RStudio or Spyder - present the user with multiple windows, which promote arduous tasks such as copy and pasting code around and rerunning code that has already been executed. These tools also tend to involve Read Eval Prompt Loops (REPLs) where code is run in a terminal session that has saved memory. This type of development environment is bad for reproducibility and not ideal for development either. Jupyter Notebooks solve all these issues by giving the user a single window where code snippets are executed and outputs are displayed inline. This lets users develop code efficiently and allows them to look back at previous work for reference, or even to make alterations.

We'll start the lesson by explaining exactly what Jupyter Notebooks are and continue to discuss why they are so popular among data scientists. Then, we'll open a Notebook together and go through some exercises to learn how the platform is used. Finally, we'll dive into our first analysis and perform an exploratory analysis in Basic Functionality and Features.

Lesson Objectives

In this lesson, you will:

Learn what a Jupyter Notebook is and why it's useful for data analysisUse Jupyter Notebook featuresStudy Python data science librariesPerform simple exploratory data analysis

Note

All code from this book are available as lesson-specific IPython notebooks in the code bundle. All color plots from this book are also available in the code bundle.

Basic Functionality and Features

In this section, we first demonstrate the usefulness of Jupyter Notebooks with examples and through discussion. Then, in order to cover the fundamentals of Jupyter Notebooks for beginners, we'll see the basic usage of them in terms of launching and interacting with the platform. For those who have used Jupyter Notebooks before, this will be mostly a review; however, you will certainly see new things in this topic as well.

Subtopic A: What is a Jupyter Notebook and Why is it Useful?

Jupyter Notebooks are locally run web applications which contain live code, equations, figures, interactive apps, and Markdown text. The standard language is Python, and that's what we'll be using for this book; however, note that a variety of alternatives are supported. This includes the other dominant data science language, R:

Those familiar with R will know about R Markdown. Markdown documents allow for Markdown-formatted text to be combined with executable code. Markdown is a simple language used for styling text on the web. For example, most GitHub repositories have a README.md Markdown file. This format is useful for basic text formatting. It's comparable to HTML but allows for much less customization. Commonly used symbols in Markdown include hashes (#) to make text into a heading, square and round brackets to insert hyperlinks, and stars to create italicized or bold text:

Having seen the basics of Markdown, let's come back to R Markdown, where Markdown text can be written alongside executable code. Jupyter Notebooks offer the equivalent functionality for Python, although, as we'll see, they function quite differently than R Markdown documents. For example, R Markdown assumes you are writing Markdown unless otherwise specified, whereas Jupyter Notebooks assume you are inputting code. This makes it more appealing to use Jupyter Notebooks for rapid development and testing.

From a data science perspective, there are two primary types for a Jupyter Notebook depending on how they are used: lab-style and deliverable.

Lab-style Notebooks are meant to serve as the programming analog of research journals. These should contain all the work you've done to load, process, analyze, and model the data. The idea here is to document everything you've done for future reference, so it's usually not advisable to delete or alter previous lab-style Notebooks. It's also a good idea to accumulate multiple date-stamped versions of the Notebook as you progress through the analysis, in case you want to look back at previous states.

Deliverable Notebooks are intended to be presentable and should contain only select parts of the lab-style Notebooks. For example, this could be an interesting discovery to share with your colleagues, an in-depth report of your analysis for a manager, or a summary of the key findings for stakeholders.

In either case, an important concept is reproducibility. If you've been diligent in documenting your software versions, anyone receiving the reports will be able to rerun the Notebook and compute the same results as you did. In the scientific community, where reproducibility is becoming increasingly difficult, this is a breath of fresh air.

Subtopic B: Navigating the Platform

Now, we are going to open up a Jupyter Notebook and start to learn the interface. Here, we will assume you have no prior knowledge of the platform and go over the basic usage.

Introducing Jupyter Notebooks

Navigate to the companion material directory in the terminal.

Note

On Unix machines such as Mac or Linux, command-line navigation can be done using ls to display directory contents and cd to change directories.

On Windows machines, use dir to display directory contents and use cd to change directories instead. If, for example, you want to change the drive from C: to D:, you should execute d: to change drives.

Start a new local Notebook server here by typing the following into the terminal:
jupyter notebook

A new window or tab of your default browser will open the Notebook Dashboard to the working directory. Here, you will see a list of folders and files contained therein.

Click on a folder to navigate to that particular path and open a file by clicking on it. Although its main use is editing IPYNB Notebook files, Jupyter functions as a standard text editor as well.Reopen the terminal window used to launch the app. We can see the NotebookApp being run on a local server. In particular, you should see a line like this: