Practical implementation of quantum key distributions (QKD) requires efficient, real-time feedback control to maintain system stability when facing disturbance from either external environment or imperfect internal components. Usually, a “scanning-and-transmitting” program is adopted to compensate physical parameter variations of devices, which can provide accurate compensation but may cost plenty of time in stopping and calibrating processes, resulting in reduced efficiency in key transmissions. Here, we propose to employ a well-known machine learning model, i.e., the long short-term memory network (LSTM), to predict those physical parameter variations in advance and actively perform real-time control on corresponding QKD devices. Experimentally, we take the phase-coding scheme as an example and run the LSTM-model-based QKD system for more than 10 days. Experimental results show that we can keep the same level of quantum-bit error rate as the traditional scanning-and-transmitting program by employing our machine learning method, but dramatically reducing the scanning time and resulting in significantly enhanced key transmission efficiency. Furthermore, our current machine learning model should also be applicable to other QKD systems using any coding scheme or QKD protocols and thus seems a very promising candidate in large-scale application of quantum communication networks in the near future.