University of Warsaw - Faculty of Economic Sciences
Libraries
library(knitr)
library(readxl)
library(arules)
library(arulesViz)
library(arulesCBA)
library("FactoMineR")
library("factoextra")
library(magrittr)
library(ggrepel) Riot’s Teamfight Tactics is a multiplayer game based on chess but much more various. The key rule of this game is you have to choose your team comp among 100 available champions. Every champion has a trait, and the more traits from a certain group of champions you have the stronger bonuses you receive. I’m a huge fan of this game and it’s hard to be up to date in this game (especially during a winter exam session) because it changes every patch and every season. So a new change was uploaded to a live server one week ago and I haven’t adapted yet. I really like to be one of the best players in European server so I will use my degree to help myself.
Association rules are a field in machine learning that finds the relation between data and more precisely will tell us what likes to combine with each other. That algorithm is used by the biggest IT companies like Facebook, Youtube, or NETFLIX to create the best possible recommendations for us. That’s why I find it useful because I will try to analyze games of the best players and by that, I will know what team comps are the best right now, and what champions are played together.
I used a useful site that shows basic statistics about TFT (team fight tactics) https://lolchess.gg/ to scrap data for 16 polish players that perform in the best polish TFT league called Ultraliga. I will use the last 5 games of every one of them to collect the data. But I will also use only team comps from winning games. That means only from place 1-4 out of 8. Because for that places u gain points. For places 5-8 you lose points. So that will give me a multidimensional approach because every player has a unique preference to play different team comps. So I will eventually accomplish 16 * 4 *5=320 rows of data
| Players_of_group_A | Players_of_group_B |
|---|---|
| OGIII | ARNOLD |
| KACPERSKY | DV1 SAGE |
| TKEY | ANO VICER |
| SIMPLYWOJTEK | DV1 SHIRCANE |
| AKI | AGO TRAVISCWAT |
| AGO LELOUCH | SPC ARKADY |
| LEFT | KUBIXON |
| AGO ZBROJSON | UNLUCKYHUBI |
I’ve mentioned previously I will use 320 rows of data that will tell what team comps are built in TFT games.
So after finalising database it’s time to inspect it and see if the data is prepared correctly
## transactions as itemMatrix in sparse format with
## 320 rows (elements/itemsets/transactions) and
## 70 columns (items) and a density of 0.1151339
##
## most frequent items:
## Silco Vi Sejuani Renata Glasc Zac (Other)
## 196 194 170 127 116 1776
##
## element (itemset/transaction) length distribution:
## sizes
## 6 7 8 9
## 13 44 174 89
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.000 8.000 8.000 8.059 9.000 9.000
##
## includes extended item information - examples:
## labels
## 1 Ahri
## 2 Alistar
## 3 Blitzcrank
That’s pretty informative for now. The most popular champion in nearly 61,25% of winner matches is Silco and most winning team comps are composed of 8 champions (the most popular basket size).
But let’s deep into the 10 popular winning champions .
From the point of view of a TFT player, the score has a logical explanation. Sejuani is pretty always combined with Vi because really strong game buffs. Silco and Renata Glasc are juz overpowered champions that will be weakened in next patches. Zac and Reksai creates perfect combo with Sejuani and Vi guaranting your team additional health points. Seraphine and Jayce are guaranting you a strong buff called ‘Innovator’ and are the most powerful champions from this buff area. Ekko and Sivir are just really strong and they do not have a certain connection with other champions. But to judge on that let’s perform a deeper analysis based on association rules
An easy and also powerful tool to check the champions frequency is just two-dimensional tables that will show the most popular combination. Cross-tables are also useful to perform correspondence analysis. But for now let’s inspect the 15 most popular champions
| Silco | Vi | Sejuani | Renata Glasc | Zac | Reksai | Seraphine | Ekko | Sivir | Jayce | Viktor | Gnar | JarvanIV | Lucian | Irelia | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Silco | 196 | 128 | 123 | 99 | 86 | 56 | 41 | 28 | 47 | 41 | 51 | 39 | 40 | 40 | 33 |
| Vi | 128 | 194 | 144 | 95 | 98 | 67 | 43 | 34 | 54 | 50 | 68 | 30 | 45 | 39 | 28 |
| Sejuani | 123 | 144 | 170 | 84 | 90 | 63 | 27 | 8 | 63 | 17 | 58 | 33 | 57 | 51 | 22 |
| Renata Glasc | 99 | 95 | 84 | 127 | 92 | 53 | 23 | 11 | 6 | 27 | 61 | 10 | 5 | 6 | 9 |
| Zac | 86 | 98 | 90 | 92 | 116 | 57 | 15 | 7 | 1 | 22 | 63 | 8 | 2 | 3 | 9 |
| Reksai | 56 | 67 | 63 | 53 | 57 | 98 | 15 | 14 | 20 | 14 | 32 | 24 | 10 | 5 | 20 |
| Seraphine | 41 | 43 | 27 | 23 | 15 | 15 | 81 | 51 | 6 | 36 | 11 | 26 | 7 | 0 | 31 |
| Ekko | 28 | 34 | 8 | 11 | 7 | 14 | 51 | 76 | 8 | 42 | 2 | 24 | 1 | 1 | 34 |
| Sivir | 47 | 54 | 63 | 6 | 1 | 20 | 6 | 8 | 74 | 7 | 1 | 23 | 55 | 50 | 17 |
| Jayce | 41 | 50 | 17 | 27 | 22 | 14 | 36 | 42 | 7 | 71 | 13 | 17 | 2 | 5 | 21 |
| Viktor | 51 | 68 | 58 | 61 | 63 | 32 | 11 | 2 | 1 | 13 | 71 | 3 | 1 | 1 | 3 |
| Gnar | 39 | 30 | 33 | 10 | 8 | 24 | 26 | 24 | 23 | 17 | 3 | 67 | 13 | 14 | 40 |
| JarvanIV | 40 | 45 | 57 | 5 | 2 | 10 | 7 | 1 | 55 | 2 | 1 | 13 | 61 | 46 | 11 |
| Lucian | 40 | 39 | 51 | 6 | 3 | 5 | 0 | 1 | 50 | 5 | 1 | 14 | 46 | 60 | 3 |
| Irelia | 33 | 28 | 22 | 9 | 9 | 20 | 31 | 34 | 17 | 21 | 3 | 40 | 11 | 3 | 58 |
ECLAT (Equivalence Class Clustering and bottom-up Lattice Traversal) algorithm is a really basic conception based on the support statistic that creates the most frequent item sets. So now it’s important to describe what support in terms of the ECLAT Algorithm means. Basically, support is the relative frequency of a certain item set in the entire basket of items. The Algorithm tells us which items occur together the most, but there are not directly created rules. So the advantage is the method is very fast but in the end we are still out of strong rules, we have just hints.
Where: X - a certain itemset N - The entire baskter of observations
So let’s perform an apriori algorithm on our data.
I will set the minimum length on 6 because that is the minimum length on the winning team from the previous chapter. The support level should be also high but by the experimental approach I’ve decided to set it on the level 0.10
## Eclat
##
## parameter specification:
## tidLists support minlen maxlen target ext
## FALSE 0.1 6 10 frequent itemsets TRUE
##
## algorithmic control:
## sparse sort verbose
## 7 -2 TRUE
##
## Absolute minimum support count: 32
##
## create itemset ...
## set transactions ...[70 item(s), 320 transaction(s)] done [0.00s].
## sorting and recoding items ... [29 item(s)] done [0.00s].
## creating bit matrix ... [29 row(s), 320 column(s)] done [0.00s].
## writing ... [2 set(s)] done [0.00s].
## Creating S4 object ... done [0.00s].
## items support count
## [1] {Renata Glasc, Sejuani, Silco, Vi, Viktor, Zac} 0.13125 42
## [2] {Reksai, Renata Glasc, Sejuani, Silco, Vi, Zac} 0.10625 34
## lhs rhs support
## [1] {Sejuani, Silco, Vi, Viktor, Zac} => {Renata Glasc} 0.13125
## [2] {Renata Glasc, Silco, Vi, Viktor, Zac} => {Sejuani} 0.13125
## [3] {Renata Glasc, Sejuani, Vi, Viktor, Zac} => {Silco} 0.13125
## [4] {Renata Glasc, Sejuani, Silco, Viktor, Zac} => {Vi} 0.13125
## [5] {Renata Glasc, Sejuani, Silco, Vi, Zac} => {Viktor} 0.13125
## [6] {Renata Glasc, Sejuani, Silco, Vi, Viktor} => {Zac} 0.13125
## [7] {Renata Glasc, Sejuani, Silco, Vi, Zac} => {Reksai} 0.10625
## [8] {Reksai, Sejuani, Silco, Vi, Zac} => {Renata Glasc} 0.10625
## [9] {Reksai, Renata Glasc, Silco, Vi, Zac} => {Sejuani} 0.10625
## [10] {Reksai, Renata Glasc, Sejuani, Vi, Zac} => {Silco} 0.10625
## [11] {Reksai, Renata Glasc, Sejuani, Silco, Zac} => {Vi} 0.10625
## [12] {Reksai, Renata Glasc, Sejuani, Silco, Vi} => {Zac} 0.10625
## confidence lift itemset
## [1] 0.9545455 2.405154 1
## [2] 0.8936170 1.682103 1
## [3] 0.8235294 1.344538 1
## [4] 1.0000000 1.649485 1
## [5] 0.7241379 3.263720 1
## [6] 1.0000000 2.758621 1
## [7] 0.5862069 1.914145 2
## [8] 0.9444444 2.379703 2
## [9] 0.9444444 1.777778 2
## [10] 0.7906977 1.290935 2
## [11] 1.0000000 1.649485 2
## [12] 0.9444444 2.605364 2
Based on the outcomes of the ECLAT algorithm I should say that to win the game I should try to include in my team especially
* {Renata Glasc, Sejuani, Silco, Vi, Viktor, Zac}
* {Reksai, Renata Glasc, Sejuani, Silco, Vi, Zac}
They are really similar. Renata Glasc, Sejuani, Silco, Vi and Zac are the same. The only difference is Vi versus Reksai. Basically the same conclusion comes from frequency based rules. But that’s not the end. Let’s perform different algorithm to check other rules.
Apriori algorithm in the opposition to ECLAT algorithm is a little bit more complicated but also has a richer outcome. Here we need to take into consideration also a confidence statistic and a lift statistic. That will cause more computation but we will receive in back richer outcome.
-> In the easiest words. Confidence measures how many transactions will occur Y when there is already an X item.
-> Here the case is more complicated because this measure checks how the conditional probability of occurrence of Y when there is an X item. So we are checking if the occurrence of X somehow can higher the probability of occurrence of the Y item.
Based on that, the Apriori algorithm is building frequency rules ### Performing on data
Once again the minimum length of the rule described by the apriori algorithm has to be 6 to be representative to this analysis
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.8 0.1 1 none FALSE TRUE 5 0.1 6
## maxlen target ext
## 10 rules TRUE
##
## Algorithmic control:
## filter tree heap memopt load sort verbose
## 0.1 TRUE TRUE FALSE TRUE 2 TRUE
##
## Absolute minimum support count: 32
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[70 item(s), 320 transaction(s)] done [0.00s].
## sorting and recoding items ... [29 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 6 done [0.00s].
## writing ... [9 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
## lhs rhs support
## [1] {Renata Glasc, Sejuani, Vi, Viktor, Zac} => {Silco} 0.13125
## [2] {Renata Glasc, Sejuani, Silco, Viktor, Zac} => {Vi} 0.13125
## [3] {Renata Glasc, Silco, Vi, Viktor, Zac} => {Sejuani} 0.13125
## [4] {Sejuani, Silco, Vi, Viktor, Zac} => {Renata Glasc} 0.13125
## [5] {Renata Glasc, Sejuani, Silco, Vi, Viktor} => {Zac} 0.13125
## [6] {Reksai, Renata Glasc, Sejuani, Silco, Zac} => {Vi} 0.10625
## [7] {Reksai, Renata Glasc, Silco, Vi, Zac} => {Sejuani} 0.10625
## [8] {Reksai, Sejuani, Silco, Vi, Zac} => {Renata Glasc} 0.10625
## [9] {Reksai, Renata Glasc, Sejuani, Silco, Vi} => {Zac} 0.10625
## confidence coverage lift count
## [1] 0.8235294 0.159375 1.344538 42
## [2] 1.0000000 0.131250 1.649485 42
## [3] 0.8936170 0.146875 1.682103 42
## [4] 0.9545455 0.137500 2.405154 42
## [5] 1.0000000 0.131250 2.758621 42
## [6] 1.0000000 0.106250 1.649485 34
## [7] 0.9444444 0.112500 1.777778 34
## [8] 0.9444444 0.112500 2.379703 34
## [9] 0.9444444 0.112500 2.605364 34
Once again I can say that the best team can be composed of Zac, Vi, Sejuani, Renata Glasc, Silco and we can then add Reksai or/and Viktor. Pretty simple but still I don’t think that this is the final answer we can get from this data.
As I’ve mentioned previously cross-tables are perfect for Correspondence Analysis. This method is mapping observations close to each other if they occur together really often or if they are correlated. The final answer is a two-dimensional plot which will show the most often occurring together champions. Seems perfect to visualize the whole TFT meta.
ctab<-crossTable(trans1, sort=TRUE)
res.ca <- CA(ctab, graph = FALSE)
options(ggrepel.max.overlaps = Inf)
fviz_ca_row(res.ca, repel = TRUE) But this graph will tell something in addition. Because the most often occurring champions are rather in the middle (they are often played with everything so no reason to give them additional meaning). More interesting is the high absolute value of dimension 1 or 2. That will tell us which comps are often played together, but they don’t occur really often at all.
So what I can see: -> top right -> yordle team comp (Veigar, Poppy, Lulu, Ziggs, Vex, Corki) and Gnar which can occur also in other teamcomps. That’s why he is more to the center.. -> Bottom right -> Hex team comp (Lucian, Swain, Nocturne, Alistar, JarvanIV, Sivir). Somehow Silco and Tamh Kench are also related to this group -> Bottom left -> Challenger team comp (Draven, Warwick, Quinn, Tryndamere and Camille) -> Top left -> Innovator team comp (Ekko, Ezreal, Zilean, Jayce, Seraphine) and Jhin which is really often played with them.
So I think that Correspondence Analysis helped to in opposition to basket market analysis distinguish popular teamcomp but more rare and which don’t occur that often in the game. But they are stll strong and winning as the data is only from winning games.
I used association rules to help myself win more matches in Teamfight Tactics games by Riot Games. The outcome is pretty helpful because both ECLAT and Apriori algorithms showed that the most often occurring winning team comp is composed of those 7 champions {Renata Glasc, Sejuani, Silco, Vi, Viktor, Zac, Reksai}.
On the other hand correspondence analysis showed also, that pretty strong team comps that are not that popular are yordles, hexs, challengers, and innovators. That analysis is somehow similar to the professional recommendations about team comps in the current 6.5 patch in team fight tactics which can be found on this link https://tftactics.gg/tierlist/team-comps. Because of that, I’m happy that machine learning methods may contribute to a higher winning rate. I hope so at least!