What are the time and space complexities of training a Naive Bayes classifier?

Quick Overview

Work out the training time and model size of a Naive Bayes classifier in terms of samples, features and classes. Tests why training is a single counting pass, how sparse inputs change the bound, and what the Gaussian, multinomial and categorical variants store.

What are the time and space complexities of training a Naive Bayes classifier?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

What are the time and space complexities of training a Naive Bayes classifier? Use $n$ for the number of training samples, $d$ for the number of features and $K$ for the number of classes. ```hint Count the statistics List the quantities each Naive Bayes variant estimates per class and per feature, then ask how many times training needs to look at each sample to compute them. ``` ### What a Strong Answer Covers - The training time bound and why a single pass over the data is enough - How sparse input changes the time bound - The model size for the common variants, including features with many categorical values - What the model keeps after training, compared with methods that store the data or optimize iteratively ### Follow-up Questions - What does it cost to predict one sample, and how can Bernoulli Naive Bayes keep that cost low on sparse input? - How would you train Naive Bayes on data spread across many machines? - How does the hashing trick change the space bound for a text classifier with an open vocabulary?

Overview: Work out the training time and model size of a Naive Bayes classifier in terms of samples, features and classes. Tests why training is a single counting pass, how sparse inputs change the bound, and what the Gaussian, multinomial and categorical variants store.

General logo
General
Nov 24, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

What are the time and space complexities of training a Naive Bayes classifier?

Use nn for the number of training samples, dd for the number of features and KK for the number of classes.

What a Strong Answer Covers Guidance

  • The training time bound and why a single pass over the data is enough
  • How sparse input changes the time bound
  • The model size for the common variants, including features with many categorical values
  • What the model keeps after training, compared with methods that store the data or optimize iteratively

Follow-up Questions Guidance

  • What does it cost to predict one sample, and how can Bernoulli Naive Bayes keep that cost low on sparse input?
  • How would you train Naive Bayes on data spread across many machines?
  • How does the hashing trick change the space bound for a text classifier with an open vocabulary?