code wiki / (root) / sketch_naive_bayes_vs_majority_bench.nx

sketch_naive_bayes_vs_majority_bench.nx

buildroot/runtime/sketch_naive_bayes_vs_majority_bench.nx

4407 B127 linesdepth 6pulls 7 transitivereach 0 importersview sourcekind benchtopic sketch
docsdependenciesstructsconstsfunctions

about

sketch_naive_bayes_vs_majority_bench.nx -- classification accuracy bench. CLAIM TO VALIDATE: Naive Bayes (Maron 1961) outperforms a majority-class baseline when features actually carry signal about the class. Without real per-feature likelihood, classification = majority class. Test: a streaming binary classification task where class 1 has features {1, 2, 3, 4} with high probability and class 0 has features {5, 6, 7, 8} with high probability. Some overlap to make it non-trivial. WORKLOAD: Train: 200 samples per class (400 total). Test: 100 fresh samples per class. Majority baseline: always predicts the more frequent class (both 50% here so any constant prediction → 50% accuracy). NaiveBayes should hit >=80% accuracy by learning the feature distribution. MEASUREMENT: ACCURACY axis: NB correct count vs majority correct count.

dependencies 4 imports · 0 importers

syscalls.nx sketch_naive_bayes.nx sketch_comparator.nx sketch_types.nx sketch_naive_bayes_vs_majority

imports: syscalls.nxsketch_naive_bayes.nxsketch_comparator.nxsketch_types.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_nb_alloc nx_hmap_alloc nx_hmap_is_pow2 nx_nb_observe_class nx_nb_observe_feature nx_hmap_get nx_hmap_probe_find nx_hmap_hash nx_hmap_entry_at nx_hmap_entry_at ↻ nx_hmap_put nx_hmap_probe_insert nx_hmap_hash ↻ nx_hmap_entry_at ↻ nx_hmap_entry_at ↻ nx_nb_predict nx_nb_score_ppm nx_nb_log_class_prior_ppm nx_nb_log2_ppm nx_nb_log_feature_likeliho nx_hmap_get ↻ nx_nb_log2_ppm ↻ nx_cmp_accuracy nx_cmp_iabs

structs

none

consts

30const NX_NBB_LCG_A: i64 = 1103515245
31const NX_NBB_LCG_C: i64 = 12345
32const NX_NBB_LCG_MOD: i64 = 0x7FFFFFFF

functions

34func main() -> i64