Hidden Markov models are a powerful technique to model and classify temporal sequences, such as in speech and gesture recognition. However, defining these models is still an art: the designer has to establish by trial and error the number of hidden states, the relevant observations, etc. We propose an extension of hidden Markov models, called dynamic naive Bayesian classifiers, and a methodology to learn automatically these models from data. The method determines: (i) the number of hidden states, (ii) the relevant attributes, (iii) the best discretization, and (iv) the structure of the model. Experimental results on learning different dynamic naive Bayesian classifiers for gesture recognition, show that our method improves significantly the recognition rates, and at the same time obtains simpler models.