Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Machine Learning Fundamentals
Machine Learning Fundamentals

Machine Learning Fundamentals: Use Python and scikit-learn to get up and running with the hottest developments in machine learning

eBook
$26.99 $29.99
Paperback
$38.99
Hardcover
$38.99
Subscription
Free Trial
Renews at $19.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
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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

Machine Learning Fundamentals

Unsupervised Learning: Real-Life Applications

Learning Objectives

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

  • Describe how clustering works
  • Import and preprocess a dataset using Pandas and Matplotlib
  • Explain the difference between the three clustering algorithms
  • Solve an unsupervised learning data problem using different algorithms
  • Compare the results of different algorithms to select the one with the best performance

This chapter describes a practical implementation of an unsupervised algorithm to a real-world dataset

Introduction


In the previous chapter, we saw how to represent data in a tabular format, create features and target matrices, preprocess data, and choose the algorithm that best suits the problem at hand. We also saw how the scikit-learn API works and why it is easy to use.

The main objective of this chapter is to solve a real-world case study, where the students will implement three different unsupervised learning solutions. These different applications serve to demonstrate the uniformity of the scikit-learn API, as well as to explain the steps taken to solve such a problem. At the end of this chapter, the students will be able to understand the use of unsupervised learning to comprehend data in order to make informed decisions.

Clustering


Clustering is a type of unsupervised machine-learning technique, where the objective is to arrive at conclusions based on the patterns found within unlabeled input data. This technique is mainly used to find meaning in the structure of large data in order to draw decisions.

For instance, from a large list of restaurants in a city, it would be useful to segregate the market into subgroups based on the type of food, quantity of clients, and style of experience to offer each cluster a service that's been configured to its specific needs.

Moreover, clustering algorithms divide the data points into n number of clusters so that the data points in the same cluster have similar features, whereas they greatly differ from the data points in other clusters.

Clustering Types

Clustering algorithms can classify data points using a methodology that is either hard or soft. The former designates data points completely to a cluster, whereas the latter method calculates for each data point the probability...

Exploring a Dataset: Wholesale Customers Dataset


As part of the process of learning the behavior and applications of clustering algorithms, the following sections of this chapter will focus on solving a real-life data problem using the Wholesale Customers dataset, which is available at the UC Irvine Machine Learning Repository.

Note

The Wholesale Customers dataset is available for download, and will be used in this topic's activity. The process of downloading it will be explained during the activity. However, students should access the following link to understand the steps that are given: http://archive.ics.uci.edu/ml/datasets/Wholesale+customers.

Datasets in repositories may contain raw, partially preprocessed, or preprocessed data. To use any of these datasets, ensure that you read the specifications of the data available to understand the process that needs to be followed to model the data effectively.

Understanding the Dataset

The suggested steps to be followed to set the book of action...

Data Visualization


Once data has been revised generically to ensure that it can be used for the desired purpose, it is time to load the dataset and use data visualization to further understand it. Data visualization is not a requirement for developing a machine-learning project, especially when dealing with datasets with hundreds or thousands of features. However, it has become an integral part of machine learning, mainly for visualizing the following:

  • Specific features that are causing trouble (for example, those that contain many missing or outlier values) and to understand how to deal with them

  • The results from the model, such as the clusters created or the number of predicted instances for each labeled category

  • The performance of the model in order to see the behavior along different iterations

Its popularity in the tasks detailed previously is explained by the fact that the human brain processes information easily when it is presented as charts or graphs, which allows us to have a general...

k-means Algorithm


The k-means algorithm is used for data without a labeled class. It involves dividing the data into K number of subgroups. The classification of data points into each group is done based on similarity, as explained before, which for this algorithm is measured by the distance from the center (centroid) of the cluster. The final output of the algorithm are the data points related to a cluster and the centroid of each cluster, which can be used to label new data in the same clusters.

The centroid of each cluster represents a collection of features that can be used to define the nature of the data points that belong there.

Understanding the Algorithm

The k-means algorithm works through an iterative process that involves the following steps:

Figure 2.6: A formula minimizing the Euclidean distance

Steps 2 and 3 are repeated in an iterative process, until a criterion is met. The criterion can be as follows:

  • The number of iterations defined.

  • The data points do not change from cluster...

Mean-Shift Algorithm


The mean-shift algorithm works by assigning each data point a cluster based on the density of data points in the data space, also known as the mode in a distribution function. Contrary to the k-means algorithm, the mean-shift algorithm does not require you to specify the number of clusters as a parameter.

The algorithm works by modeling the data points as a distribution function, where high-density areas (high concentration of data points) represent high peaks. Then, the general idea is to shift each data point until it reaches its nearest peak, which becomes a cluster.

Understanding the Algorithm

The first step of the mean-shift algorithm is the representation of the data points as a density distribution. To do so, the algorithm builds upon the idea of Kernel Density Estimation (KDE), which is a method used to estimate the distribution of a set of data:

Figure 2.10: An image depicting the idea behind Kernel Density Estimation

In the preceding diagram, the red dots represent...

DBSCAN Algorithm


The density-based spatial clustering of applications with noise (DBSCAN) algorithm groups together points that are close to each other (with many neighbors) and marks those points that are further away with no close neighbors as outliers.

According to this, and as its name states, the algorithm classifies data points based on the density of all data points in the data space.

Understanding the Algorithm

The DBSCAN algorithm requires two main parameters: epsilon and the minimum number of observations.

