September 17, 2026
Clustering of Brazilian Municipalities Based on Public Socioeconomic Indicators
Everton da Silva Moraes; Rafael Henrique Roque
DOI: 10.22167/2675-6528-202602506
Article derived from a Final Course Work (TCC), with content based on the student’s original work and adapted to the editorial format of the Revista E&S with the support of the ResumeAI tool, an artificial intelligence solution developed by the Pecege Institute for textual synthesis and organization.
Summary
A study applied the k-means algorithm to group the 5,570 Brazilian municipalities based on public socioeconomic indicators provided by the Brazilian Institute of Geography and Statistics (IBGE), aiming to support comparative analyses and benchmarking practices in municipal public management. Data from 5,570 municipalities, obtained via the IBGE Application Programming Interface (API), were processed and standardized using the z-score method. 24 variables were organized into six indicator groups: general data, population, education, health, economy, and infrastructure. For each group, the k-means algorithm was executed with k values ranging between 100 and 500, with an increment of five units. The quality of the groupings was evaluated using the Variance Ratio Criterion (VRC), Silhouette Score, Jaccard Index, and Bayesian Information Criterion (BIC), with the results normalized and combined into a weighted score to identify the ideal number of clusters. The results showed distinct grouping patterns among the indicator groups, with the economy group showing greater distinguishing capacity and the population group, less. The final clustering identified general similarities between municipalities, with the best k determined at 100. It was concluded that the clustering technique was viable for identifying similar municipal profiles. The proposed approach demonstrated potential as an analytical tool to support comparison between municipalities and inform planning and decision-making processes in public management.
Keywords: Clusters; IBGE; Socioeconomic indicators; K-means; Validation metrics.
1. Introduction
Brazil is characterized by vast territorial, racial, climatic, and socioeconomic diversity, as widely recognized by official and academic studies (Carmo, 2025). Although this multiplicity confers advantages in different dimensions, such as the diversity of economic activities and a broad consumer market, it has also resulted in heterogeneous and unequal socioeconomic development among the regions, states, and the 5,570 Brazilian municipalities (IBGE, 2022).
In this scenario, a central challenge for municipal public management lies in identifying municipalities with similar socioeconomic profiles, which can serve as a reference for the adoption of best practices. This approach aligns with the concept of benchmarking, which involves the systematic comparison between organizational or territorial units with the aim of identifying improvement opportunities based on successful experiences in analogous contexts (Albertin et al., 2021). The relevance of benchmarking in public management is undeniable, provided that the specificities and local conditions of each territorial unit are considered.
The acquisition of data and information for benchmarking can come from diverse sources, including public data (Albertin et al., 2021). In Brazil, the Brazilian Institute of Geography and Statistics (IBGE) is a primary source, with the Demographic Census (IBGE, 2025) providing detailed socioeconomic indicators on the resident population. However, the mere availability of this data does not resolve the issue of how to compare municipalities with very different socioeconomic realities in a structured and data-driven manner.
To overcome this methodological gap, the clustering technique, or grouping, emerges as a promising analytical tool. It is an unsupervised machine learning method that aims to identify patterns of similarity between objects, grouping them based on their characteristics (Sousa, 2019). Conceptually, more similar elements tend to present smaller distances between themselves in a multidimensional data space, while less similar elements move away, forming distinct groups.
Among clustering techniques, the k-means algorithm stands out for its computational simplicity, efficiency in processing large databases, and wide applicability in socioeconomic and public management studies (Jake, 2025). It operates by partitioning data into a predetermined number of clusters, defining centroids that represent the center of each cluster based on the arithmetic mean of the observations assigned to it, adjusting them iteratively until the algorithm reaches stability.
The application of clustering allows for the organization of municipalities into homogeneous groups, enabling more adequate comparisons and fostering the application of benchmarking, which is justified by the need for an analytical tool to support comparisons between municipalities and subsidize planning and decision-making processes in public management. Given this context, the general objective of the present research was to apply the k-means algorithm to group Brazilian municipalities based on public indicators, in order to identify similar socioeconomic profiles that can support benchmarking practices in public management.
2. Material and Methods
The present research adopted a quantitative methodological approach, of an exploratory nature, focused on the application of unsupervised machine learning techniques. The study was organized in sequential steps: bibliographic survey, data extraction and modeling, clustering development, evaluation of clustering configurations, and finally, the final clustering. The central objective was to group the 5,570 Brazilian municipalities based on public socioeconomic indicators.
The data were collected through Application Programming Interface (API) requests from the Brazilian Institute of Geography and Statistics (IBGE), using official information. The collection focused on socioeconomic indicators for the year 2022. Python programming language was used for data extraction and processing, with libraries such as `pandas` and `requests`.
The extraction stage involved obtaining aggregates and metadata from IBGE for the 2022 period, focusing on N6 locality-level records. For methodology validation, the municipality of Mogi das Cruzes (Locality ID 3530607) was selected, considering its relevance and available data. Initially, 38 representative indicators were selected, sourced from the Demographic Census, Central Register of Enterprises, and Civil Registration Statistical Survey.
In data modeling, the information, originally in JSON format, was converted to a relational model (Banhara et al., 2023; Cardoso et al., 2012). Among the selected indicators, 24 main variables were defined for clustering, being organized into six thematic groups: General Data, Population, Education, Health, Economy, and Infrastructure. The presence of missing values and the existence of different scales among the variables were verified.
The standardization process began with filling in the missing values, using the median of each variable to mitigate the influence of *outliers*. Subsequently, the variables were standardized using the z-score method, employing the `StandardScaler` function from the `scikit-learn` library in Python, resulting in data with a mean of zero and a standard deviation of one (Hair Jr et al., 2009; Silva, 2024).
To avoid redundancies, a Pearson correlation analysis was performed between the standardized variables (Figueiredo Filho and Silva Jr, 2009). Pairs of variables with an absolute correlation greater than 0.99 were identified, and one of the variables in each pair was disregarded for the clustering step.
The clustering was developed using the k-means algorithm, an unsupervised machine learning technique implemented with the `kmeans` function from the `scikit-learn` library (Sousa, 2019; Jake, 2025). For each of the six indicator groups, the algorithm was executed with a number of clusters (k) ranging from 100 to 500, in increments of five units. This procedure aimed to generate feasible groupings for comparative analyses.
The refinement of the clustering included the evaluation of the quality of the groupings through four validation metrics: Variance Ratio Criterion (VRC), Bayesian Information Criterion (BIC), Silhouette Index, and Jaccard Index (Fontana and Naldi, 2009; Naldi, 2011). These metrics were calculated using the `numpy` and `scikit-learn` libraries, and the BIC was determined by a Gaussian Mixture Model (GMM).
The metrics were standardized by min-max normalization, inverting the BIC as it is a minimization metric. To determine the ideal k, distinct weights were assigned to the normalized metrics, based on priorities such as internal affinity, dispersion, and stability. A weighted score was calculated for each k, and the highest score indicated the most suitable k, using `pandas` and `scikit-learn`.
Finally, a “final” clustering of Brazilian municipalities was executed, following the same parameters of k variation (100 to 500, with increments of five units), using the most suitable clusters per indicator group, seeking to identify general patterns of similarity.
3. Results and Discussion
This section details the results obtained from applying the k-means algorithm to group Brazilian municipalities, based on public socioeconomic indicators, and discusses the significance of these findings. The research began with data extraction through Application Programming Interface (API) requests from the Brazilian Institute of Geography and Statistics (IBGE), using the Python programming language. A total of 38 final combinations of variables and classifications were extracted, which were subsequently processed and modeled. Of these, 14 variables were considered auxiliary, while 24 were defined as primary, organized into indicator groups: general data, population, education, health, economy, and infrastructure.
During the data treatment stage, the existence of missing values for some variables in part of the 5,570 analyzed municipalities was verified. Furthermore, it was found that the variables presented distinct scales and ranges, which could distort the clustering results. To mitigate these issues, a standardization process was implemented. Firstly, missing values were filled with the median of the respective variable, a choice justified by the median’s lower sensitivity to extreme values and outliers, common in municipal socioeconomic indicators, ensuring a more robust and less distorted representation of the data.
After filling the gaps, the variables were standardized using the z-score method, which transformed all data to a mean of zero and a standard deviation of one. This step was crucial to ensure that the k-means algorithm did not assign disproportionate weights to variables with different scales, such as territorial area in square kilometers and percentages. Subsequently, a Pearson correlation analysis was performed to identify pairs of variables with high correlations, i.e., above 0.99 or below -0.99. This analysis aimed to mitigate information redundancy and avoid distorting the performance of the clustering algorithm.
From this correlation analysis, it was identified that some variables presented high redundancy. Consequently, the variables VAR_05_PADR, VAR_09_PADR, and VAR_19_PADR were disregarded, which corresponded, respectively, to the percentage of women in the population, the percentage of the rural population, and the average monthly salary in reais of formal workers. This removal was done to optimize the dataset and ensure that each variable contributed more independently to the formation of clusters, improving the quality of subsequent groupings.
With the dataset prepared and standardized, the municipalities were clustered by indicator group. The k-means algorithm was executed for each of the six indicator groups, with the number of clusters (k) ranging from 100 to 500, in increments of five units. This approach allowed for the exploration of different grouping granularities, seeking to identify the most suitable configuration for each set of variables. The quality of the groupings was evaluated using four validation metrics: Variance Ratio Criterion (VRC), Bayesian Information Criterion (BIC), Silhouette Score, and Jaccard Index.
The clustering results for the “General Data” indicator group demonstrated an ability to differentiate municipalities at more aggregated levels. However, this capacity decreased as the number of clusters (k) increased, indicating that the distinction became less evident in more detailed groupings. Initial silhouette criterion values were high but reduced with the increment of k, while the Variance Ratio Criterion (VRC) increased. The BIC, in turn, presented less negative values, suggesting an increase in model complexity without a proportional gain in quality, and the Jaccard Index exhibited moderate variation between 0.3136 and 0.9550, indicating acceptable stability. The best k for this group was determined to be 120.
The “Population” indicator group revealed a low capacity for distinguishing between municipalities. Silhouette criterion values remained low, ranging between 0.2037 and 0.2141, and the Variance Ratio Criterion (VRC) showed little variation across different k values. The Bayesian Information Criterion (BIC) showed an increasing trend, indicating that increasing model complexity did not result in significant improvements in clustering. The Jaccard Index also remained at moderate levels, confirming that there were no significant gains in stability with the increment of k. For this group, the best k was identified at 115.
In contrast, the “Education” indicator group demonstrated good discriminatory capacity. The silhouette criterion presented moderate values, with a slight upward trend as k increased, suggesting an improvement in the separation between clusters. The Variance Ratio Criterion (VRC) also followed this consistent growth behavior, indicating an increase in differentiation between groups. The Bayesian Information Criterion (BIC) showed a relative improvement, with less negative values, pointing to a reasonable balance between fit and complexity. The Jaccard Index remained at moderate levels, with some elevated points, indicating consistent stability in the groupings. The best k for this group was 495.
The “Health” indicator group proved to have differentiation capacity, albeit limited. The silhouette criterion presented intermediate values, between 0.2491 and 0.2747, indicating a moderate separation of clusters. The Variance Ratio Criterion (VRC) remained relatively stable, while the Bayesian Information Criterion (BIC) showed an increasing trend, suggesting an increase in model complexity without significant quality gains. The Jaccard Index also presented moderate values, confirming acceptable stability of the groupings, but without major advances in distinction. The best k for this group was 465.
The “Economy” indicator group stood out for its strong distinguishing capacity, being one of the most relevant groups for clustering. The silhouette criterion showed higher values, indicating good separation between clusters. The Variance Ratio Criterion (VRC) showed an increasing trend, and the Bayesian Information Criterion (BIC) values were progressively better, i.e., less negative, suggesting an optimal balance between separation and model fit. Furthermore, the Jaccard Index showed high values at several points, indicating high cluster stability. The best k for this group was 380.
Finally, the “Infrastructure” indicator group showed a behavior similar to the “Education” group. The observed differentiation occurred more due to an internal reorganization of the groups than an effective separation between them. The silhouette criterion was moderate, the Variance Ratio Criterion (VRC) decreased, and the Bayesian Information Criterion (BIC) increased with the increment of k, confirming that there was no significant improvement in the separation between clusters. The Jaccard Index presented moderate levels, proving stability, but without relevant structural gains. The best k for this group was 480.
After the individual analysis of the indicator groups, a final clustering was performed using all the main variables, with the k-means algorithm executed again for k values between 100 and 500, with an increment of five units. This final clustering managed to capture general patterns of similarity between the municipalities, but with limitations for very granular analyses. The interpretation of the clusters should be understood as an approximation of similarity, and not as rigidly defined segmentations, which is corroborated by the values of the validation metrics.
The silhouette criteria for the final clustering showed low values, ranging from 0.1501 to 0.1589, indicating a moderate to low separation between clusters. The Variance Ratio Criterion (VRC) showed a decreasing trend with the increment of k, evidencing a drop in the differentiation capacity between clusters. The Bayesian Information Criterion (BIC) showed an increasing trend, indicating that more complex models did not result in better fits. The Jaccard Index, in turn, remained at moderate levels, suggesting consistent stability of the groupings.
Based on the calculation of the weighted score of the validation metrics, the best k for the final clustering was determined to be 100. This k value indicates the best balance between the internal cohesion of the clusters, the separation between them, and the model’s complexity, avoiding excessive grouping that could lead to unnecessary data fragmentation. The Variance Ratio Criterion (VRC) of 430.369, although it does not have a fixed ideal value, suggests good differentiation between groups compared to other k values.
The Bayesian Information Criterion (BIC) of 400.479 for k=100 indicates an adequate level of model complexity compared to the other configurations tested, as lower BIC values are preferable. The Silhouette Criterion of 0.158933, which ranges from -1 to 1, points to low separation, a value below 0.2. However, this value is considered acceptable given the continuous nature and high complexity of the socioeconomic data analyzed. The Jaccard Index was not applicable for the first k analyzed, as it is used to compare the stability of clusters in different runs.
In summary, the results demonstrate the viability of applying the k-means algorithm to group the 5,570 Brazilian municipalities based on public socioeconomic indicators. The clustering by indicator groups revealed distinct patterns of distinction capacity, with the Economy group showing the highest and the Population group the lowest. The final clustering, with an ideal k of 100, allowed for the identification of similar municipal profiles, providing a promising analytical tool to support comparative analyses and benchmarking practices in public management, despite the limitations inherent in the nature of the data and the algorithm’s sensitivity.
4. Conclusion
The study applied the k-means algorithm to group the 5,570 Brazilian municipalities based on public socioeconomic indicators, seeking to identify similar profiles that could support benchmarking practices in public management. The viability of the clustering technique to organize the municipalities was verified, using 24 variables distributed in six indicator groups. The results showed distinct grouping patterns among the groups, with the Economy group presenting greater distinction capacity and the Population group, lower. The final clustering, with the best k determined at 100, allowed for the identification of general similarities between the municipalities. Although the silhouette criterion indicated a moderate to low separation between clusters, this value was considered acceptable given the complexity of the socioeconomic data, and the Variance Ratio and Bayesian Information Criterion metrics corroborated an adequate balance between cohesion and model complexity.
The main contribution of this study lies in the proposition of an analytical tool to support comparative analyses and benchmarking practices in municipal public management, subsidizing planning and decision-making processes. However, the work acknowledges limitations inherent in the use of public data, which may be subject to differences in updating and possible underreporting. The sensitivity of the k-means algorithm to the choice of the number of clusters (k) and the use of Euclidean distance in socioeconomic data also represent aspects that demand consideration. For future studies, it is suggested to apply the methodology with updated data and explore other distance metrics or clustering algorithms to refine the identification of municipal profiles.
Bibliographic References
Albertin, M.R.; Elias, S.J.B.; JR., Dmontier P. A. 2021. Benchmarking Para Um Desempenho Superior. Editora Alta Books, Rio de Janeiro, RJ, Brasil. Disponível em: https://app.minhabiblioteca.com.br/reader/books/9786555201635. Acesso em: 04 out. 2025.
Banhara, N.; Duarte, D.; Schreiner, G. 2023. Extração de Esquemas de Documentos JSON: O que há de Novo?. In: Anais da XVIII Escola Regional de Banco de Dados, 2023, Palmas, PR, Brasil. Anais… p. 11-20
Cardoso, G.C..; Cardoso, V.M. 2012. Sistemas de Banco de Dados, 1ª Edição. Saraiva, Rio de Janeiro, RJ, Brasil. Disponível em: https://app.minhabiblioteca.com.br/reader/books/9788502162839. Acesso em: 07 out. 2025.
Carmo, N. C.; Nunes, F G.; Santos, A. M. 2025. Território, Sociedade e Desigualdade: Uma Revisão de Literatura. Revista Verde Grande: Geografia E Interdisciplinaridade 6(01): 31-51.
Figueiredo Filho, D. B.; Silva Jr. J. A. 2009. Desvendando os Mistérios do Coeficiente de Correlação de Pearson (r), Revista Política Hoje 18(01): 115-146
Fontana, A.; Naldi, M.C. 2009. Estudo e Comparação de Métodos para Estimação de Números de Grupos em Problemas de Agrupamento de Dados. Disponível em: https://web.icmc.usp.br/SCATUSU/RT/Relatorios_Tecnicos/BIBLIOTECA_113_RT_340.pdf. Acesso em 12 out. 2025.
Hair Jr., Joseph F.; Black, William C.; Babin, Barry J.; et al. 2009. Análise multivariada de dados. 6. ed. Bookman, Porto Alegre, RS, Brasil. Disponível em: https://app.minhabiblioteca.com.br/reader/books/9788577805341. Acesso em: 08 out. 2025.
Instituto Brasileiro de Geografia e Estatística [IBGE]. 2023. Cidades e Estados do Brasil: Mogi das Cruzes (SP). Disponível em: https://cidades.ibge.gov.br/brasil/sp/mogi-das-cruzes/panorama. Acesso em: 02 out 2025
Instituto Brasileiro de Geografia e Estatística [IBGE]. 2025. Censo Demográfico 2022: Unidades de conservação: principais características das pessoas residentes e dos domicílios, por recortes territoriais e grupos populacionais específicos: resultados do universo. Disponível em: https://biblioteca.ibge.gov.br/visualizacao/livros/liv102192.pdf, Acesso em: 04 out 2025
Jake, V. 2025. Guia Do Python para Data Science – Tradução da Segunda Edição: ferramentas essenciais para trabalhar com dados. Alta Books, Rio de Janeiro, RJ, Brasil. Disponível em: https://app.minhabiblioteca.com.br/reader/books/9788550821795/. Acesso em: 12 out. 2025.
Naldi, C. M. 2011, Técnicas de combinação para agrupamento centralizado e distribuídos de dados. Tese de Doutorado em Ciências da Computação, Instituto de Ciências Matemáticas de Computação – ICMC-USP, São Carlos, SP, Brasil
Silva, E. N. 2024. Aplicação de aprendizado de máquina na identificação de reações de pragas a compostos semioquímicos. Trabalho de Conclusão de Curso de Bacharelado em Ciência da Computação. Universidade Federal de Alagoas, Maceió, AL, Brasil.
Sousa, M.C. C. 2019. Uma análise do algoritmo k-means como introdução ao aprendizado de máquinas. Trabalho de Conclusão de Curso do Curso de Matemática. Universidade Federal do Tocantis, Araguaína, TO, Brasil.
Article originating from the Course Conclusion Work of the Specialization in Data Science and Analytics of the MBA USP/Esalq
To learn more about the course, click here and access the MBX Academy platform