Addressing the problems of manual dependence and low accuracy of traditional building electrical system fault diagnosis, this paper proposes a novel method, which is based on random forest optimized by improved sparrow search algorithm (ISSA-RF). Firstly, the method utilizes a fault collection platform to acquire raw signals of various faults. Secondly, the features of these signals are extracted by time-domain and frequency-domain analysis. Furthermore, principal component analysis (PCA) is employed to reduce the dimensionality of the extracted features. Finally, the reduced features are input into ISSA-RF for classification. In ISSA-RF, the improved sparrow algorithm (ISSA) is used to optimize the parameters of the random forest (RF). The parameters for ISSA optimization are n_estimators and min_samples_leaf. In this case, the accuracy of the proposed method can reach 98.61% through validation experiment. In addition, the proposed method also exhibits superior performance compared with traditional fault classification algorithms and the latest building electrical fault diagnosis algorithms.