In this KnowledgeCity course on Python for Data Science Advanced: Unsupervised Learning, you’ll learn about unsupervised machine learning by studying…
In this KnowledgeCity course on Python for Data Science Advanced: Unsupervised Learning, you’ll learn about unsupervised machine learning by studying principals, component analysis, and clustering techniques. We’ll go over principal component analysis, and how to cluster data using K-means in Python. You’ll also learn about the DBSCAN unsupervised machine learning algorithm, and we’ll spend time covering affinity propagation in the realm of machine learning.
Unsupervised learning is a way for machines to find patterns or groups in data without being told what those patterns are. We’ll explore DBSCAN, an acronym that stands for Density-Based Spatial Clustering of Applications with Noise. It's an unsupervised machine learning algorithm used for clustering data points in a dataset. K-means is a popular unsupervised machine learning algorithm used for clustering and data partitioning. Its primary goal is to group data points into clusters. We’ll also explore affinity propagation, a clustering algorithm used in unsupervised machine learning that doesn't require you to specify the number of clusters beforehand—instead, it discovers the number of clusters from the data all on its own.
Learning Objectives
- Explain how unsupervised machine learning works
- Describe the functions of various unsupervised learning algorithms
- Understand how to find clusters within data using affinity propagation
Skills you’ll gain
DbscanDeep LinkingK-Means ClusteringUnsupervised LearningWhat You'll Learn
- Explain how unsupervised machine learning works and finds patterns or groups in data without being told what those patterns are
- Apply principal component analysis to data
- Cluster data using the K-means algorithm in Python
- Use the DBSCAN (Density-Based Spatial Clustering of Applications with Noise) algorithm to cluster data points
- Find clusters within data using affinity propagation without specifying the number of clusters beforehand
- Describe the functions of various unsupervised learning algorithms
Key Takeaways
- Unsupervised learning lets machines find patterns or groups in data without being told what those patterns are.
- K-means is a popular unsupervised machine learning algorithm used for clustering and data partitioning, grouping data points into clusters.
- DBSCAN stands for Density-Based Spatial Clustering of Applications with Noise and is an unsupervised algorithm used for clustering data points in a dataset.
- Affinity propagation does not require you to specify the number of clusters beforehand; it discovers the number of clusters from the data on its own.
- Principal component analysis is one of the techniques covered for working with data in unsupervised learning.
Frequently Asked Questions
What clustering techniques does this course cover?
The course covers principal component analysis and clustering techniques including K-means, DBSCAN, and affinity propagation.
What is DBSCAN as taught in this course?
DBSCAN stands for Density-Based Spatial Clustering of Applications with Noise, an unsupervised machine learning algorithm used for clustering data points in a dataset.
Do I need to specify the number of clusters when using affinity propagation?
No. Affinity propagation does not require you to specify the number of clusters beforehand; it discovers the number of clusters from the data on its own.
What skills will I gain from this course?
You will gain skills in DBSCAN, deep linking, K-means clustering, and unsupervised learning.
What programming language is used in this course?
The course uses Python, for example to cluster data using K-means.
Transcript
Show transcript (free preview lesson)
Transcript of the free preview lesson. Remaining lessons unlock with the full course.
Hello, my name is Nissar Dajani, and in these lessons, you will learn about unsupervised machine learning through principal component analysis and clustering techniques, for example, a means, DB scan, and affinity propagation. And in this lesson, you will learn about principal component analysis, or PCA for short. So imagine you have a big box of colored marbles, but you just don't know how to sort them because you don't have any labels like red, blue, or green. Unsupervised machine learning is like trying to figure out how to group these marbles without any help. You look at their colors and shapes and try to find patterns on your own. In the world of computers and data, unsupervised learning is a way for machines to find patterns or groups in data without being told what those patterns are. It's like teaching a computer to spot similarities in things like grouping pictures of apples and bananas together without telling the computer which is which. So that's the general concept behind unsupervised machine learning. Now imagine you have a lot of pictures and they're very detailed. Sometimes all these details can make it hard to understand what's important in the picture. PCA, which is a type of unsupervised machine learning, is like having a magic tool that can help you focus on the most important parts. When you use PCA on pictures, it takes the complex details and simplifies them. It's like squishing or rotating the picture in a way that keeps the most important stuff and removes less important stuff. So you end up with a simpler picture that still has all the main information. In simpler terms, PCA helps you reduce the busyness of pictures or data so you can understand them better. It's like finding the essential parts in a sea of details. So in a nutshell, unsupervised learning is about finding patterns in data without being told what those patterns are. And PCA is a tool to make complicated data simpler to understand by focusing on the most important parts. Alright, let's switch to a Jupyter Notebook to review a code example and see how we can implement unsupervised learning and specifically PCA using some Python code. I start by first importing the required libraries. I have NumPy for numerical operations and data manipulation. I have pandas for more data manipulation capabilities. I have Pyplot from Matplotlib for creating plots and data visualization. And I have PCA and standard scalar from sklearn decomposition and sklearn pre-processing, respectively. These are used for performing PCA and data standardization. Next I have my sample data. Here we generate a random data set of 100 data points with two features using NumPy. The np.random.seed is used to ensure reproducibility, meaning that some random data will be generated each time you run the code. Next we standardize the data. Standardization makes sure that all features have a mean of zero and a variance, also called a spread, of one. This step is essential because PCA is sensitive to the scale of the data and standardization ensures that all features are on the same scale. Then we apply PCA with the end-components parameter set to 2, indicating that we want to reduce the dimensionality to just two components. PCA then computes these two new components based on the original data. Next we calculate and store the explained variance ratios. These values tell us how much of the total variance in the data is explained by each of the two principal components. And in this part, we create a figure with two sub-lots. The first sub-lot, denoted by PLT.subplot121, displays the original standardized data as a scatterplot. And the second sub-lot, denoted by PLT.subplot122. This one will display the data, but after applying PCA. Now the 121 in PLT.subplot121. This is used to specify the arrangement of sub-lots in a grid when creating multiple sub-lots with any single figure. It's a way of dividing a figure into rows and columns to determine where a specific sub-lot should be placed. In PLT.subplot121, the 121 can be broken down as follows. The first digit, which is the one, this specifies the number of rows in the grid. The second digit, which is the two, this specifies the number of columns in the grid. And the third digit, which is the one, this specifies the position of the current sub-lot within the grid, counting from the top left and moving from the left to the right. So in this case, PLT.subplot121 means you are creating a grid with one row and two columns, and you are selecting the first position in that grid, which would be the top left position for the current sub-lot. This allows you to place two sub-lots side by side within the same figure. And so for the second sub-lot, the PLT.subplot122. This means it's the second sub-lot in this figure. As you can see, this numbering system is a convenient way to arrange and label sub-lots when working with multiple plots in a single figure. Then we call the PLT.show method to display the two sub-lots, followed by a printout of the explained variance ratio. So let's run this code and see where we get back. The output of this code will be a single figure with two sub-lots side by side. The first sub-lot, labeled OriginalData, shows the original standardized data as a scatter-plot. Each point in the scatter-plot represents a data point from the data set. Then the second sub-lot, labeled PCAReduceData, shows the data after applying PCA. In this plot, you will notice that the data is transformed and might look different. PCA has effectively reduced the dimensionality of the data while preserving the most important information. Scatterplot in this sub-lot shows how the data looks in this reduced form. Then just below the sub-lots, we have the explained variance ratios printed in the console. This indicates how much of the total variance in the data is explained by each of the two principal components. Typically, one component explains a significant portion of the variance, while the other explains less. These ratios help us understand how much information is retained after dimensionality reduction. So the first value of 0.5120026, this represents the proportion of the total variance in the data that is explained by the first principal component, so in this case, it's approximately 51.2%. The second value of 0.4879974, this represents the proportion of the total variance in the data that is explained by the second principal component, and it's approximately 48.8%. These values sum up to 1 or 100%, because they account for the entire variance in the data. The first value, the 51.2%, is larger, which means the first principal component captures more of the variance in the data, while the second principal component captures the remaining variance. When the first principal component explains a large portion of the variance, it means it retains most of the important information in the data. Practice, this suggests that you can effectively reduce the data's dimensionality by using just the first principal component while retaining a significant amount of the data's original formation. In many PCE applications, you might choose to retain only the top N principal components, where N is determined by the cumulative explained variance you wish to preserve. For instance, if you want to retain 95% of the variance, you would sum the explained variance ratios and keep the first few components that achieve that cumulative ratio. In our case here, the first component explains the majority of the variance, so it's often sufficient to work with only the first component for dimensionality reduction, while the second component might be less informative in our analysis. So in this lesson, you learned about principal component analysis. In the next lesson, you will learn about K-means. Thanks for watching.
Learn on the Go
Take your learning anywhere — the KnowledgeCity mobile app lets you watch lessons on the go.