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
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
$17.99 $26.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Colombia

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

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 : 9781838551025
Category :
Languages :
Concepts :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Colombia

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 132.97
Data Science Projects with Python
$38.99
Python Machine Learning
$54.99
Data Science  with Python
$38.99
Total $ 132.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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela