This paper proposes a two-dimensional photonic crystal structure for designing optical NAND and NOR logic gates using dielectric rods in an air substrate. The simplicity and compact size of the proposed structure make it suitable for the fabrication of integrated optical circuits. This study leverages machine learning methods, specifically the AdaBoost Regressor and Feedforward Neural Network (FNN) models, to enhance gate performance by identifying optimal parameters. Notably, this research introduces the optimization of the phase parameter and rod radius to improve gate efficiency. Additionally, we evaluated 30 different architectures to determine the best FNN model for each scenario. The proposed gates exhibit high output power for the logical “1” state and low output power for the logical “0” state, which is crucial for minimizing detection errors. Our results indicate that machine learning techniques can significantly enhance the performance and reliability of optical logic gates, paving the way for advancements in integrated optical circuit design.