The accuracy of positioning in ultra-wide band (UWB) systems can be improved by identifying the conditions of line-of-sight (LOS) and non-line-of-sight (NLOS) propagation and taking appropriate measures. At present, machine learning methods have already been extensively applied to NLOS identification. Unfortunately, those traditional methods are incapable of performing well in the cases of small samples and class-imbalance samples. In this letter, a novel method is proposed to identify LOS and NLOS components by utilizing Capsule Networks (CapsNet). As indicated by simulation results, the CapsNet-based method allows LOS and NLOS measurements to be classified with 94.63% accuracy, 95.58% precision, 94.74% recall rate, and a 0.9490 F2-score. In addition, CapsNet is compared against decision tree (DT), least squares vector machine (LS-SVM) and K nearest neighbor (KNN) based on experimental data. The comparison results show that the proposed CapsNet outperforms benchmark methods in the cases of both small samples and class-imbalance samples.