Safety is the key point of railway transportation, and railway traffic accident prediction is the main content of safety management. There are complex nonlinear relationships between an accident and its relevant indexes. For this reason, triangular gray relational analysis (TGRA) is used for obtaining the indexes related to the accident and the deep auto-encoder (DAE) for finding out the complex relationships between them and then predicting the accident. In addition, a nonlinear weight changing particle swarm optimization algorithm, which has better convergence and global searching ability, is proposed to obtain better DAE structure and parameters, including the number of hidden layers, the number of neurons at each hidden layer and learning rates. The model was used to forecast railway traffic accidents at Shenyang Railway Bureau, Guangzhou Railway Corporation, and Nanchang Railway Bureau. The results of the experiments show that the proposed model achieves the best performance for predicting railway traffic accidents.