Epsilon, also known as eps, is the maximum distance that defines the radius within which the algorithm searches for neighbors. The minimum number of observations, on the other hand, refers to the number of data points required to form a high density area (min_samples). However, the latter is optional in scikit-learn as the default value is set to 5:

Figure 2.13: An illustration of how the DBSCAN algorithm classifies data into clusters

In the preceding diagram, the blue dots are assigned...

Evaluating the Performance of Clusters


After applying a clustering algorithm, it is necessary to evaluate how well the algorithm has performed. This is especially important when it is difficult to visually evaluate the clusters, for example, when there are several features.

Usually, with supervised algorithms, it is easy to evaluate the performance by simply comparing the prediction of each instance with its true value (class). On the other hand, when dealing with unsupervised models, it is necessary to pursue other strategies. In the specific case of clustering algorithms, it is possible to evaluate performance by measuring the similarity of the data points that belong to the same cluster.

Available Metrics in Scikit-Learn

Scikit-learn allows its users to use two different scores for evaluating the performance of unsupervised clustering algorithms. The main idea behind these scores is to measure how well-defined the cluster's edges are, instead of measuring the dispersion within a cluster...

Summary


Data problems where the input data is unrelated to a labeled output is handled using unsupervised learning. The main objective of such data problems is to understand the data by finding patterns that, in some cases, can be generalized to new instances. In this context, this chapter covered clustering algorithms, which work by aggregating similar data points into clusters, while separating data points that greatly differ. After this, the chapter covered data visualization tools that can be used to analyze problematic features during data preprocessing. We also saw how to apply different algorithms to the dataset and compare their performance to choose the one that best fits the data. Two different metrics for performance evaluation, the Silhouette Coefficient metric and the Calinski-Harabasz index, were also discussed in light of the inability to represent all of the features in a plot, and thereby graphically evaluate performance on scikit-learn. However, it is important to understand...

Left arrow icon Right arrow icon

Key benefits

  • Explore scikit-learn uniform API and its application into any type of model
  • Understand the difference between supervised and unsupervised models
  • Learn the usage of machine learning through real-world examples

Description

As machine learning algorithms become popular, new tools that optimize these algorithms are also developed. Machine Learning Fundamentals explains you how to use the syntax of scikit-learn. You'll study the difference between supervised and unsupervised models, as well as the importance of choosing the appropriate algorithm for each dataset. You'll apply unsupervised clustering algorithms over real-world datasets, to discover patterns and profiles, and explore the process to solve an unsupervised machine learning problem. The focus of the book then shifts to supervised learning algorithms. You'll learn to implement different supervised algorithms and develop neural network structures using the scikit-learn package. You'll also learn how to perform coherent result analysis to improve the performance of the algorithm by tuning hyperparameters. By the end of this book, you will have gain all the skills required to start programming machine learning algorithms.

Who is this book for?

Machine Learning Fundamentals is designed for developers who are new to the field of machine learning and want to learn how to use the scikit-learn library to develop machine learning algorithms. You must have some knowledge and experience in Python programming, but you do not need any prior knowledge of scikit-learn or machine learning algorithms.

What you will learn

  • Understand the importance of data representation
  • Gain insights into the differences between supervised and unsupervised models
  • Explore data using the Matplotlib library
  • Study popular algorithms, such as k-means, Mean-Shift, and DBSCAN
  • Measure model performance through different metrics
  • Implement a confusion matrix using scikit-learn
  • Study popular algorithms, such as Naïve-Bayes, Decision Tree, and SVM
  • Perform error analysis to improve the performance of the model
  • Learn to build a comprehensive machine learning program

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 29, 2018
Length: 240 pages
Edition : 1st
Language : English
ISBN-13 : 9781789801767
Category :
Languages :

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
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 29, 2018
Length: 240 pages
Edition : 1st
Language : English
ISBN-13 : 9781789801767
Category :
Languages :

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 $ 126.97
Machine Learning Fundamentals
$38.99
Artificial Intelligence and Machine Learning Fundamentals
$32.99
Machine Learning Algorithms
$54.99
Total $ 126.97 Stars icon

Table of Contents

6 Chapters
Introduction to Scikit-Learn Chevron down icon Chevron up icon
Unsupervised Learning: Real-Life Applications Chevron down icon Chevron up icon
Supervised Learning: Key Steps Chevron down icon Chevron up icon
Supervised Learning Algorithms: Predict Annual Income Chevron down icon Chevron up icon
Artificial Neural Networks: Predict Annual Income Chevron down icon Chevron up icon
Building Your Own Program Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(3 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Cihan Aug 30, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Why did I spent a lot of money to buy ALL other machine learning books but not this one? After 50 pages, you were lost. However, with this book, finally someone explained what is X, Y, and basic terminology beneath all this process. I mean, author describes every line starting from "import" statements and helps you remember it with immediate exercises. Even though I purchased 4 other books, this is the only text which helps me understand cleaning messy data, dealing with NaN values, normalization and so on. It works with real world data. MUST BUY! Bravo!
Amazon Verified review Amazon
Nicolás Aristizábal Jul 24, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Hyatt treats this complex topic in very simple words. Highly recommended to read!
Amazon Verified review Amazon
JC Dec 26, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This was my first approch to the topic and this book was the best starting point as it explains all concepts very clearly and with detailed examples and activities that helped me cement the knowledge. Even though the theory for each algorithm is very complete, it also teaches how to effectively apply the knowledge in real-life scenarios. I totally recommend it for those starting their journey in machine learning!
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.

Modal Close icon
Modal Close icon