Underwater target localization technology plays a vital role in the development and utilization of marine resources. Due to the multipath effect in the hydroacoustic channel, the received signal is the superposition of a series of direct and reflected acoustic paths, making it challenging to accurately identify the direct path using existing methods. To address this issue, this paper proposes a high-precision direct path recognition method based on Light Gradient Boosting Machine (LightGBM), which utilizes the amplitude, Time of Arrival (TOA), reception angle, and phase of the received pulse as input features. Meanwhile, the direct linear conversion of acoustic wave propagation time from transmitter to receiver into a distance value, as commonly observed in radio ranging in air, is not feasible. Consequently, a method based on Effective Sound Velocity (ESV) is introduced to compensate for the bending of sound rays. By utilizing the recognized direct path delay value and the sound velocity value after compensating for sound ray bending, we can calculate the precise position of underwater targets. Experimental results validate the effectiveness of the proposed method in significantly improving the accuracy of underwater target localization.