In this post, I’ll explain what hierarchical clustering is and how to implement it with Python.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1234)
N = 10 # number of points
matrix = np.random.rand(N, 2) # N points in 2 dimensional space
M = matrix * 10 # multiply ten so that the numbers are easier to understand. # Otherwise, all numbers are between 0 and 1
M
arr …