This paper analyzes the factors affecting the happiness of smart city residents, uses principal component analysis method and random forest method, and uses SPSS, SPSSPRO and other software to analyze and process the data. First, it establishes the evaluation index of the happiness of smart city residents, and then evaluates the measures that can improve the happiness of residents in the construction of smart city. Finally, reasonable development suggestions for the construction of smart cities are put forward through forecasting and processing. Research background and theoretical literature. Find out the relevant theoretical basis, and finally determine the reasonable research method. The index of resident happiness is designed from the perspective of smart economic happiness, smart political happiness, smart public service happiness, smart security management happiness, and smart ecological environment happiness, and is used as the index factor of principal component analysis. The model of influencing urban residents' happiness under smart city. According to the resident data, the principal component analysis method is constructed, and then the random forest model is used to test, and finally the weight of the influencing factors of residents' happiness under the smart city is obtained.