Optical frequency combs have been widely used in spectrum analysis, coherent optical communication, and accurate distance measurement. We propose a straightforward method to improve the flatness of optical frequency combs. First, we derived the output of the optical signal for the configuration of a cascaded MZM and two PMs. Second, we identified the parameter value when the flatness was optimal after traversing different parameter spaces. The optimal flatness conditions could be automatically determined from an existing sample dataset by using neural networks and Bayesian optimization, which significantly reduced the calculation cost. Furthermore, a broad spectrum and low power consumption were also achieved. Finally, the generated optical frequency comb signal was divided into eight carriers with 50 GHz intervals, and the optical transmission system was verified by applying a 16-QAM modulation of 40 GBaud/s to each channel. The constellation diagram proved the feasibility of this optical comb generation scheme.