Accurate classification of soil types and contamination is crucial for crops' productivity. Among the soil analysis techniques, laser-induced breakdown spectroscopy (LIBS) has become a prominent technology for real-time characterization of soil properties. LIBS coupled with supervised machine learning and chemometrics methods (e.g., partial least squares discriminate analysis (PLS-DA), principal component analysis (PCA)) has demonstrated great capabilities for soils classification. However, when the training and test spectra have different distribution and not representative of each other, there are generalization issues, which make the model trained on training spectra hard to adapt to test spectra. In this work we propose a method to calibrate the test spectra using the median of principal components (PCs). PCA is used to analyze the spectra distribution. We independently compute the median of both training's and test's PCs, and then the test's median is adjusted based on its differences with training's. With the calibrated PCs, the test spectra is reconstructed accordingly. To test the performance of the proposed calibration algorithm, we conduct experiments on a publicly available challenging LIBS dataset. We compare our calibration algorithm with the current best performing calibration method on the same test set, using the same machine learning (ML) algorithm, PLS-DA, trained with the same training set. Our method improves the test accuracy by 1.2%. The reason using PLS-DA for performance comparison is that it is currently the best performing ML algorithm. To further improve the test accuracy, other ML algorithms are investigated. Convolutional neural networks (CNN) have achieved good accuracy in lithological classification with LIBS recently. Therefore, it is extended in this work to soil classification. We use CNN as a tool for feature extraction and as an end-to-end classifier. We use the CNN based extraction mechanism with other classifiers, such as support vector machine (SVM) and random forest (RF), for soil classification. The performance of CNN models on the calibrated test spectra is compared, which concludes that CNN combined with SVM achieves the best accuracy and improves the test accuracy by 3.1% compared to the best performing ML algorithm PLS-DA.