Machine learning is used to investigate the codon usage of protein-encoding genes, which is one of the fundamental questions of molecular biology. The presentation, parameter learning, and decoding of the conditional random field (CRF) model are implemented and then utilized to analyze the codon usage of the genes ofEscherichia coliand its phages. Most genes ofE. coliuse codons conforming to the weights of the model determined by allE. coligenes. Phages use the codons like their hostE. coli. Finally, the study evaluates the codon usage of several example genes in the context of the model. These results help to understand the codon usage inE. coli.