<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thiago Silva on Medium]]></title>
        <description><![CDATA[Stories by Thiago Silva on Medium]]></description>
        <link>https://medium.com/@thiagossilva17?source=rss-1e776b0a0adb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VNTPUY1qc4WRdtePiFBcqQ.png</url>
            <title>Stories by Thiago Silva on Medium</title>
            <link>https://medium.com/@thiagossilva17?source=rss-1e776b0a0adb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 16:57:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thiagossilva17/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Segmentation of soccer players with Machine Learning K Means algorithm.]]></title>
            <link>https://medium.com/@thiagossilva17/segmentation-of-soccer-players-with-machine-learning-k-means-algorithm-fcab9acf6482?source=rss-1e776b0a0adb------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcab9acf6482</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[k-means]]></category>
            <category><![CDATA[football]]></category>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Thiago Silva]]></dc:creator>
            <pubDate>Tue, 01 Nov 2022 01:05:16 GMT</pubDate>
            <atom:updated>2022-11-01T01:05:16.971Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will show you how to segment the players of the Brazilian football championship of the 2022 season with the Machine Learning K-means algorithm.</p><p><strong>What is the purpose of this work?</strong></p><p>The objective is to apply the Machine Learning K-means algorithm to build a clustering model capable of segmenting players based on their real performance statistics, distinguishing offensive, defensive and goalkeeper athletes, in addition to the possible identification of national football talents, showing better performances and other insights.</p><p><strong>What is the data source?</strong></p><p>For this work, we will use the APIs of the Fotmob and Transfermarkt sites to obtain the data through the R language. It is worth mentioning that at the time of publishing this article, the 2022 Brazilian football championship is still in progress, so this model will take into account the data available until the 34th round, it is also worth mentioning that the APIs used to extract the data are updated every round, so if you choose a new one extraction, you may get results that differ from the results presented here.</p><p>If you want to obtain exactly the same result as this publication, you can access my <a href="https://github.com/thiagossilva17"><strong>GitHub</strong></a> in repository <a href="https://github.com/thiagossilva17/Project-5---Segmentation-of-Brazilian-league-players"><strong>“Project-5 — -Segmentation-of-Brazilian-league-players”</strong></a>, access the “data” folder, and download the bases used when creating this model. To extract other football data, go to my profile here on Medium and read my first article on <a href="https://medium.com/@thiagossilva17/how-to-extract-football-databases-by-apis-using-the-r-language-5a45f4c61079"><strong>how to extract football databases by APIs using the R language.</strong></a></p><p><strong>Which variables will be used in this work?</strong></p><p>Age, position, games played, minutes played, goals, assists, chances created, great chances created, long passing accuracy, short passing accuracy, shots out, shots on goal, dribbles made with success; penalties taken, penalties conceded, blocks, tackles, interceptions, ball possession gained in the final third of the field, defenses, percentage of defenses, yellow cards, red cards, and other variables created based on these variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wDmLv6lx-XOBryQgOlm5Qg.png" /></figure><p><strong>What software is needed for this process?</strong></p><p>The <a href="https://cran.r-project.org/bin/windows/base/">R language</a> and the <a href="https://www.rstudio.com/">Rstudio IDE</a> will be used to obtain, process, model, and visualize the data.</p><p><strong>Preparing environment for extracts and model creation:</strong></p><p>For the preparation and organization of the data, it will be necessary to install and load the libraries below, according to the code:</p><blockquote>install.packages(“worldfootballR”)<br>library(worldfootballR)<br>install.packages(“dply”)<br>library(dplyr)<br>install.packages(“tidyr”)<br>library(tidyr)<br>install.packages(“stringr”)<br>library(stringr)<br>install.packages(“tm”)<br>library(tm)<br>install.packages(“stringi”)<br>library(stringi)<br>install.packages(“xlsx”)<br>library(xlsx)<br>install.packages(“ggplot2”)<br>library(ggplot2)<br>install.packages(“caret”)<br>library(caret)<br>install.packages(“factoextra”)<br>library(factoextra)<br>install.packages(“gridExtra”)<br>library(gridExtra)</blockquote><p>After installing and loading the packages, we will start by extracting player-level performance data from the FotMob API and remodeling the arrangement of the base in order to have the statistics arranged by columns, a suitable format for the application of the K-means algorithm, can be done as follows:</p><blockquote># HOME — EXTRACTION OF PERFORMANCE DATA FROM THE FOTMOB API AND DATA REMODELING<br>PERFORMANCE_DATA &lt;- fotmob_get_season_stats(<br> country = “BRA”,<br> league_name = “Serie A”,<br> season = “2022”,<br> stat_name = c(“Chances created”, “Big chances created”,”Big chances missed”, “Accurate long balls per 90”, “Accurate passes per 90”,”Shots per 90&quot;,”Shots on target per 90&quot;, “Goals per 90”, “Assists”, “Goals + Assists”,”Successful dribbles per 90&quot;,”Successful tackles per 90&quot;,”Penalties won”,”Penalties conceded”,”Blocks per 90&quot;,”Clean sheets”,”Clearances per 90&quot;,”Fouls committed per 90&quot;,”Goals conceded per 90&quot;,”Interceptions per 90&quot;,”Possession won final 3rd per 90&quot;,”Save percentage”,”Saves per 90&quot;,”Top scorer”,”Yellow cards”,”Red cards”),<br> team_or_player = “player”<br>)</blockquote><blockquote>#separating descriptive variables for base remodeling<br>df_desc &lt;- PERFORMANCE_DATA %&gt;% select(10,9,11,16,15,20)<br>df_desc &lt;- unique(df_desc)</blockquote><blockquote>PERFORMANCE_DATA&lt;- PERFORMANCE_DATA %&gt;% select(10,7,13)<br>PERFORMANCE_DATA &lt;- PERFORMANCE_DATA %&gt;% pivot_wider(names_from = stat_name, values_from = stat_value)<br>#Replacing NA values with 0<br>PERFORMANCE_DATA &lt;- PERFORMANCE_DATA %&gt;%<br> replace(is.na(.), 0)<br>#returning descriptive variables to the main base, after remodeling<br>PERFORMANCE_DATA &lt;- left_join(PERFORMANCE_DATA, df_desc, by=”particiant_id”)</blockquote><p>In the next step, we will use the Transfermarkt API to get information related to the age and position of players.</p><blockquote># EXTRACTING AGE AND POSITION DATA FROM TRANSFERMARKT API<br>#PREPARATION<br>TRANSFERMARKT_DATA &lt;- tm_squad_stats(team_url = c(“<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/1023/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/1023/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/614/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/614/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/199/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/199/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/6600/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/6600/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/2462/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/2462/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/679/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/679/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/330/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/330/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/2863/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/2863/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/3197/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/3197/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/221/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/221/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/8793/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/8793/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/10870/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/10870/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/537/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/537/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/585/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/585/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/2029/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/2029/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/28022/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/28022/saison_id/2022</a>&quot;, “<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/776/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/776/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/2035/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/2035/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/15172/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/15172/saison_id/2022</a>&quot;,&quot;<a href="https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/10492/saison_id/2022">https://www.transfermarkt.com/se-palmeiras-sao-paulo/startseite/verein/10492/saison_id/2022</a>&quot;))<br>names(TRANSFERMARKT_DATA)[1] &lt;- “team_name_transfermarkt”<br>TRANSFERMARKT_DATA &lt;- TRANSFERMARKT_DATA %&gt;% select(1,4,6,7,8)</blockquote><p>To unite the bases, it is worth mentioning that there is no “ID” field that relates the players between the two APIs, so it will be necessary to make this crossing directly by the name of the athletes,<br>but many players have the same names, so to differentiate them we will concatenate the player’s name with the team name, but first, text mining techniques will be applied to<br>remove accents, punctuation and standardize all of them with capital letters, in order to have the least difference in writing between the two bases. (Note that there were only 2 players on the same team with the same, and these were corrected later on).</p><blockquote>#Mining texts from the Transfermarkt database<br>#Removing punctuation from all base names<br>TRANSFERMARKT_DATA$player_name &lt;- apply(TRANSFERMARKT_DATA[,2,drop=F],2, removePunctuation)<br>#Converting names to capital letters<br>TRANSFERMARKT_DATA$player_name &lt;- apply(TRANSFERMARKT_DATA[,2,drop=F],2, toupper)<br>#Converting column type to character<br>TRANSFERMARKT_DATA$player_name&lt;- as.character(TRANSFERMARKT_DATA$player_name)<br># Removing accents from names<br>TRANSFERMARKT_DATA$player_name &lt;- stri_trans_general(TRANSFERMARKT_DATA$player_name,id=”Latin-ASCII”)</blockquote><blockquote>#Mining texts from Fotmob base<br># Removing punctuation from all base names<br>PERFORMANCE_DATA$participant_name &lt;- apply(PERFORMANCE_DATA[,28,drop=F],2, removePunctuation)<br>#Converting column type to character<br>PERFORMANCE_DATA$participant_name&lt;- as.character(PERFORMANCE_DATA$participant_name)<br># Converting names to capital letters<br>PERFORMANCE_DATA$participant_name &lt;- apply(PERFORMANCE_DATA[,28,drop=F],2, toupper)<br># Removing accents from names<br>PERFORMANCE_DATA$participant_name &lt;- stri_trans_general(PERFORMANCE_DATA$participant_name,id=”Latin-ASCII”)</blockquote><blockquote>#CREATING FROM/TO TO STANDARDIZE THE NAMES OF THE TWO APIs’ TEAM.<br>team_name_fotmob &lt;- c(“Palmeiras”,”Ceará”,”Bragantino”,”Fluminense”,”Atlético Mineiro”,”Internacional”,”Flamengo”,”São Paulo”,”América Mineiro”,”Cuiabá”,”Atlético Goianiense”,”Coritiba”,”Fortaleza EC”,”Botafogo”,”Avaí”,”Santos”,”Goiás”,”Atlético Paranaense”,”Juventude”,”Corinthians”)<br>team_name_transfermarkt &lt;- c(“Sociedade Esportiva Palmeiras”,”Ceará Sporting Club”,”Red Bull Bragantino”,”Fluminense Football Club”,”Clube Atlético Mineiro”,”Sport Club Internacional”,<br> “Clube de Regatas do Flamengo”,”São Paulo Futebol Clube”,”América Futebol Clube (MG)”,”Cuiabá Esporte Clube (MT)”,”Atlético Clube Goianiense”,”Coritiba Foot Ball Club”,”Fortaleza Esporte Clube”,”Botafogo de Futebol e Regatas”,”Avaí Futebol Clube (SC)”,”Santos FC”,”Goiás Esporte Clube”,”Club Athletico Paranaense”,”Esporte Clube Juventude”,”Sport Club Corinthians Paulista”)<br>team_names &lt;- data.frame(team_name_fotmob, team_name_transfermarkt)<br>TRANSFERMARKT_DATA$team_name_DEPARA &lt;- left_join(TRANSFERMARKT_DATA, team_names, by=”team_name_transfermarkt”)<br>TRANSFERMARKT_DATA$team_name_DEPARA &lt;- TRANSFERMARKT_DATA$team_name_DEPARA$team_name_fotmob</blockquote><blockquote>#CONCATENTING PLAYER NAME WITH TEAM NAME FOR BOTH BASES<br>TRANSFERMARKT_DATA$concatenado &lt;- paste(TRANSFERMARKT_DATA$player_name,”_”,TRANSFERMARKT_DATA$team_name_DEPARA)<br>PERFORMANCE_DATA$concatenado &lt;- paste(PERFORMANCE_DATA$participant_name,”_”,PERFORMANCE_DATA$team_name)</blockquote><p>Even with the treatment, some relatively important athletes could not be identified, such as Corinthians owner Eduardo Queiroz who is one of the APIs registered as “DU QUEIROZ” (Your nickname), in this context, I will manually correct some players that I do not want to take into account in the analysis and are relatively important in the Brazilian football scene.</p><blockquote>#CORRECTING NOMENCLATURE OF ATHLETES WITH DIFFERENT REGISTRATIONS<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”RONI _ Palmeiras”,”RONY _ Palmeiras”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”MURILO CERQUEIRA _ Palmeiras”,”MURILO _ Palmeiras”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”JOSE LOPEZ _ Palmeiras”,”JOSE MANUEL LOPEZ _ Palmeiras”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”LUAN GARCIA _ Palmeiras”,”LUAN _ Palmeiras”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”LUCIANO NEVES _ São Paulo”,”LUCIANO _ São Paulo”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”DIEGO _ São Paulo”,”DIEGO COSTA _ São Paulo”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”SANDRY SANTOS _ Santos”,”SANDRY _ Santos”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”PAULO GANSO _ Fluminense”,”GANSO _ Fluminense”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”VIKTOR HUGO _ Flamengo”,”VICTOR HUGO _ Flamengo”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”RAUL _ Corinthians”,”RAUL GUSTAVO _ Corinthians”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”EDUARDO QUEIROZ _ Corinthians”,”DU QUEIROZ _ Corinthians”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”RAMIRES _ Bragantino”,”ERIC RAMIRES _ Bragantino”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”ARTUR GUIMARAES _ Bragantino”,”ARTUR _ Bragantino”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”VICTOR LEANDRO CUESTA _ Botafogo”,”VICTOR CUESTA _ Botafogo”)<br>PERFORMANCE_DATA$concatenado &lt;- str_replace(PERFORMANCE_DATA$concatenado,”RODRIGUINHO _ América Mineiro”,”RODRIGUINHO _ Cuiabá”)</blockquote><p>It is worth remembering that the APIs are updated every round, so with each new query request, there will be variations in the data, such as players<br>who have contractually left their teams or were bought/sold on the international transfer market, so there will be no universal treatment that<br>solve all the specific cases of the base.</p><p>We continue with the union of the bases:</p><blockquote>#UNITING BASES<br>PERFORMANCE_DATA &lt;- left_join(PERFORMANCE_DATA, TRANSFERMARKT_DATA, by=”concatenado”)</blockquote><blockquote>#Checking number of baselines<br>nrow(PERFORMANCE_DATA)<br>#Percentage of NAS values in each column<br>NAS &lt;- round(colSums(is.na(PERFORMANCE_DATA))*100/nrow(PERFORMANCE_DATA), 2)<br>#SEE ALL NAS<br>NAS</blockquote><p>In the Ceará team, there were two players with names Richards, when crossing with the Transfermarkt API concatenating the athlete’s name with the name of the club, there was a repetition due to them having the same name, at this moment, we removed this repetition.</p><blockquote>#removing special case richard ceara, player with exactly the same name on the same team<br>PERFORMANCE_DATA$Exclude &lt;- ifelse(PERFORMANCE_DATA$particiant_id == 934515 &amp; PERFORMANCE_DATA$player_pos == ‘Defensive Midfield’ | PERFORMANCE_DATA$particiant_id == 882625 &amp; PERFORMANCE_DATA$player_pos == ‘Goalkeeper’,1,0)<br>PERFORMANCE_DATA &lt;- filter(PERFORMANCE_DATA, Exclude != 1)<br>PERFORMANCE_DATA$Exclude &lt;- NULL</blockquote><blockquote># Removing NA values<br>PERFORMANCE_DATA&lt;- na.omit(PERFORMANCE_DATA)<br># Checking number of lines remaining<br>nrow(PERFORMANCE_DATA)</blockquote><p>After the treatments above, we went from 45.32% missing data to 27.42%, that is, the methods were effective and helped us to recover <strong>113 athletes</strong> (<strong>17.9%</strong> of base athletes). In case of a replica of this work, you can evaluate and include changes from other athletes so that the model takes them into account too, the other players not found at the intersection are due to the fact that they are no longer active in Brazilian football, the vast majority of these were sold to football international or for other divisions of Brazilian football, so these will not be relevant to the study and will be disregarded from the base. Right now, we are left with 469 players on base.</p><p>The next step will be the creation of new variables that will provide us with more insights and help to better segment groups of different performances.</p><p>We will create a field zone variable, this will determine based on the specific position variable if the athlete acts in the attack, midfield, defense or as a goalkeeper.</p><blockquote>#Creating field zone variable<br>PERFORMANCE_DATA$Zone &lt;- ifelse(PERFORMANCE_DATA$player_pos == “Right Winger” | PERFORMANCE_DATA$player_pos == “Left Winger” | PERFORMANCE_DATA$player_pos == “Centre-Forward” | PERFORMANCE_DATA$player_pos == “Second Striker”, “Attacker”,<br> ifelse(PERFORMANCE_DATA$player_pos == “Attacking Midfield” | PERFORMANCE_DATA$player_pos == “Central Midfield” | PERFORMANCE_DATA$player_pos == “Defensive Midfield” | PERFORMANCE_DATA$player_pos == “Left Midfield” | PERFORMANCE_DATA$player_pos == “Right Midfield”, “Midfield”,<br> ifelse(PERFORMANCE_DATA$player_pos == “Right-Back” | PERFORMANCE_DATA$player_pos == “Left-Back” | PERFORMANCE_DATA$player_pos == “Centre-Back”, “Defender”,<br> “Goalkeeper”)))<br>PERFORMANCE_DATA &lt;- PERFORMANCE_DATA %&gt;% select(1,28,29,32:35,38,36,39,40,30:31,37,2:27)</blockquote><p>The field zone will be entered as a dummy variable in this case and the goalkeepers will be assumed as a control category where they will be classified as 0 in all these variables.</p><blockquote>#GOALKEEPERS ARE BEING REPRESENTED AS CONTROL CATEGORIES, WHERE IT IS THE ONLY POSITION CLASSIFIED WITH 0 IN ALL DUMMIES VARIABLES<br>PERFORMANCE_DATA$Dummie_position &lt;- PERFORMANCE_DATA$player_pos<br>#TRANSFORMING DUMMIES<br>PERFORMANCE_DATA$Dummie &lt;- 1<br>PERFORMANCE_DATA &lt;- PERFORMANCE_DATA %&gt;% pivot_wider(names_from = Dummie_position, values_from = Dummie)<br>PERFORMANCE_DATA&lt;- PERFORMANCE_DATA %&gt;%<br> mutate_if(is.numeric, funs(ifelse(is.na(.), 0, .)))<br>PERFORMANCE_DATA$Goalkeeper &lt;- NULL</blockquote><p>The Starting Player variable will determine that athletes with an average playing time of more than 45 minutes per match will be considered starters.</p><blockquote>#CONSIDERING PLAYERS WHO ACT ON AVERAGE MORE THAN 45 MIN AS OWNERS<br>PERFORMANCE_DATA$AVG_time &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$matches_played,0)<br>PERFORMANCE_DATA$starting_player &lt;- ifelse(PERFORMANCE_DATA$AVG_time &gt; 45 ,1,0)</blockquote><p>Creating dummies for the field zone variable, here the goalkeepers will also be the control group.</p><blockquote>#GOALKEEPERS ARE BEING REPRESENTED AS CONTROL CATEGORIES BY SETTING THE POSITION ZONES BELOW, WHERE THEY ARE THE ONLY ZONE RATED WITH 0 IN ALL DUMMIES VARIABLES<br>PERFORMANCE_DATA$Attacking &lt;- ifelse(PERFORMANCE_DATA$`Right Winger` == 1 | PERFORMANCE_DATA$`Left Winger` == 1 | PERFORMANCE_DATA$`Centre-Forward` == 1 | PERFORMANCE_DATA$`Second Striker` == 1, 1, 0)<br>PERFORMANCE_DATA$Midfield &lt;- ifelse(PERFORMANCE_DATA$`Attacking Midfield` == 1 | PERFORMANCE_DATA$`Central Midfield` == 1 | PERFORMANCE_DATA$`Defensive Midfield` == 1 | PERFORMANCE_DATA$`Left Midfield` == 1, 1, 0)<br>PERFORMANCE_DATA$Defender &lt;- ifelse(PERFORMANCE_DATA$`Right-Back` == 1 | PERFORMANCE_DATA$`Left-Back` == 1 | PERFORMANCE_DATA$`Centre-Back` == 1 , 1, 0)</blockquote><p>Some of the variables provided by the FotMob API were divided by 90 min (the time of a football match), at this moment I do the inverse calculation to get the real statistics of these variables.</p><blockquote>#Creating variables for better group segmentation and greater analysis power<br>PERFORMANCE_DATA$Matches_90min_played &lt;- round(PERFORMANCE_DATA$minutes_played/90,2)<br>PERFORMANCE_DATA$Big_chances_created_per_match &lt;- round(PERFORMANCE_DATA$`Big chances created` / PERFORMANCE_DATA$matches_played,2)<br>PERFORMANCE_DATA$Chances_created_per_match &lt;- round(PERFORMANCE_DATA$`Chances created` / PERFORMANCE_DATA$matches_played,2)<br>PERFORMANCE_DATA$Big_chances_missed_per_match &lt;- round(PERFORMANCE_DATA$`Big chances missed` / PERFORMANCE_DATA$matches_played, 2)<br>PERFORMANCE_DATA$Goals_Assists_per_match &lt;- round(PERFORMANCE_DATA$`Goals + Assists` / PERFORMANCE_DATA$matches_played,2)<br>PERFORMANCE_DATA$Successful_dribbles &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Successful dribbles per 90`)<br>PERFORMANCE_DATA$Disarms &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Successful tackles per 90`)<br>PERFORMANCE_DATA$Shots &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Shots per 90`)<br>PERFORMANCE_DATA$Shots_on_target &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Shots on target per 90`)<br>PERFORMANCE_DATA$Blocks &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Blocks per 90`)<br>PERFORMANCE_DATA$Fouls_committed &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Fouls committed per 90`)<br>PERFORMANCE_DATA$Goals_conceded &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Goals conceded per 90`)<br>PERFORMANCE_DATA$Clearances &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Clearances per 90`)<br>PERFORMANCE_DATA$Interceptions &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Interceptions per 90`)<br>PERFORMANCE_DATA$Possession_won_final_3rd &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Possession won final 3rd per 90`)<br>PERFORMANCE_DATA$Saves &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Saves per 90`)<br>PERFORMANCE_DATA$Accurate_long_balls &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Accurate long balls per 90`)<br>PERFORMANCE_DATA$Accurate_passes &lt;- round(PERFORMANCE_DATA$Matches_90min_played * PERFORMANCE_DATA$`Accurate passes per 90`)<br>PERFORMANCE_DATA$Sum_yellow_red_cards &lt;- PERFORMANCE_DATA$`Yellow cards` + PERFORMANCE_DATA$`Red cards`<br>PERFORMANCE_DATA$Sum_Disarms_Blocks_Intercep &lt;- PERFORMANCE_DATA$Disarms + PERFORMANCE_DATA$Blocks + PERFORMANCE_DATA$Interceptions<br>PERFORMANCE_DATA$Big_chances_created_per_assists &lt;- PERFORMANCE_DATA$`Big chances created` / PERFORMANCE_DATA$Assists<br>PERFORMANCE_DATA$Shots_on_target_per_goals &lt;- PERFORMANCE_DATA$Shots_on_target / PERFORMANCE_DATA$`Top scorer`</blockquote><p>To enrich our model and analysis, I then create variables dependent on the timing of each athlete.</p><blockquote>#Creating variables to explore timing data<br>PERFORMANCE_DATA$Minutes_for_Goals &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$`Top scorer`)<br>PERFORMANCE_DATA$Minutes_for_Assists &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$Assists)<br>PERFORMANCE_DATA$Minutes_for_Goals_Assists &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$`Goals + Assists`)<br>PERFORMANCE_DATA$Minutes_for_Big_chances_created &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$`Big chances created`)<br>PERFORMANCE_DATA$Minutes_for_Big_chances_missed &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$`Big chances missed`)<br>PERFORMANCE_DATA$Minutes_for_Disarms &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$Disarms)<br>PERFORMANCE_DATA$Minutes_for_Blocks &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$Blocks)<br>PERFORMANCE_DATA$Minutes_for_Interceptions &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$Interceptions)<br>PERFORMANCE_DATA$Minutes_for_Saves &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$Saves)<br>PERFORMANCE_DATA$Minutes_for_YellowCards &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$`Yellow cards`)<br>PERFORMANCE_DATA$Minutes_for_RedCards &lt;- round(PERFORMANCE_DATA$minutes_played / PERFORMANCE_DATA$`Red cards`)</blockquote><p>In this step, we will correct the divisions by zero in the new timing variables. Where athletes who have statistics equal to zero received the score they have in the championship so far.</p><blockquote>#handling divisors by zero<br>PERFORMANCE_DATA$Minutes_for_Goals &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Goals == “Inf” | PERFORMANCE_DATA$Minutes_for_Goals == “NaN” , PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Goals)<br>PERFORMANCE_DATA$Minutes_for_Assists &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Assists == “Inf” | PERFORMANCE_DATA$Minutes_for_Assists == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Assists)<br>PERFORMANCE_DATA$Minutes_for_Goals_Assists &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Goals_Assists == “Inf” | PERFORMANCE_DATA$Minutes_for_Goals_Assists == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Goals_Assists)<br>PERFORMANCE_DATA$Minutes_for_Big_chances_created &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Big_chances_created == “Inf” | PERFORMANCE_DATA$Minutes_for_Big_chances_created == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Big_chances_created)<br>PERFORMANCE_DATA$Minutes_for_Big_chances_missed &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Big_chances_missed == “Inf” | PERFORMANCE_DATA$Minutes_for_Big_chances_missed == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Big_chances_missed)<br>PERFORMANCE_DATA$Minutes_for_Disarms &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Disarms == “Inf” | PERFORMANCE_DATA$Minutes_for_Disarms == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Disarms)<br>PERFORMANCE_DATA$Minutes_for_Blocks &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Blocks == “Inf” | PERFORMANCE_DATA$Minutes_for_Blocks == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Blocks)<br>PERFORMANCE_DATA$Minutes_for_Interceptions &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Interceptions == “Inf” | PERFORMANCE_DATA$Minutes_for_Interceptions == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Interceptions)<br>PERFORMANCE_DATA$Minutes_for_Saves &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_Saves == “Inf” | PERFORMANCE_DATA$Minutes_for_Saves == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_Saves)<br>PERFORMANCE_DATA$Minutes_for_YellowCards &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_YellowCards == “Inf” | PERFORMANCE_DATA$Minutes_for_YellowCards == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_YellowCards)<br>PERFORMANCE_DATA$Minutes_for_RedCards &lt;- ifelse(PERFORMANCE_DATA$Minutes_for_RedCards == “Inf” | PERFORMANCE_DATA$Minutes_for_RedCards == “NaN”, PERFORMANCE_DATA$minutes_played, PERFORMANCE_DATA$Minutes_for_RedCards)<br>PERFORMANCE_DATA$Big_chances_created_per_assists &lt;- ifelse(PERFORMANCE_DATA$Big_chances_created_per_assists == “Inf” | PERFORMANCE_DATA$Big_chances_created_per_assists == “NaN”, PERFORMANCE_DATA$`Big chances created`, PERFORMANCE_DATA$Big_chances_created_per_assists)<br>PERFORMANCE_DATA$Shots_on_target_per_goals &lt;- ifelse(PERFORMANCE_DATA$Shots_on_target_per_goals == “Inf” | PERFORMANCE_DATA$Shots_on_target_per_goals == “NaN”, PERFORMANCE_DATA$Shots_on_target, PERFORMANCE_DATA$Shots_on_target_per_goals)</blockquote><p>We will also separate Olympic-age youth (under 23) as well as players under and over 30.</p><blockquote>#Creating variables for segmentation and exploration of age data<br>PERFORMANCE_DATA$Age23 &lt;- ifelse(PERFORMANCE_DATA$player_age &lt;= 23, 1,0)<br>PERFORMANCE_DATA$smaller_Age30 &lt;- ifelse(PERFORMANCE_DATA$player_age &gt; 23 &amp; PERFORMANCE_DATA$player_age &lt; 30 , 1,0)<br>PERFORMANCE_DATA$larger_Age30 &lt;- ifelse(PERFORMANCE_DATA$player_age &gt;= 30, 1,0)<br>PERFORMANCE_DATA$None_Goals_Assists &lt;- ifelse(PERFORMANCE_DATA$`Goals + Assists` == 0, 1,0)</blockquote><p>After preparing the base, we can start creating the clustering model with the application of the Machine Learning K-means algorithm. For this, we will make a copy of the base original in order to normalize the numerical values ​​and make all the variables have the same order of magnitude (This will make one variable not influence more than the other just because it has another order of magnitude). Then, we created 10 clustering models with a different number of groups, model 1 with 2 clusters up to model 10 with 11 clusters.</p><blockquote>PERFORMANCE_DATA_NORMALIZED &lt;- PERFORMANCE_DATA<br># PERFORMING PREDICTION WITH CLUSTERING ALGORITHM AND USING “SCALE” STANDARDIZATION METHOD<br>PERFORMANCE_DATA_NORMALIZED &lt;- predict(preProcess(PERFORMANCE_DATA_NORMALIZED[,12:94], method =”scale”) ,PERFORMANCE_DATA_NORMALIZED)<br>#COMMAND TO ENSURE THE READER REACHES THE SAME RESULT<br>set.seed(1)</blockquote><blockquote>#SEPARATING DIFFERENT TYPES OF CLUSTERS<br>G2 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=2)<br>G3 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=3)<br>G4 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=4)<br>G5 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=5)<br>G6 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=6)<br>G7 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=7)<br>G8 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=8)<br>G9 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=9)<br>G10 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=10)<br>G11 &lt;- kmeans(PERFORMANCE_DATA_NORMALIZED[12:94], centers=11)</blockquote><p>For the determination of the ideal model, I will visually analyze the arrangement of the data by comparing the 10 models of different numbers of clusters.</p><blockquote># Storing model graphs in variables<br>viz_G2 &lt;- fviz_cluster(G2, data = PERFORMANCE_DATA_NORMALIZED[,c(12:94)],palette = c(“#DC143C”,”#7fffd4&quot;), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 1”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WNPQ2m2Rw5x33lXXQx3Ew.png" /></figure><blockquote>viz_G3 &lt;- fviz_cluster(G3, data = PERFORMANCE_DATA_NORMALIZED[,c(12:94)],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 2”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8op8oev1m3AQaHVXHwfVBw.png" /></figure><blockquote>viz_G4 &lt;- fviz_cluster(G4, data = PERFORMANCE_DATA_NORMALIZED[,c(12:94)],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 3”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tamABUCrQKRPGCwj0tLa-g.png" /></figure><blockquote>viz_G5 &lt;- fviz_cluster(G5, data = PERFORMANCE_DATA_NORMALIZED[,c(12:94)],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”, “#FF1493”), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 4”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrXiNpojW1qi1kSQZ3epAg.png" /></figure><blockquote>viz_G6 &lt;- fviz_cluster(G6, data = PERFORMANCE_DATA_NORMALIZED[12:94],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”, “#FF1493”,”#FF0000&quot;), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 5”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QL4xDXXriIsLkzPSWQrEcw.png" /></figure><blockquote>viz_G7 &lt;- fviz_cluster(G7, data = PERFORMANCE_DATA_NORMALIZED[12:94],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”, “#FF1493”,”#FF0000&quot;, “#C71585”), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 6”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zXWQUySt35xN9n3i1uOLmQ.png" /></figure><blockquote>viz_G8 &lt;- fviz_cluster(G8, data = PERFORMANCE_DATA_NORMALIZED[12:94],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”, “#FF1493”,”#FF0000&quot;, “#C71585”, “#C71585”), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 7”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1cdkiUN7uwsiWHB4qZAb9Q.png" /></figure><blockquote>viz_G9 &lt;- fviz_cluster(G9, data = PERFORMANCE_DATA_NORMALIZED[12:94],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”, “#FF1493”,”#FF0000&quot;, “#C71585”, “#C71585”, “#C71585”), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 8”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lOdc0ZBw2TcH5hM_IY20Vg.png" /></figure><blockquote>viz_G10 &lt;- fviz_cluster(G10, data = PERFORMANCE_DATA_NORMALIZED[12:94],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”, “#FF1493”,”#FF0000&quot;, “#C71585”, “#C71585”, “#C71585”, “#C71585” ), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 9”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NchfFxYWJd_h5qYkbxQKNg.png" /></figure><blockquote>viz_G11 &lt;- fviz_cluster(G11, data = PERFORMANCE_DATA_NORMALIZED[12:94],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”, “#FF1493”,”#FF0000&quot;, “#C71585”, “#C71585”, “#C71585”, “#C71585”, “#C71585” ), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Modelo 10”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dKgYhIBWt9AmHRsPc1S8zw.png" /></figure><blockquote># Visually comparing models<br>grid.arrange(viz_G2,viz_G3, viz_G4, viz_G5,viz_G6, viz_G7, viz_G8, viz_G9, viz_G10, viz_G11, nrow=2, ncol=5)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPnuq5tan8Gesu1V7r6aaA.png" /></figure><p>It is noted that models 1, 2, and 3 had the best performances, as they are able to better segment the different groups without overlaps, and model 3 is the only one of these to group separately the data arranged at the bottom of the graph (Group formed entirely by goalkeepers) and therefore will be the chosen model.</p><blockquote>#Viewing chosen model<br>viz_G4 &lt;- fviz_cluster(G4, data = PERFORMANCE_DATA_NORMALIZED[,c(12:94)],palette = c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#a9a9a9”), geom = “point”, ellipse.type = “convex”, ggtheme = theme_classic(), main = “Model 3 (4 Clusters)”)<br>grid.arrange(viz_G4, nrow=1, ncol=1)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fTD4DbhefiTVc0wU_rJDiA.png" /></figure><p>After choosing the best model, we can start analyzing the clusters by identifying what they have in common. First, we will see how the clusters were separated by the proportion of players per field zone (attack, midfield, defense, and goalkeepers).</p><blockquote># Storing clusters in the original dataset<br>PERFORMANCE_DATA$Cluster &lt;- G4$cluster</blockquote><blockquote>#Exploring proportion of the field zone variable<br>Group1 &lt;- filter(PERFORMANCE_DATA, Cluster ==1)<br>prop.table(table(Group1$Zone))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*2CaDyaIRs-RalgVR0mTVGQ.png" /></figure><p>Note that 58% of the composition of Cluster 1 is formed by attackers, with 35% of midfielders, 5% of players who work in the defensive zone, and less than 1% of goalkeepers.</p><blockquote>Group2 &lt;- filter(PERFORMANCE_DATA, Cluster ==2)<br>prop.table(table(Group2$Zone))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*YwON2tuBFH12QkG93Y3keg.png" /></figure><p>Cluster 2 is composed of 23% of players who act in the attack, 28% of players in midfield, 36% of players that act in the defense, and 8% of goalkeepers.</p><blockquote>Group3 &lt;- filter(PERFORMANCE_DATA, Cluster ==3)<br>prop.table(table(Group3$Zone))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*qOU_CUqOEAV-u6LEnQI4fg.png" /></figure><p>Cluster 3 is composed of 63% of defensive players and 36% of midfield players.</p><blockquote>Group4 &lt;- filter(PERFORMANCE_DATA, Cluster ==4)<br>prop.table(table(Group4$Zone))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*ggAaAy2yecdA3K3OCEjtMw.png" /></figure><p>Cluster 4 is a group formed entirely by goalkeepers.</p><p>Next, we will compare in tables the proportions of some variables that will give us an overview of the most relevant characteristics of the clusters.</p><blockquote># Comparing proportions of variables by clusters<br>PERFORMANCE_DATA %&gt;% group_by(Cluster) %&gt;% summarise_at(vars(player_age), list(Age_mean = mean))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*Wod3qasiLmBetwgcWwnE-w.png" /></figure><blockquote>EDA_GoalsAssists &lt;- PERFORMANCE_DATA %&gt;% group_by(Cluster) %&gt;% summarise_at(vars(`Goals + Assists`), list(Sum_Goals_and_Assists = sum))<br>EDA_GoalsAssists$Percent &lt;- round((EDA_GoalsAssists$Sum_Goals_and_Assists / sum(EDA_GoalsAssists$Sum_Goals_and_Assists))*100,2)<br>EDA_GoalsAssists</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*DvHH7Gbu_03GTssgNWgnAw.png" /></figure><blockquote>EDA_Goals &lt;- PERFORMANCE_DATA %&gt;% group_by(Cluster) %&gt;% summarise_at(vars(`Top scorer`), list(Goals = sum))<br>EDA_Goals$Percent &lt;- round((EDA_Goals$Goals / sum(EDA_Goals$Goals))*100,2)<br>EDA_Goals</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*2EBTsE9rPrdCPY6-ECTaMw.png" /></figure><blockquote>EDA_Assists &lt;- PERFORMANCE_DATA %&gt;% group_by(Cluster) %&gt;% summarise_at(vars(Assists), list(Assists = sum))<br>EDA_Assists$Percent &lt;- round((EDA_Assists$Assists / sum(EDA_Assists$Assists))*100,2)<br>EDA_Assists</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*XEwJ4INnYUUSK7Ob3s1bhQ.png" /></figure><blockquote>EDA_BigChancesCreated &lt;- PERFORMANCE_DATA %&gt;% group_by(Cluster) %&gt;% summarise_at(vars(`Big chances created`), list(BigChancesCreated = sum))<br>EDA_BigChancesCreated$Percent &lt;- round((EDA_BigChancesCreated$BigChancesCreated / sum(EDA_BigChancesCreated$BigChancesCreated))*100,2)<br>EDA_BigChancesCreated</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*DALXGuOGal3QsQFJDoMOmQ.png" /></figure><blockquote>EDA_Accurate_passes &lt;- PERFORMANCE_DATA %&gt;% group_by(Cluster) %&gt;% summarise_at(vars(Accurate_passes), list(Accurate_passes = sum))<br>EDA_Accurate_passes$Percent &lt;- round((EDA_Accurate_passes$Accurate_passes / sum(EDA_Accurate_passes$Accurate_passes))*100,2)<br>EDA_Accurate_passes</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*Nicy6wW8oaL_o90sYVHZRQ.png" /></figure><blockquote>EDA_Accurate_long_balls &lt;- PERFORMANCE_DATA %&gt;% group_by(Cluster) %&gt;% summarise_at(vars(Accurate_long_balls), list(Accurate_long_balls = sum))<br>EDA_Accurate_long_balls$Percent &lt;- round((EDA_Accurate_long_balls$Accurate_long_balls / sum(EDA_Accurate_long_balls$Accurate_long_balls))*100,2)<br>EDA_Accurate_long_balls</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*yrOFJ_RLJTjnB_zeIroeqg.png" /></figure><blockquote>EDA_Disarms_Blocks_Intercep &lt;- PERFORMANCE_DATA %&gt;% group_by(Cluster) %&gt;% summarise_at(vars(Sum_Disarms_Blocks_Intercep), list(Disarms_Blocks_Intercep = sum))<br>EDA_Disarms_Blocks_Intercep$Percent &lt;- round((EDA_Disarms_Blocks_Intercep$Disarms_Blocks_Intercep / sum(EDA_Disarms_Blocks_Intercep$Disarms_Blocks_Intercep))*100,2)<br>EDA_Disarms_Blocks_Intercep</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*4nFvItdWWYSrjAi6c2tWng.png" /></figure><p>We will also use box plots to explore other variables and compare clusters.</p><blockquote>#Exploring variables with Boxplots<br>par(mfrow=c(1,3))<br>boxplot(PERFORMANCE_DATA$matches_played ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Matches played”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$minutes_played ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes played”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$player_age ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Age”, xlab = “Cluster”, ylab = “”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fHZfkXOsJ94HuvDrOBEJCg.png" /></figure><blockquote>par(mfrow=c(2,4))<br>boxplot(PERFORMANCE_DATA$`Chances created` ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Chances created”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$`Big chances created` ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Big chances created”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$`Big chances missed` ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Big chances missed”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Assists ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Assists”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$`Top scorer` ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Goals”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Shots ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Shots”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Shots_on_target ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Shots on target”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Successful_dribbles ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Successful dribbles”, xlab = “Cluster”, ylab = “”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A88bW-bR-8hd0Oxe4k30SQ.png" /></figure><blockquote>boxplot(PERFORMANCE_DATA$Accurate_passes ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Accurate passes”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Accurate_long_balls ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Accurate long balls”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Disarms ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Disarms”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Blocks ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Blocks”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Interceptions ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Interceptions”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Possession_won_final_3rd ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Possession won final 3rd”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Fouls_committed ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Fouls committed”, xlab = “Cluster”, ylab = “”)<br>boxplot(PERFORMANCE_DATA$Sum_yellow_red_cards ~ PERFORMANCE_DATA$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Yellow/Red Cards”, xlab = “Cluster”, ylab = “”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOyqlgZFJ4ttAQUWf5eCWA.png" /></figure><blockquote>#For minute views, players who have a stat equal to zero are being disregarded.<br>DataMinutes_GoalsAssists &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Goals_Assists, `Goals + Assists`, `Top scorer`,Assists, Cluster)<br>DataMinutes_GoalsAssists$Remove &lt;- ifelse(DataMinutes_GoalsAssists$Minutes_for_Goals_Assists == DataMinutes_GoalsAssists$minutes_played,1,0)<br>DataMinutes_GoalsAssists &lt;- filter(DataMinutes_GoalsAssists, Remove== 0)<br>DataMinutes_GoalsAssists &lt;- DataMinutes_GoalsAssists[order(DataMinutes_GoalsAssists$Minutes_for_Goals_Assists, decreasing = F),]<br>DataMinutes_GoalsAssists$Remove &lt;-NULL<br>DataMinutes_GoalsAssists$Position &lt;- row.names(DataMinutes_GoalsAssists)<br>boxplot(DataMinutes_GoalsAssists$Minutes_for_Goals_Assists ~ DataMinutes_GoalsAssists$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes for Goals/Assists”, xlab = “Cluster”, ylab = “”)</blockquote><blockquote>DataMinutes_Goals &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Goals, `Top scorer`, Cluster)<br>DataMinutes_Goals$Remove &lt;- ifelse(DataMinutes_Goals$Minutes_for_Goals == DataMinutes_Goals$minutes_played,1,0)<br>DataMinutes_Goals &lt;- filter(DataMinutes_Goals, Remove== 0)<br>DataMinutes_Goals &lt;- DataMinutes_Goals[order(DataMinutes_Goals$Minutes_for_Goals, decreasing = F),]<br>DataMinutes_Goals$Remove &lt;-NULL<br>DataMinutes_Goals$Position &lt;- row.names(DataMinutes_Goals)<br>boxplot(DataMinutes_Goals$Minutes_for_Goals ~ DataMinutes_Goals$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes for Goals”, xlab = “Cluster”, ylab = “”)</blockquote><blockquote>DataMinutes_Assists &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Assists, Assists, Cluster)<br>DataMinutes_Assists$Remove &lt;- ifelse(DataMinutes_Assists$Minutes_for_Assists == DataMinutes_Assists$minutes_played,1,0)<br>DataMinutes_Assists &lt;- filter(DataMinutes_Assists, Remove== 0)<br>DataMinutes_Assists &lt;- DataMinutes_Assists[order(DataMinutes_Assists$Minutes_for_Assists, decreasing = F),]<br>DataMinutes_Assists$Remove &lt;-NULL<br>DataMinutes_Assists$Position &lt;- row.names(DataMinutes_Assists)<br>boxplot(DataMinutes_Assists$Minutes_for_Assists ~ DataMinutes_Assists$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes for Assists”, xlab = “Cluster”, ylab = “”)</blockquote><blockquote>DataMinutes_BigChancesCreated &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Big_chances_created, Cluster)<br>DataMinutes_BigChancesCreated$Remove &lt;- ifelse(DataMinutes_BigChancesCreated$Minutes_for_Big_chances_created == DataMinutes_BigChancesCreated$minutes_played,1,0)<br>DataMinutes_BigChancesCreated &lt;- filter(DataMinutes_BigChancesCreated, Remove== 0)<br>DataMinutes_BigChancesCreated &lt;- DataMinutes_BigChancesCreated[order(DataMinutes_BigChancesCreated$Minutes_for_Big_chances_created, decreasing = F),]<br>DataMinutes_BigChancesCreated$Remove &lt;-NULL<br>DataMinutes_BigChancesCreated$Position &lt;- row.names(DataMinutes_BigChancesCreated)<br>boxplot(DataMinutes_BigChancesCreated$Minutes_for_Big_chances_created ~ DataMinutes_BigChancesCreated$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes for Big chances created”, xlab = “Cluster”, ylab = “”)</blockquote><blockquote>DataMinutes_BigChancesMissed &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Big_chances_missed, Cluster)<br>DataMinutes_BigChancesMissed$Remove &lt;- ifelse(DataMinutes_BigChancesMissed$Minutes_for_Big_chances_missed == DataMinutes_BigChancesMissed$minutes_played,1,0)<br>DataMinutes_BigChancesMissed &lt;- filter(DataMinutes_BigChancesMissed, Remove== 0)<br>DataMinutes_BigChancesMissed &lt;- DataMinutes_BigChancesMissed[order(DataMinutes_BigChancesMissed$Minutes_for_Big_chances_missed, decreasing = F),]<br>DataMinutes_BigChancesMissed$Remove &lt;-NULL<br>DataMinutes_BigChancesMissed$Position &lt;- row.names(DataMinutes_BigChancesMissed)<br>boxplot(DataMinutes_BigChancesMissed$Minutes_for_Big_chances_missed ~ DataMinutes_BigChancesMissed$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes for Big chances missed”, xlab = “Cluster”, ylab = “”)</blockquote><blockquote>DataMinutes_Disarms &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Disarms, Cluster)<br>DataMinutes_Disarms$Remove &lt;- ifelse(DataMinutes_Disarms$Minutes_for_Disarms == DataMinutes_Disarms$minutes_played,1,0)<br>DataMinutes_Disarms &lt;- filter(DataMinutes_Disarms, Remove== 0)<br>DataMinutes_Disarms &lt;- DataMinutes_Disarms[order(DataMinutes_Disarms$Minutes_for_Disarms, decreasing = F),]<br>DataMinutes_Disarms$Remove &lt;-NULL<br>DataMinutes_Disarms$Position &lt;- row.names(DataMinutes_Disarms)<br>boxplot(DataMinutes_Disarms$Minutes_for_Disarms ~ DataMinutes_Disarms$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes for Disarms”, xlab = “Cluster”, ylab = “”)</blockquote><blockquote>DataMinutes_Blocks &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Blocks, Cluster)<br>DataMinutes_Blocks$Remove &lt;- ifelse(DataMinutes_Blocks$Minutes_for_Blocks == DataMinutes_Blocks$minutes_played,1,0)<br>DataMinutes_Blocks &lt;- filter(DataMinutes_Blocks, Remove== 0)<br>DataMinutes_Blocks &lt;- DataMinutes_Blocks[order(DataMinutes_Blocks$Minutes_for_Blocks, decreasing = F),]<br>DataMinutes_Blocks$Remove &lt;-NULL<br>DataMinutes_Blocks$Position &lt;- row.names(DataMinutes_Blocks)<br>boxplot(DataMinutes_Blocks$Minutes_for_Blocks ~ DataMinutes_Blocks$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes for Blocks”, xlab = “Cluster”, ylab = “”)</blockquote><blockquote>DataMinutes_Interceptions &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Interceptions, Cluster)<br>DataMinutes_Interceptions$Remove &lt;- ifelse(DataMinutes_Interceptions$Minutes_for_Interceptions == DataMinutes_Interceptions$minutes_played,1,0)<br>DataMinutes_Interceptions &lt;- filter(DataMinutes_Interceptions, Remove== 0)<br>DataMinutes_Interceptions &lt;- DataMinutes_Interceptions[order(DataMinutes_Interceptions$Minutes_for_Interceptions, decreasing = F),]<br>DataMinutes_Interceptions$Remove &lt;-NULL<br>DataMinutes_Interceptions$Position &lt;- row.names(DataMinutes_Interceptions)<br>boxplot(DataMinutes_Interceptions$Minutes_for_Interceptions ~ DataMinutes_Interceptions$Cluster, col= c(“#DC143C”,”#7fffd4&quot;, “#87cefa”, “#f3f3f3”), main=”Minutes for Interceptions”, xlab = “Cluster”, ylab = “”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYPnY6o8UDwfLLAm8OJdCw.png" /></figure><blockquote>#Creating specific views for goalkeepers<br>par(mfrow=c(1,4))<br>Goalkeepers &lt;- filter(PERFORMANCE_DATA, Cluster == 4)<br>boxplot(Goalkeepers$Saves ~ Goalkeepers$Cluster, col= c(“#f3f3f3”), main=”Saves”, xlab = “Cluster 4 (Goalkeepers)”, ylab = “”)<br>DataMinutes_Saves &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Minutes_for_Saves, Cluster)<br>DataMinutes_Saves$Remove &lt;- ifelse(DataMinutes_Saves$Minutes_for_Saves == DataMinutes_Saves$minutes_played,1,0)<br>DataMinutes_Saves &lt;- filter(DataMinutes_Saves, Remove== 0)<br>DataMinutes_Saves &lt;- DataMinutes_Saves[order(DataMinutes_Saves$Minutes_for_Saves, decreasing = F),]<br>DataMinutes_Saves$Remove &lt;-NULL<br>DataMinutes_Saves$Position &lt;- row.names(DataMinutes_Saves)<br>boxplot(DataMinutes_Saves$Minutes_for_Saves ~ Goalkeepers$Cluster, col= c(“#f3f3f3”), main=”Minutes for saves”, xlab = “Cluster 4 (Goalkeepers)”, ylab = “”)<br>boxplot(Goalkeepers$Goals_conceded ~ Goalkeepers$Cluster, col= c(“#f3f3f3”), main=”Goals conceded”, xlab = “Cluster 4 (Goalkeepers)”, ylab = “”)<br>boxplot(Goalkeepers$Clearances ~ Goalkeepers$Cluster, col= c(“#f3f3f3”), main=”Clearances”, xlab = “Cluster 4 (Goalkeepers)”, ylab = “”)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jtyhketL4aevZ7E-c9J6ag.png" /></figure><p><strong>Definition of cluster characteristics.</strong></p><p><strong>Cluster 1</strong> (Red) nicknamed <strong>“Decisive Players”</strong>, has an average age of 27 years, 58% of its composition formed by forwards, 75% of its athletes played more than 20 matches and played for more than 1000 minutes, has the top 10 top scorers in the league, the top 10 players with the most goal assists, are responsible for 59% of all great scoring chances created so far, as well as being active defensively in the offensive zone, with 25% of its athletes gaining possession of the ball in the most dangerous zone of the field by more than 12x.</p><p><strong>Cluster 2</strong> (Green) nicknamed<strong> “Players with low minutes”</strong>, has an average age of 26 years, and is the group with the best balance of attacking (26%) and defensive (36%) players. with 75% of its athletes played less than 14 matches and played less than 1000 minutes, it is the group with the lowest proportion of passes, tackles, and chances created among all clusters. This group excels when analyzing statistics by minutes, 50% of this cluster needs less than 300 minutes to score a goal.</p><p><strong>Cluster 3 </strong>(Blue) nicknamed <strong>“Defensive Players”</strong>, has an average age of 27 years, 63% of its composition is formed by defensive players, 75% of its athletes played more than 20 matches and played for more than 1400 minutes, is the holder of 61% of the right passes made so far, in addition to 71% of the right long balls made, his best performance comes from scoring statistics, this cluster was responsible for 71% of all tackles, blocks and interceptions in the entire championship so far.</p><p><strong>Cluster 4</strong> (Grey), composed entirely of <strong>goalkeepers</strong>, has an average age of 32 years, just over 50% of its athletes made more than 70 saves and 25% conceded less than 23 goals.</p><p><strong>Individual highlights:</strong></p><p><strong>Cluster 1:</strong> I mention here the player <strong>Pedro</strong> do Flamengo as a highlight of this cluster, he has the incredible mark of 1 goal every 2 shots on target, with direct participation in a goal or assist every 83 minutes, in addition to being only 23 years old, his market value is estimated at less than half that of the most expensive player in his position (Gabigol), a difference of 84 million reais.</p><blockquote>#Pedro<br>Rank_ShotsOnTargetForGoals &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Shots_on_target_per_goals, Cluster)<br>filter(Rank_ShotsOnTargetForGoals, participant_name == “PEDRO”, team_name == “Flamengo”)<br>head(DataMinutes_Goals,3)<br>#Extracting market value data from Transfermarkt API<br>Transfermarkt_MarketValue &lt;- tm_player_market_values(country_name = “Brazil”, start_year = 2021)<br>#handling player names<br>Transfermarkt_MarketValue$player_name &lt;- apply(Transfermarkt_MarketValue[,7,drop=F],2, removePunctuation)<br>Transfermarkt_MarketValue$player_name&lt;- as.character(Transfermarkt_MarketValue$player_name)<br>Transfermarkt_MarketValue$player_name &lt;- apply(Transfermarkt_MarketValue[,7,drop=F],2, toupper)<br>Transfermarkt_MarketValue$player_name &lt;- stri_trans_general(Transfermarkt_MarketValue$player_name,id=”Latin-ASCII”)<br>Data_temporary &lt;- TRANSFERMARKT_DATA %&gt;% select(2,1)<br>Transfermarkt_MarketValue &lt;- left_join(Transfermarkt_MarketValue, Data_temporary, by=”player_name”)<br>Transfermarkt_MarketValue$concatenado &lt;- paste(Transfermarkt_MarketValue$player_name,”_”,Transfermarkt_MarketValue$team_name_transfermarkt)<br>Transfermarkt_MarketValue &lt;- Transfermarkt_MarketValue %&gt;% select(21,13,14,18)<br>Transfermarkt_MarketValue$MarketValue_MM &lt;- Transfermarkt_MarketValue$player_market_value_euro / 1000000<br>Transfermarkt_MarketValue &lt;- Transfermarkt_MarketValue[order(Transfermarkt_MarketValue$MarketValue_MM, decreasing = T),]<br>Transfermarkt_MarketValue$Position &lt;- 1:nrow(Transfermarkt_MarketValue)<br>filter(Transfermarkt_MarketValue, Position == c(1,20))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*M7_2skdp2bfDHA6xz8N8Zg.png" /></figure><p><strong>Cluster 2: </strong>The right winger <strong>Michel Araujo</strong> from Fluminense, appears as an individual highlight of this group, with the surprising mark of participating in a goal or assist every 16 minutes played, the athlete has 5 matches made and only 49 minutes played, but he already counts 1 goal and 2 assists so far.</p><blockquote>View(DataMinutes_GoalsAssists)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTPllN3l_CKKoxu--3MsPQ.png" /></figure><p><strong>Cluster 3:</strong> Defender <strong>Gustavo Gomez</strong> do Palmeiras, appears as the individual highlight of this group, in addition to appearing among the top 15 athletes with the most tackles, blocks, and interceptions made, he is also the 15th top scorer championship so far with an incredible 9 goals scored.</p><blockquote>Rank_Disarms_Blocks_Intercep &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,Sum_Disarms_Blocks_Intercep, Cluster)<br>Rank_Disarms_Blocks_Intercep &lt;- Rank_Disarms_Blocks_Intercep[order(Rank_Disarms_Blocks_Intercep$Sum_Disarms_Blocks_Intercep, decreasing = T),]<br>Rank_Disarms_Blocks_Intercep$Position &lt;- row.names(Rank_Disarms_Blocks_Intercep)<br>head(Rank_Disarms_Blocks_Intercep,15)</blockquote><blockquote>Rank_Goals &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,`Top scorer`, Cluster)<br>Rank_Goals &lt;- Rank_Goals[order(Rank_Goals$`Top scorer`, decreasing = T),]<br>Rank_Goals$Position &lt;- row.names(Rank_Goals)<br>View(Rank_Goals)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WK1DGsVwoR121Q2iuf24rA.png" /></figure><p><strong>Cluster 4:</strong> The goalkeeper <strong>Tadeu</strong> do Goiás appears as the highlight of this group, being the most activated goalkeeper in the championship when he needs to make a save every 22 minutes played.</p><blockquote>View(DataMinutes_Saves)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDFO2dBbCjbHe7RVTus1Tg.png" /></figure><p><strong>Youth Highlights:</strong></p><p>As a highlight among young people (Olympic-age players, under 23 years old), I mention 3 names that lead to extremely important statistics, the first is the boy <strong>Endrick</strong>, the Palmeiras player who is 16 years old and played for only 106 minutes, he is the 1st in the ranking of athletes who need fewer minutes to score 1 goal, the young man already has 2 goals scored in just 106 minutes of action, which leaves him with the incredible mark of 1 goal every 53 minutes.</p><blockquote>#Endrick<br>View(DataMinutes_Goals)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-95QrwBaVfcIJk1WOEEbA.png" /></figure><p>The second name is the athlete <strong>João Gomes</strong> do Flamengo, the 21-year-old defensive midfielder needs only 31 minutes to disarm an opponent with ball possession, being the first place in this ranking.</p><blockquote>#Joao Gomes<br>View(DataMinutes_Disarms)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6kUUVBQrlXffFk2BmdKZGg.png" /></figure><p>The last one is the young <strong>Marcos Leonardo</strong> striker for Santos, just 19 years old, he is the league’s top scorer among Olympic-age players, leading the category with 13 goals scored in 31 games played.</p><blockquote>#Marcos Leonardo<br>Rank_GoalsAssists_age23 &lt;- PERFORMANCE_DATA %&gt;% select(1:4,9,11:14,`Goals + Assists`,Age23, Cluster)<br>Rank_GoalsAssists_age23 &lt;- filter(Rank_GoalsAssists_age23, Age23 == 1)<br>Rank_GoalsAssists_age23 &lt;- Rank_GoalsAssists_age23[order(Rank_GoalsAssists_age23$`Goals + Assists`, decreasing = T),]<br>Rank_GoalsAssists_age23$Position &lt;- row.names(Rank_GoalsAssists_age23)<br>View(Rank_GoalsAssists_age23)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eq4RjlTFM-hXbPlGQSQa7w.png" /></figure><p><strong>Did the model achieve the expected result?</strong></p><p>Yes. The application of the Machine Learning K-means algorithm to create a clustering model for the 2022 Brazilian championship players proved to be effective in segmenting offensive, defensive, and goalkeepers separately, allowing to extract of relevant insights from the explored clusters. This study can be useful for decisions to buy and sell new athletes, contract renewals, individual awards, and other real applications.</p><p><strong>How can this work be improved?</strong></p><p>This work can be improved with the application of other statistical clustering techniques, the creation of new variables for segmentation and analysis, a deeper exploration of the data already arranged, in addition to the possibility of crossing data with other sources of information and other ideas.</p><p><strong>Final considerations.</strong></p><p>My name is Thiago Silva, I’m a Brazilian data scientist and this is my second article on Medium. I often use football bases to improve my knowledge of Statistics and Machine Learning. For more content like this, follow me on this platform and connect with me on <a href="https://www.linkedin.com/in/thiagodossantossilva/">Linkedin</a>.</p><p>Thank you for your access and I count on your comment for improvements in future publications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcab9acf6482" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to extract football databases by APIs using the R language.]]></title>
            <link>https://medium.com/@thiagossilva17/how-to-extract-football-databases-by-apis-using-the-r-language-5a45f4c61079?source=rss-1e776b0a0adb------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a45f4c61079</guid>
            <category><![CDATA[sports-analytics]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[football]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Thiago Silva]]></dc:creator>
            <pubDate>Mon, 17 Oct 2022 01:03:58 GMT</pubDate>
            <atom:updated>2022-10-17T01:03:58.283Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I’ll show you how we can use the power of the R language to extract football databases from the most renowned statistical references in the sports world, through API calls quickly and easily, using the incredible package <a href="https://github.com/JaseZiv/worldfootballR">“worldfootballR”</a> created by Australian data scientist <a href="https://github.com/JaseZiv">Jason Zivkovic</a>.</p><p><strong>What types of data are available?</strong></p><p>The following API calls start from databases at the “team” level, where it is possible to find statistics on clubs and teams from different tournaments and competitions, to the extraction of databases at the “player” level, as well as the entire your historical performance statistics, demographic and other information.</p><p><strong>What are the sources of information?</strong></p><p>The sources of information used as a reference for data extraction are <a href="https://www.transfermarkt.com/">Transfermarkt </a>(the 25th most accessed website in Germany and one of the largest sports websites in the world),<a href="https://www.fotmob.com/"> Fotmob</a> (The Norwegian website recognized by Google, Apple, and the New York Times as the leader in sports statistics), <a href="https://fbref.com/">FBref</a> and <a href="https://understat.com/">Understat</a>.</p><p><strong>What software is needed for the process?</strong></p><p>To replicate the steps below, it is recommended that you have installed the <a href="https://cran.r-project.org/bin/windows/base/">R language (4.2.1) </a>and the <a href="https://www.rstudio.com/">Rstudio IDE (2022.07.1+554)</a> on your machine, which can be found free of charge at the respective official links. If your operating system is not Windows, you can search the websites for the operating system you prefer.</p><p><strong>Preparing the environment for extractions.</strong></p><p>After installing the R language and the Rstudio IDE, we must install and load the “worldfootballR”, “dplyr” and “tidyr” libraries to request data and use the language in an agile and efficient way. follow:</p><blockquote>install.packages(“devtools”)<br>devtools::install_github(“JaseZiv/worldfootballR”)<br>library(worldfootballR)<br>install.packages(“dplyr”)<br>library(dplyr)<br>install.packages(“tidyr”)<br>library(tidyr)</blockquote><p>After loading the packages, we can start API calls.</p><p><strong>1st Extraction: Erling Haaland’s stock history. </strong><a href="https://understat.com/"><strong>(Understat)</strong></a></p><p>Our first request will be at the player level, and we’ll use Manchester City’s worldwide phenomenon Erling Haaland as an example.</p><blockquote>Haaland_shots &lt;- understat_player_shots(player_url = “<a href="https://understat.com/player/8260">https://understat.com/player/8260</a>&quot;)</blockquote><blockquote>View(Haaland_shots)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JX4kpJFujDSC6i8UmlftIQ.png" /></figure><p>The code above, allows us to bring information about all the shots of Haaland in his career!!! Amazing right?</p><p>The level of depth of the information is surreal, we can know the exact location on the field, where each action of the athlete started, what type of action was performed (kick, pass, cross…), with which leg it was performed, if it was blocked, defended, out, who promoted the pass, the match, the minute and various other information.</p><p>To query data from other athletes, you can change the “player_url” argument and provide the “URL” you want. To find it, access the <a href="https://understat.com/">understat</a> website and the page of the desired athlete, simply copying their address in the same pattern.</p><p><strong>2nd Extract: Transfer history of Real Madrid players. </strong><a href="https://www.transfermarkt.com/"><strong>(Transfermarkt)</strong></a></p><blockquote>RealMadrid_Transfers &lt;- tm_team_transfers(team_url = “<a href="https://www.transfermarkt.com/real-madrid/startseite/verein/418">https://www.transfermarkt.com/real-madrid/startseite/verein/418</a>&quot;, transfer_window = “all”)</blockquote><blockquote>View(RealMadrid_Transfers)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a4Gag49H6OXSK7pgc6BO4g.png" /></figure><p>In the second extraction, the Transfermarkt API will be used to extract the transfer history of the Real Madrid club in the 2022/2023 season. <br>Here we have variables such as Athlete sold/bought, sale/buy value, previous club, future club, age, position, goals, time played, and other variables for each athlete involved in any club negotiations in the season.</p><p><strong>3rd Extract: Barcelona (3) x (3) Inter match summary in Uefa Champions League 2022 </strong><a href="https://fbref.com/en/"><strong>(FBref)</strong></a></p><blockquote>Bar_Int_UCL_2022_summary &lt;- fb_match_summary(match_url = “<a href="https://fbref.com/en/matches/fac347dd/Barcelona-Internazionale-October-12-2022-Champions-League">https://fbref.com/en/matches/fac347dd/Barcelona-Internazionale-October-12-2022-Champions-League</a>&quot;)</blockquote><blockquote>View(Bar_Int_UCL_2022_summary)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hW_rSTt84FIKRihDAbzBNg.png" /></figure><p>In the third extraction, we will use the FBref API to extract the data from the Barcelona 3 x 3 Inter match by UCL 2022, here we have the base distributed by events that occurred in the game, for example, minute of each yellow/red card, corners, goals, penalties, and others.</p><p><strong>4th Extract: Athletes’ performance statistics for the 2022/2023 season </strong><a href="https://www.fotmob.com/"><strong>(Fotmob)</strong></a></p><p>In the fourth extraction, the Fotmob API will be used to extract the performance statistics of all Premier League athletes from the 2022/2023 season.</p><blockquote>PL_player_Stats &lt;- fotmob_get_season_stats(<br> country = “ENG”,<br> league_name = “Premier League”,<br> season = “2022/2023”,<br> stat_name = c(“Chances created”, “Big chances created”,”Big chances missed”, “Accurate long balls per 90”, “Accurate passes per 90”,”Shots per 90&quot;,”Shots on target per 90&quot;, “Goals per 90”, “Assists”, “Goals + Assists”,”Successful dribbles per 90&quot;,”Successful tackles per 90&quot;,”Penalties won”,”Penalties conceded”,”Blocks per 90&quot;,”Clean sheets”,”Clearances per 90&quot;,”Fouls committed per 90&quot;,”Goals conceded per 90&quot;,”Interceptions per 90&quot;,”Possession won final 3rd per 90&quot;,”Save percentage”,”Saves per 90&quot;,”Top scorer”,”Yellow cards”,”Red cards”),<br> team_or_player = “player”<br>)</blockquote><blockquote>View(PL_player_Stats)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HdS5mmvUnvejDhWm8uwOOQ.png" /></figure><p>Among the variables of this base, we have information such as the number of goals, assists, chances created, great chances created, chances lost, great chances lost, tackles, yellow/red cards, long/short passes, and other information about each athlete in the competition.</p><p><strong>How to save these databases locally?</strong></p><p>You can use the code below to save the databases on your local machine, just change the directory name to the name used on your machine, and make sure you keep the slashes “/” as shown below:</p><blockquote>write.csv(DATABASE_NAME, “C:/DIRECTORY_NAME/DATABASE_NAME.csv”)</blockquote><blockquote>for example:</blockquote><blockquote>write.csv(Haaland_shots, “C:/DESKTOP_THIAGO_SILVA/Haaland.csv”)</blockquote><p><strong>How to find other databases?</strong></p><p>To explore other bases and possibilities of the <a href="https://github.com/JaseZiv/worldfootballR">“worldfootballR”</a> package, I recommend accessing the <a href="https://github.com/JaseZiv">Github of creator Jason Zivkovic</a>, who has been doing an excellent job in facilitating the use of this data in such a simple way. The 4 examples presented here are just a few possibilities among the dozens of calls available in the package.</p><p><strong>Final considerations.</strong></p><p>It is worth mentioning that the APIs are the responsibility of the supplier companies, so these services are subject to change without prior notice, which may cause bugs or malfunctions of some functions, hence the importance of community participation to detect/adjust any problems that may arise. can happen in these calls.</p><p>My name is Thiago Silva, I’m a Brazilian data scientist and this is my first article on Medium. I often use football bases to improve my knowledge of Statistics and Machine Learning. For more content like this, follow me on this platform and connect with me on <a href="https://www.linkedin.com/in/thiagodossantossilva/">Linkedin</a>.</p><p>Thank you for your access and I count on your comment for improvements in future publications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a45f4c61079" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>