etric</span><span class="o">=</span><span class="n">dist_method</span><span class="p">)</span>
    <span class="n">link_mat</span> <span class="o">=</span> <span class="n">hierarchy</span><span class="o">.</span><span class="n">linkage</span><span class="p">(</span><span class="n">dist_mat</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="n">cluster_method</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">optimal</span><span class="o