# Check: how much does the learning curve depend on the shuffle (seed)?
# Same setup as part5_learning_curve.py, repeated for the seeds 572 and 1 to 9
# (the list was fixed before running). Prints the lowest and highest accuracy
# over the 10 seeds for each training size.
import numpy as np
from common import load_split
from nb import train_nb, classify_documents, accuracy

SEEDS = [572, 1, 2, 3, 4, 5, 6, 7, 8, 9]
train_docs, train_labels, eval_docs, eval_labels = load_split()
n = len(train_docs)

results = {pct: [] for pct in range(10, 101, 10)}
for seed in SEEDS:
    order = np.random.default_rng(seed).permutation(n)
    for pct in results:
        k = int(round(pct / 100 * n))
        idx = order[:k]
        model = train_nb([train_docs[i] for i in idx], [train_labels[i] for i in idx])
        results[pct].append(accuracy(eval_labels, classify_documents(eval_docs, model)))

print('percent  lowest  highest')
for pct, accs in results.items():
    print(pct, ' ', round(min(accs), 4), ' ', round(max(accs), 4))
