The solar wind transports solar activity energy to interplanetary space,causing changes in the spatial structure of the Earth's magnetosphere and causing disastrous space weather.The Kp index is an important indicator for space weather alerts and a key parameter for the coupling between solar wind and the magnetosphere.With the development of machine learning methods,more and more space weather forecasting works adopt this method.In this paper,two machine learning methods,Gradient Boosting Regression(GBR)algorithm and Random Forest(RF),are used to construct a 3-hour Kp in-dex prediction model with solar wind,interplanetary magnetic field parameters,historical Kp values and sunspot data as inputs.The forecast results show that our methods can predict the Kp index one hour in advance and the correlation coefficient is 0.90 between the Kp index of the optimal case recommended by the model and the actual value.The GBR model performs better,the root Mean Square Error(Erms)is 0.56,and the Prediction Efficiency(P)is 0.81.The Kp index prediction model shows varying perfor-mances in different solar cycle phases,with better result during the cycle descending phase.The high-speed solar wind drive dominates the magnetospheric dynamics,and the model with solar wind as the main input parameter in the cycle descending phase has a better prediction effect.The model prediction situations under different geomagnetic disturbances have been compared.Compared with moderate and super severe magnetic storms,the model has the highest prediction accuracy for severe magnetic storms(6≤ Kp<7).In this study,the results of different prediction models are compared and analyzed.The pre-diction model can not only provide early warning of severe space weather,but also better understand the relationship between geomagnetic index and solar wind input energy,which provides more methods and theoretical basis for the research work of solar wind-magnetosphere coupling.