
Applied Unsupervised Learning with R takes a hands-on approach to using R to reveal the hidden patterns in your unstructured data. It contains multiple activities that use real-life business scenarios for you to practice and apply your new skills in a highly relevant context. The GitHub link for this course is – https://github.com/TrainingByPackt/Applied-Unsupervised-Learning-with-R-eLearning
Each great journey begins with a humble step. Our upcoming adventure in the land of data wrangling is no exception. Before we can do awesome things with data, we need to be prepared with the most productive environment. In this small note, we shall see how to do that.
To process the data on computers and come up with relevant results a class of algorithms are used, known as machine learning algorithms. Machine learning is basically divided into two parts - supervised learning and unsupervised learning, depending on the type of data that is used. Supervised learning is used for processed data, for example, the X-ray images at the hospital. On the other hand, unsupervised learning is done on raw data without labels.
Clustering is a set of methods or algorithms that are used to find natural groupings according to predefined properties of variables in a dataset. Clustering in unsupervised learning means the same as it is defined in the dictionary - several similar things that occur together. Let us look at an example of two clusters in a dataset in the following diagram.
To understand the Iris dataset, we will use the Iris flowers dataset to learn how to classify three species of Iris flowers (Versicolor, Setosa, and Virginica) without using labels. This dataset is built-in to R and is very good for learning about the implementation of clustering techniques.
K-means clustering is one of the most basic types of unsupervised learning algorithm. This algorithm finds natural groupings in accordance with a predefined similarity or distance measure.
Now that we have learnt about k-means clustering and Let us use some built-in libraries of R to perform k-means clustering instead of writing custom code, which is lengthy and prone to bugs and errors.
Market segmentation is dividing customers into different segments with some common characteristics. Customer Segmentation is useful to:
Increase customer conversion and retention
Develop and identify new products for a segment and its needs
Improve brand communication with a segment
Identify gaps and make new marketing strategy
Let us understand this better through an example.
k-medoids is another type of clustering algorithm that can be used to fid natural groupings in a dataset. k-medoids clustering is very similar to k-means clustering, except for a few differences. The k-medoids clustering algorithm has a slightly different optimization function than k-means. In this section, we're going to study k-medoids clustering.
Let us quickly recap our learning from this lesson.
In the previous lesson, we have learnt about the most basic algorithms of unsupervised learning: k-means clustering and k-medoids clustering. These are not only important for practical use but are also important for understanding clustering itself. In this lesson, we will study some other advanced clustering algorithms. k-means is a general-purpose clustering algorithm that is enough for most cases, but in some special cases, depending on the type of data, advanced clustering algorithms can produce better results.
All the clustering types that we have studied so far are based on a distance metric. What if we get a dataset in which it's not possible to measure the distance between variables in a traditional sense, as in the case of categorical variables? In such cases, we use k-modes clustering. k-modes clustering is an extension of k-means clustering, dealing with modes instead of means. One of the major applications of k-modes clustering is analyzing categorical data such as survey results.
Density based clustering or DBSCAN is one of the most intuitive forms of clustering. It is easy to find naturally occurring clusters and outliers in data with this type of clustering. It doesn’t require you to define number of clusters.
Hierarchical clustering merges clusters sequentially. We can see that more clearly with help of the output of a hierarchical clustering algorithm called dendrogram.
Hierarchical clustering is of two types:
Agglomerative
Divisive
Let us learn about these types in detail in the video.
Let us quickly recap our learning from this lesson.
Another form of unsupervised learning called probability distribution is a part of classical statistics in mathematics text courses. With the advent of big data, the use of probability distributions in exploratory data analysis and other modelling applications has increased. Let us study the use of probability distributions as a form of unsupervised learning in this lesson.
There are two families of methods in statistics: parametric and non-parametric methods. Non-parametric methods are meant to deal with data that could take any shape. Parametric methods, by contrast, make assumptions about the shape that data takes on. These assumptions are often encoded as parameters. Let us learn about the different types in this video.
So far, we've studied parametric distributions in this lesson, but in real life, all distributions are either approximations of parametric distributions or don't resemble any parametric distributions at all. In such cases, we use a technique called Kernel Density Estimation, or KDE, to estimate their probability distributions.
Now that we’ve learned how to generate the probability density functions of datasets that don't closely resemble standard distributions, we’ll learn how to perform some tests to distinguish these nonstandard distributions from each other.
Let us quickly recap our learning from this lesson.
This lesson presents techniques for unsupervised learning that accomplish something called dimension reduction. First, we will discuss what a dimension is, why we want to avoid having too many dimensions, and the basic idea of dimension reduction.
The dimensions of a dataset are nothing more than the collection of distinct numbers that are required to describe observations in it. Let us learn about the various dimension reduction techniques.
Market basket analysis or Affinity Analysis is a method that allows us to take high-dimensional data and reduce it to something that is simple and manageable without losing too much information along the way. In market basket analysis, our goal is to generate rules that govern the data. Let us understand this better through an example of a grocery store in the upcoming video.
Now that we have prepared our data for the main steps of market basket analysis, let us consider the factors that will determine the parameters we will use in our algorithm.
The next type of dimension reduction method we will cover is called PCA. This is a very common technique used by researchers in a wide variety of fields. Let us learn about PCA and its implementation in this video.
Let us quickly recap our learning from this lesson.
Unsupervised learning is concerned with analyzing the structure of data to draw useful conclusions. In this lesson, we will examine methods that enable us to use the structure of data to compare datasets. The major methods we will look at are hash functions, analytic signatures, and latent variable models.
Imagine that you want to send an R script to your friend. However, you and your friend have been having technical problems with your files – maybe your computers have been infected by malware, or maybe a hacker is tampering with your files. So, you need a way to ensure that your script is sent intact to your friend, without being corrupted or changed. Let us understand the different means to overcome this situation
Each time you sign your name, your signature should look the same. To verify whether a signature matches, we need to check for substantial similarity but not perfect identity. The method for encoding image data that enables quick and approximate comparisons between datasets is referred as an analytic signature. Before we create an analytic signature, let us do some data preparation, as outlined in the next exercise.
Now that we have learnt about Analytic signatures, as next step, we can compare these two signatures, to see whether they have mapped our different images to different signature values.
So far, we have only used hashes and analytic signatures to compare two images or four short strings. However, there is no limit to the unsupervised learning methods that can be applied to hashes or analytic signatures. Let’s see how.
Latent variable model’s express data in terms of a small number of variables that are hidden or latent. By finding the latent variables that correspond to a dataset, we can better understand the data and potentially even understand where it came from or how it was generated. Let us learn this better through different theories of intelligence.
Let us quickly recap our learning from this lesson.
Data analysis often begins with an implicit assumption that all observations are valid, accurate, and trustworthy. Unsupervised learning is used in various instances to detect anomalous behavior, for example, to identify fraudulent transactions in a bank, to find defective products by manufactures and so on. Let us study several anomaly detection techniques in the following sections.
Anomaly detection is simplest in the univariate case, that is, when each observation is only one number. For univariate data, anomaly detection consists of looking for outliers. R's built-in boxplot function makes an initial exploratory check for outliers quite easy. Let us learn this better through the following exercise.
Parametric anomaly detection, as explained in this video, is common practice. However, its applicability depends on whether the parametric assumptions behind it are valid.
Collective anomalies are a collection of related data instances that are anomalous to the entire data set. Contextual anomalies are observations that are considered anomalies only because of their neighbors. Let us learn these concepts better through an example in this video.
Kernel density estimation provides a natural way to test whether these new results are anomalous, even without having specialized knowledge of the blood test being used or even of medicine in general. To calculate Kernel density, we need to specify the bandwidth which is a measure of the variance of the normal distributions that we are using to model our data. Let us learn this in detail through the following video.
Let us quickly recap our learning from this lesson.
Starting with the basics, Applied Unsupervised Learning with R explains clustering methods, distribution analysis, data encoders, and features of R that enable you to understand your data better and get answers to your most pressing business questions.
This course begins with the most important and commonly used method for unsupervised learning - clustering - and explains the three main clustering algorithms - k-means, divisive, and agglomerative. Following this, you'll study market basket analysis, kernel density estimation, principal component analysis, and anomaly detection. You'll be introduced to these methods using code written in R, with further instructions on how to work with, edit, and improve R code. To help you gain a practical understanding, the course also features useful tips on applying these methods to real business problems, including market segmentation and fraud detection. By working through interesting activities, you'll explore data encoders and latent variable models.
By the end of this course, you will have a better understanding of different anomaly detection methods, such as outlier detection, Mahalanobis distances, and contextual and collective anomaly detection.
About the Author
Alok Malik is a data scientist based in India. He has previously worked on creating and deploying unsupervised learning solutions in fields such as finance, cryptocurrency trading, logistics, and natural language processing. He has a bachelor's degree in technology from the Indian Institute of Information Technology, Design and Manufacturing, Jabalpur, where he studied electronics and communication engineering.Bradford Tuckfield has designed and implemented data science solutions for firms in a variety of industries. He studied math for his bachelor's degree and economics for his Ph.D. He has written for scholarly journals and the popular press, on topics including linear algebra, psychology, and public policy.
Bert Gollnick is a Diploma in Aerospace Engineering and has pursued MSc in Economics.
He is also a Data Scientist and has 10 years experience in R. He is also an online trainer for Data Science and Machine Learning.