Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Weather Data: Complete and Ward Linkages | Hierarchical Clustering
Cluster Analysis in Python
course content

Kursusindhold

Cluster Analysis in Python

Cluster Analysis in Python

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

book
Weather Data: Complete and Ward Linkages

The last chart was good, but if you remember the K-Means and K-Medoids algorithms results, you may remember that there was at least one more line that unlike all the others goes downwards close to July. The average linkage in hierarchical clustering didn't catch that dynamic.

We saw that for complete and ward linkages there is sense to consider 4 clusters. Let's find out will they catch that?

Opgave

Swipe to start coding

Table
  1. Import numpy with np alias.
  2. Iterate over the linkages list. At each step:
  • Create a hierarchical clustering model with 4 clusters and method j named model.
  • Fit the numerical data of temp and predict the labels. Add predicted labels as the 'prediction' column to temp.
  • Create a temp_res DataFrame with monthly averages for each group. To do it group the values of temp by the 'prediction' column, calculate the mean, and then apply the .stack() method.
  • Add column 'method' to temp_res DataFrame with value j being repeated the number of rows in temp_res times.
  • Merge res and temp_res dataframes using .concat function of pd.
  1. Reassign the column names of res to ['Group', 'Month', 'Temp', "Method"].
  2. Within the FacetGrid function set the col parameter to 'Method'. This will build a separate chart for each value of the 'Method' column.
  3. Within the .map function set the seaborn line plot function as the first parameter.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 7
toggle bottom row

book
Weather Data: Complete and Ward Linkages

The last chart was good, but if you remember the K-Means and K-Medoids algorithms results, you may remember that there was at least one more line that unlike all the others goes downwards close to July. The average linkage in hierarchical clustering didn't catch that dynamic.

We saw that for complete and ward linkages there is sense to consider 4 clusters. Let's find out will they catch that?

Opgave

Swipe to start coding

Table
  1. Import numpy with np alias.
  2. Iterate over the linkages list. At each step:
  • Create a hierarchical clustering model with 4 clusters and method j named model.
  • Fit the numerical data of temp and predict the labels. Add predicted labels as the 'prediction' column to temp.
  • Create a temp_res DataFrame with monthly averages for each group. To do it group the values of temp by the 'prediction' column, calculate the mean, and then apply the .stack() method.
  • Add column 'method' to temp_res DataFrame with value j being repeated the number of rows in temp_res times.
  • Merge res and temp_res dataframes using .concat function of pd.
  1. Reassign the column names of res to ['Group', 'Month', 'Temp', "Method"].
  2. Within the FacetGrid function set the col parameter to 'Method'. This will build a separate chart for each value of the 'Method' column.
  3. Within the .map function set the seaborn line plot function as the first parameter.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 7
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt