Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Data Science Projects with Python
Data Science Projects with Python

Data Science Projects with Python: A case study approach to successful data science projects using Python, pandas, and scikit-learn

eBook
€8.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Data Science Projects with Python

Chapter 2. Introduction toScikit-Learn and Model Evaluation

Note

Learning Objectives

By the end of this chapter, you will be able to:

  • Explain the response variable

  • Describe the implications of imbalanced data in binary classification

  • Split data into training and testing sets

  • Describe model fitting in scikit-learn

  • Derive several metrics for binary classification

  • Create an ROC curve and a precision-recall curve

Note

This chapter will conclude the initial exploratory analysis and present new tools to perform model evaluation.

Introduction


The first chapter got you started with some basic Python, and then progressed to equipping you with tools for data exploration. Specifically, we performed operations such as loading the dataset and verifying data integrity, and we performed our first exploratory analysis on our case study dataset.

In this chapter, we finish our exploration of the data by examining the response variable. After we've concluded that the data is of high quality and makes sense, we will be ready to move forward with the practical concerns of developing machine learning models. We will take our first steps with scikit-learn, one of the most popular machine learning packages available in the Python language. Before learning the details of how mathematical models work in the next chapter, here we'll start to get comfortable with the syntax for using them in scikit-learn.

We will also learn some common techniques for how to answer the question, "Is this model good or not?" There are many possible ways...

Exploring the Response Variable and Concluding the Initial Exploration


We have now looked through all the features to see whether any data is missing, as well as to generally examine them. The features are important because they constitute the inputs to our machine learning algorithm. On the other side of the model lies the output, which is a prediction of the response variable. For our problem, this is a binary flag indicating whether or not an account will default the next month, which would have been October for our historical dataset.

Our overall job on this project is to come up with a predictive model for this target. Since the response variable is a yes/no flag, this problem is called a binary classification task. In our labeled data, the samples (accounts) that defaulted (that is, 'default payment next month' = 1) are said to belong to the positive class, while those that didn't belong to the negative class. The key piece of information to examine regarding the response of a binary...

Introduction to Scikit-Learn


While pandas will save you a lot of time in loading, examining, and cleaning data, the machine learning algorithms that will enable you to do predictive modeling are located in other packages. We consider scikit-learn to be the premier machine learning package for Python, outside of deep learning. While it's impossible for any one package to offer "everything," scikit-learn comes pretty close in terms of accommodating a wide range of approaches for classification and regression, and unsupervised learning. That being said, a few other packages you should also be aware of are as follows:

SciPy:

  • Most of the packages we've used so far are actually part of the SciPy ecosystem.

  • SciPy itself offers lightweight functions for classical approaches such as linear regression and linear programming.

StatsModels:

  • More oriented toward statistics and more comfortable for users familiar with R

  • Can get p-values and confidence intervals on regression coefficients

  • Capability for time series...

Model Performance Metrics for Binary Classification


Before we start building predictive models in earnest, we would like to know how we can determine, once we've created a model, whether it is "good" in some sense of the word. As you may imagine, this question has received a lot of attention from researchers and practitioners. Consequently, there is a wide variety of model performance metrics to choose from.

Note

For an idea of the range of options, have a look at the scikit-learn model evaluation page: https://scikit-learn.org/stable/modules/model_evaluation.html#model-evaluation.

When selecting a model performance metric to assess the predictive quality of a model, it's important to keep two things in mind.

Appropriateness of the metric for the problem

Metrics are typically only defined for a specific class of problems, such as classification or regression. For a binary classification problem, several metrics characterize the correctness of the yes or no question that the model answers. An...

Summary


In this chapter, we finished the initial exploration of the case study data by examining the response variable. Once we became confident in the completeness and correctness of the data set, we became prepared to explore the relation between features and response and build models.

We spent much of this chapter getting used to model fitting in scikit-learn at a technical, coding level, and learning about metrics we could use with the binary classification problem of the case study. When trying different feature sets and different kinds of models, you will need some way to tell if one approach is working better than another. Consequently, you'll need to use model performance metrics.

While accuracy is a familiar and intuitive metric, we learned why it may not give a useful assessment of the performance of a classifier. We learned how to use a majority class null model to tell whether an accuracy rate is truly good, or no better than what would result from prediction of simply the most...

Left arrow icon Right arrow icon

Key benefits

  • Tackle data science problems by identifying the problem to be solved
  • Illustrate patterns in data using appropriate visualizations
  • Implement suitable machine learning algorithms to gain insights from data

Description

Data Science Projects with Python is designed to give you practical guidance on industry-standard data analysis and machine learning tools, by applying them to realistic data problems. You will learn how to use pandas and Matplotlib to critically examine datasets with summary statistics and graphs, and extract the insights you seek to derive. You will build your knowledge as you prepare data using the scikit-learn package and feed it to machine learning algorithms such as regularized logistic regression and random forest. You’ll discover how to tune algorithms to provide the most accurate predictions on new and unseen data. As you progress, you’ll gain insights into the working and output of these algorithms, building your understanding of both the predictive capabilities of the models and why they make these predictions. By then end of this book, you will have the necessary skills to confidently use machine learning algorithms to perform detailed data analysis and extract meaningful insights from unstructured data.

