For detecting changes in air composition, the traditional method based on measuring the speed of sound lacks selectivity for different gaseous species and is easily influenced by environmental effects such as pressure, humidity, and temperature. Additionally, this method is difficult to be used for the quantitative analysis of air mixed with an unknown gas. In this paper, a data-driven model is developed for detecting changes in air composition from a qualitative perspective. By comparing the measured speed of sound with that theoretically calculated using the virial expansion for real air, the precise differences are used as data to construct a distance matrix, then the most typical speed difference is identified in order to calculate the z-score, from which the one-sided p-value (which is the probability of the z-score from a normal distribution) is calculated to detect a change in air composition at a given significance level. Experimental results show that the proposed data-driven model can accurately locate the time of change and determine the change intervals for air composition variations, and it has better accuracy and a lower value of RFT, almost equal to zero, compared with methods such as quartiles, standard deviation, interquartile range, and Bayesian detection and thus can be applied to domestic and industrial sensors for air monitoring, gas detection, and gas pollution alarms.