Beamforming has been one of the most important enabling techniques for millimeter wave (mmWave) communications and massive multiple-in-multiple-out (MIMO) systems. Due to the hardware limitation, fully digital beamforming has been proven to be difficult to achieve for commercial cellular communication systems. Consequently, the hybrid beamforming, as a combination of digital baseband precoders and analog RF phase shifters, has been intensively investigated in an attempt to achieve a performance close to the fully digital beamformers. In this paper, we further step to develop a more flexible and feasible hybrid beamforming system that utilizes the machine learning techniques, to improve the achievable spectral efficiency. After using the traditional convex optimization techniques to optimize the baseband and phase shifter outputs, the results are then introduced to different machine learning approximation networks to approach the performance of fully digital beamforming. Simulation results show that the suggested two-step algorithm can attain almost the same efficiency as that can be achieved by fully digital architectures.