The prediction of slope stability is considered as one of the critical concerns in geotechnical engineering. Conventional stochastic analysis with spatially variable slopes is time-consuming and highly computation-demanding. To assess the slope stability problems with a more desirable computational effort, many machine learning (ML) algorithms have been proposed. However, most ML-based techniques require that the training data must be in the same feature space and have the same distribution, and the model may need to be rebuilt when the spatial distribution changes. This paper presents a new ML-based algorithm, which combines the principal component analysis (PCA)-based neural network (NN) and transfer learning (TL) techniques (i.e. PCA–NN–TL) to conduct the stability analysis of slopes with different spatial distributions. The Monte Carlo coupled with finite element simulation is first conducted for data acquisition considering the spatial variability of cohesive strength or friction angle of soils from eight slopes with the same geometry. The PCA method is incorporated into the neural network algorithm (i.e. PCA-NN) to increase the computational efficiency by reducing the input variables. It is found that the PCA-NN algorithm performs well in improving the prediction of slope stability for a given slope in terms of the computational accuracy and computational effort when compared with the other two algorithms (i.e. NN and decision trees, DT). Furthermore, the PCA–NN–TL algorithm shows great potential in assessing the stability of slope even with fewer training data.