Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Case 2: Four Distinct Clusters | K-Means Algorithm
Cluster Analysis in Python
course content

Course Content

Cluster Analysis in Python

Cluster Analysis in Python

1. K-Means Algorithm
2. K-Medoids Algorithm
3. Hierarchical Clustering
4. Spectral Clustering

Case 2: Four Distinct Clusters

Well, I think that the model did good work. But what if we try to divide the points into 4 groups?

Task

  1. Import necessary libraries with their standard aliases. These are pandas (pd), matplotlib.pyplot (plt), seaborn (sns), and KMeans from sklearn.cluster.
  2. Create a KMeans model object with 4 clusters.
  3. Fit the data to the model.
  4. Predict the labels for data. Save the result within the 'prediction' column of data.
  5. Build scatter plot for 'x' and 'y' columns of data with each point being painted with respect to the 'prediction' column.

Task

  1. Import necessary libraries with their standard aliases. These are pandas (pd), matplotlib.pyplot (plt), seaborn (sns), and KMeans from sklearn.cluster.
  2. Create a KMeans model object with 4 clusters.
  3. Fit the data to the model.
  4. Predict the labels for data. Save the result within the 'prediction' column of data.
  5. Build scatter plot for 'x' and 'y' columns of data with each point being painted with respect to the 'prediction' column.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 1. Chapter 5
toggle bottom row

Case 2: Four Distinct Clusters

Well, I think that the model did good work. But what if we try to divide the points into 4 groups?

Task

  1. Import necessary libraries with their standard aliases. These are pandas (pd), matplotlib.pyplot (plt), seaborn (sns), and KMeans from sklearn.cluster.
  2. Create a KMeans model object with 4 clusters.
  3. Fit the data to the model.
  4. Predict the labels for data. Save the result within the 'prediction' column of data.
  5. Build scatter plot for 'x' and 'y' columns of data with each point being painted with respect to the 'prediction' column.

Task

  1. Import necessary libraries with their standard aliases. These are pandas (pd), matplotlib.pyplot (plt), seaborn (sns), and KMeans from sklearn.cluster.
  2. Create a KMeans model object with 4 clusters.
  3. Fit the data to the model.
  4. Predict the labels for data. Save the result within the 'prediction' column of data.
  5. Build scatter plot for 'x' and 'y' columns of data with each point being painted with respect to the 'prediction' column.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 1. Chapter 5
toggle bottom row

Case 2: Four Distinct Clusters

Well, I think that the model did good work. But what if we try to divide the points into 4 groups?

Task

  1. Import necessary libraries with their standard aliases. These are pandas (pd), matplotlib.pyplot (plt), seaborn (sns), and KMeans from sklearn.cluster.
  2. Create a KMeans model object with 4 clusters.
  3. Fit the data to the model.
  4. Predict the labels for data. Save the result within the 'prediction' column of data.
  5. Build scatter plot for 'x' and 'y' columns of data with each point being painted with respect to the 'prediction' column.

Task

  1. Import necessary libraries with their standard aliases. These are pandas (pd), matplotlib.pyplot (plt), seaborn (sns), and KMeans from sklearn.cluster.
  2. Create a KMeans model object with 4 clusters.
  3. Fit the data to the model.
  4. Predict the labels for data. Save the result within the 'prediction' column of data.
  5. Build scatter plot for 'x' and 'y' columns of data with each point being painted with respect to the 'prediction' column.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Well, I think that the model did good work. But what if we try to divide the points into 4 groups?

Task

  1. Import necessary libraries with their standard aliases. These are pandas (pd), matplotlib.pyplot (plt), seaborn (sns), and KMeans from sklearn.cluster.
  2. Create a KMeans model object with 4 clusters.
  3. Fit the data to the model.
  4. Predict the labels for data. Save the result within the 'prediction' column of data.
  5. Build scatter plot for 'x' and 'y' columns of data with each point being painted with respect to the 'prediction' column.

Switch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 5
Switch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt