Session Ready
Exercise

Assign cluster membership

In this exercise you will leverage the hclust() function to calculate the iterative linkage steps and you will use the cutree() function to extract the cluster assignments for the desired number (k) of clusters.

You are given the positions of 12 players at the start of a 6v6 soccer match. This is stored in the lineup data frame.

You know that this match has two teams (k = 2), let's use the clustering methods you learned to assign which team each player belongs in based on their position.

Notes:

  • The linkage method can be passed via the method parameter: hclust(distance_matrix, method = "complete")
  • Remember that in soccer opposing teams start on their half of the field.
  • Because these positions are measured using the same scale we do not need to re-scale our data.
Instructions
100 XP
  • Calculate the Euclidean distance matrix dist_players among all twelve players
  • Perform the complete linkage calculation for hierarchical clustering using hclust and store this as hc_players
  • Build the cluster assignment vector clusters_k2 using cutree() with a k = 2
  • Append the cluster assignments as a column cluster to the lineup data frame and save the results to a new data frame called lineup_k2_complete