Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Clustering Weather Data | K-Means Algorithm
Cluster Analysis in Python
course content

Contenuti del Corso

Cluster Analysis in Python

Cluster Analysis in Python

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

book
Clustering Weather Data

Let's work with some real data. If you passed the 'Visualization in Python with matplotlib' course you might remember the USA cities' weather data. We will use an expanded version of this dataset there.

First, let's describe our dataset. It contains 15 columns: Country, City, All the 12 months, and Continent. Obviously, the months' columns are numerical and contain the average monthly temperature in Fahrenheit. For example, each row of this DataFrame looks like this.

We may guess that it would be logical to cluster by continent. But let's remind, that all the continents combine different climate types, which depend on proximity to the sea, to the ocean, to mountains, and so on. So, let's find out how will K-Means algorithm divide the observations.

Compito

Swipe to start coding

Given DataFrame data. Watch out, that numerical columns have indices 2 - 13! Table

  1. Import the pandas, seaborn libraries with their standard aliases (pd and sns respectively), and KMeans from sklearn.clusters.
  2. Create range object with integers from 2 to 9 assigned to clusters variable.
  3. Iterate over clusters values. At each step:
  • Initialize KMeans model with new number of clusters (i).
  • Fit the model to 2-13 (indices) columns of data. Remember .iloc[] method of DataFrame. You can pass the first parameter to access certain rows, and the second to access columns.
  • Add model total within sum of squares value (value of .inertia_ attribute of model) to variances list.
  1. Display the seaborn lineplot "number of clusters vs total within sum of squares" (clusters - x-axis vs variances - y-axis).

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 6
toggle bottom row

book
Clustering Weather Data

Let's work with some real data. If you passed the 'Visualization in Python with matplotlib' course you might remember the USA cities' weather data. We will use an expanded version of this dataset there.

First, let's describe our dataset. It contains 15 columns: Country, City, All the 12 months, and Continent. Obviously, the months' columns are numerical and contain the average monthly temperature in Fahrenheit. For example, each row of this DataFrame looks like this.

We may guess that it would be logical to cluster by continent. But let's remind, that all the continents combine different climate types, which depend on proximity to the sea, to the ocean, to mountains, and so on. So, let's find out how will K-Means algorithm divide the observations.

Compito

Swipe to start coding

Given DataFrame data. Watch out, that numerical columns have indices 2 - 13! Table

  1. Import the pandas, seaborn libraries with their standard aliases (pd and sns respectively), and KMeans from sklearn.clusters.
  2. Create range object with integers from 2 to 9 assigned to clusters variable.
  3. Iterate over clusters values. At each step:
  • Initialize KMeans model with new number of clusters (i).
  • Fit the model to 2-13 (indices) columns of data. Remember .iloc[] method of DataFrame. You can pass the first parameter to access certain rows, and the second to access columns.
  • Add model total within sum of squares value (value of .inertia_ attribute of model) to variances list.
  1. Display the seaborn lineplot "number of clusters vs total within sum of squares" (clusters - x-axis vs variances - y-axis).

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 6
Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Siamo spiacenti che qualcosa sia andato storto. Cosa è successo?
some-alt