Who is this book for?

If you are a data analyst, data scientist, or business analyst who wants to get started using Python and machine learning techniques to analyze data and predict outcomes, this book is for you. Basic knowledge of Python and data analytics will help you get the most from this book. Familiarity with mathematical concepts such as algebra and basic statistics will also be useful.

What you will learn

  • Install the required packages to set up a data science coding environment
  • Load data into a Jupyter notebook running Python
  • Use Matplotlib to create data visualizations
  • Fit machine learning models using scikit-learn
  • Use lasso and ridge regression to regularize your models
  • Compare performance between models to find the best outcomes
  • Use k-fold cross-validation to select model hyperparameters

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 30, 2019
Length: 374 pages
Edition : 1st
Language : English
ISBN-13 : 9781838552602
Category :
Languages :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 30, 2019
Length: 374 pages
Edition : 1st
Language : English
ISBN-13 : 9781838552602
Category :
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 100.97
Data Science Projects with Python
€28.99
Python Machine Learning
€41.99
Data Science  with Python
€29.99
Total 100.97 Stars icon
Banner background image

Table of Contents

6 Chapters
Data Exploration and Cleaning Chevron down icon Chevron up icon
Introduction toScikit-Learn and Model Evaluation Chevron down icon Chevron up icon
Details of Logistic Regression and Feature Exploration Chevron down icon Chevron up icon
The Bias-Variance Trade-off Chevron down icon Chevron up icon
Decision Trees and Random Forests Chevron down icon Chevron up icon
Imputation of Missing Data, Financial Analysis, and Delivery to Client Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(17 Ratings)
5 star 64.7%
4 star 17.6%
3 star 5.9%
2 star 5.9%
1 star 5.9%
Filter icon Filter
Top Reviews

Filter reviews by




Honest Reviewer Jul 08, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is very well written and author did a good job explaining every line of codes and concepts. Worth every penny! Thank you!
Amazon Verified review Amazon
Monsoon Feb 03, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I liked this book better because it broke through some other books' lectures and abstracts and dove into the kind of data and scenarios that I am more likely to actually encounter in my job, rather than just memorize them. Plus I didn't have to fix or workaround outdated or outversioned python code as I have had to do with some online teaching forums. This book will move your career or business forward.
Amazon Verified review Amazon
Jonas Jun 24, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book teaches you the best practices of data science and machine learning based on real world case studies. I found this highly valuable because you are able to actually work on real data sets. This is also a quick way to learn industry recognized tools and mathematical concepts that are actually being used by data scientist. Another advantage of this book in my opinion is the author's approach for coding. Author writes and explains each code and outcome separately rather than giving you several paragraphs of code and explain them all at once. I strongly recommend this book if you want to learn data science and machine learning on a practical level applying code and assessing the outcome
Amazon Verified review Amazon
Richard Aug 09, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As someone who has managed multiple data science projects in academia and the business world, I found this book to be a much-needed introduction to practical data science in the real-world. Some books thoroughly cover the mathematical complexity of machine learning models while others focus on implementing the models through coding (e.g. Scikit-Learn, Tensor flow, etc.). However, it is rare to find a book that ties the math and coding together to provide a comprehensive take on the data science process, which includes much under-appreciated topics such as data munging, exploratory data analysis, model evaluation, etc. Nevertheless, the author also does not skip out on explanation of the mathematics of the machine learning models and treat them as “black-boxes,” which can be frustrating for many readers who need more depth.This book is ideal for individuals with some familiarity with Python and limited mathematical background. It does not include the latest, cutting-edge deep learning models. However, having a robust process of understanding the data and evaluating models is more critical to the success of a data science project than applying the latest, most sophisticated models coming out of academic research. In this regards, the author does an excellent job of walking through its reader step-by-step in building a robust pipeline process using real-world data science projects as examples.Chapter 6: Imputation of Missing Data, Financial Analysis, and Delivery to Client offers a good overview of the most important step in data science in the business world. You would be hard-pressed to find information in this chapter anywhere else.For experienced data scientists, this book may be too introductory, but it can serve as a textbook or a training manual for your team if you lead a team with entry-level data scientists/analysts who recently graduated from school and still need help applying what they learned from school in the real-world.My only suggestion to the author would have been to include more materials on the next steps and provide a brief survey of the latest models in data science and resources to learn about them.All in all, it is a great book for new entrants or those hoping to join the field. It also seems ideal as a textbook for short 6-8 week data science courses.
Amazon Verified review Amazon
C. Bennett May 25, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As a professor at DePaul University who teaches data science and machine learning, I can say that this is a great book for introducing the fundamental concepts that lie behind using Python for data science projects. Readers will learn useful coding skills in Python, and its various packages for data manipulation and visualization such as Pandas, Numpy, Matplotlib. Furthermore, they will learn how to use Scikit-Learn, one of the major data science toolkits in Python, to construct machine learning models based on the same data. The book is well laid out, with each section building on the last, and reflects what actual data scientist do in the field day-to-day.The book provides a great platform for anyone who is interested in learning practical "how-to" skills, and creates the foundation for those who want to move on to more advanced concepts.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.