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

Arrow left icon
Profile Icon Stephen Klosterman
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (17 Ratings)
Paperback Apr 2019 374 pages 1st Edition
eBook
€8.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Stephen Klosterman
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (17 Ratings)
Paperback Apr 2019 374 pages 1st Edition
eBook
€8.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €22.99
Paperback
€28.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781838551025
Category :
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

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
€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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.