<jupyter_start><jupyter_text>Understanding the Rand indexSee [Wikipedia](https://en.wikipedia.org/wiki/Rand_index) for a simple explanationThe ARi will give a score from close to zero for random assignments to 1 for a perfect assignment, regardless of the number of clusters used.<jupyter_code>import numpy as np
import pandas as pd
y_true = np.random.randint(0, 3, 100)
y_pred_1 = np.random.randint(0, 3, 100)
y_pred_2 = y_true
y_pred_3 = np.where(np.random.rand(100) < 0.8, y_true, y_pred_1)
y = pd.DataFrame(np.c_[y_true, y_pred_1, y_pred_2, y_pred_3], 
                 columns='Y Y1 Y2 Y3'.split())
y
from sklearn.metrics import adjusted_rand_score
for pred in ['Y1', 'Y2', 'Y3']:
    print(f'ARI(Y, {pred}) = {adjusted_rand_score(y.Y, y[pred]):.3}')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12611464968152866, 'fraction_numerical': 0.03821656050955414, 'mean_word_length': 5.046153846153846, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '218305', 'license': 'MIT', 'n_tokens_mistral': 314, 'n_tokens_neox': 295, 'n_words': 80, 'path': 'notebooks/Adjusted_Rand_Index.ipynb', 'repo_name': 'cliburn/bios-823-2021', 'size': '785'}