For this project, my group partner and I scraped Magic the Gathering Decks from the web and performed several machine learning tasks with on the deck attributes and on the attributes for the cards using Python. For my part, I focused mainly on clustering all of the different cards. The cards have attributes including: color(s), primary type(s), secondary type(s), and additional tag(s). Below are some of the results for my work on the project.
As there were several possible values for each of the categorical types, after converting the values to binary, we ended up with 463 factors. After some exploration I decided to use Isomap, instead of PCA, to reduce the dimensionality to 111. Now that I'm further along in the Master's in Analytics program, I would like to try to apply tensor decomposition to this problem to reduce the dimensionality.
I then trained a Kmeans model on 10,000 cards to create 10 clusters. Below is a 3D respresentation of the cards colored by cluster.
Here are the cluster centers for each cluster:
- cluster 0: color_B, p_Creature, s_Vampire
- cluster 1: color_B, p_Sorcery, t_Discard
- cluster 2: p_Artifact
- cluster 3: p_Land, t_Mana, t_Land
- cluster 4: color_W, color_U, color_B, p_Enchantment
- cluster 5: color_R, color_G, p_Sorcery
- cluster 6: color_R, p_Instant
- cluster 7: color_U, p_Creature, s_Human
- cluster 8: p_Land, t_Card Draw, t_Land
- cluster 9: color_W, p_Creature, s_Human
Predictions
Here are the predicted clusters for some cards using the Kmeans model that we built:
Name | Colors | Primary Types | Secondary Types | Label |
Alquist Proft, Master Sleuth | U, W | Creature | Detective, Human | 7 |
Denizen of the Deep | U | Creature | Serpent | 7 |
Cemetery Illuminator | U | Creature | Spirit | 7 |
Wash Out | U | Sorcery | 1 | |
Stromkirk Occultist | R | Creature | Horror, Vampire | 0 |
Standard Bearer | W | Creature | Flagbearer, Human | 9 |
Eye of Ramos | Artifact | 2 | ||
Souls Might | G | Sorcery | 5 | |
Torch Fiend | R | Creature | Devil | 0 |
Lord of the Unreal | U | Creature | Wizard, Human | 7 |
How to Replace Expensive cards in a Deck
Another interesting question we explored was how to create a good deck with a reasonable replacements for expensive cards. The most expensive card we found was Timetwister. If we want to replace Timetwister with a different card, according to hamming distance of the attributes, here are the closest options:
Name | Colors | Primary Type | Tags | Price | Mana Cost |
Timetwister | U | Sorcery | Card Draw, Enabler, Graveyard, Recursion | 3393.07 | 3 |
Flood of Recollection | U | Sorcery | Card Draw, Graveyard, Recursion | 0.07 | 2 |
Serum Visions | U | Sorcery | Card Draw, Enabler | 0.59 | 1 |
Portent | U | Sorcery | Card Draw, Enabler | 0.21 | 1 |
Tunnel Vision | U | Sorcery | Card Draw, Graveyard | 1.60 | 6 |
Bond of Insight | U | Sorcery | Card Draw, Mill, Graveyard, Recursion | 0.13 | 4 |
Paired Cards
We also set up the data as a network graph and analyzed which cards are in the same decks all of the time:
Name | Colors | Primary Types | Secondary Types | Size | Decks |
Ondu Cleric | W | Creature | Cleric, Ally, Kor | 2 | 11 |
Kabira Evangel | W | Creature | Cleric, Ally, Human | 2 | 11 |
Ragemonger | B, R | Creature | Shaman, Minotaur | 3 | 11 |
Neheb, the Worthy | B, R | Creature | Warrior, Minotaur | 3 | 11 |
Kragma Warcaller | B, R | Creature | Warrior, Minotaur | 3 | 11 |
Graf Rats | B | Creature | Rat | 2 | 8 |
Midnight Scavengers | B | Creature | Rogue, Human | 2 | 8 |
Stinkdrinker Daredevil | R | Creature | Rogue, Goblin | 3 | 7 |
Borderland Behemoth | R | Creature | Warrior, Giant | 3 | 7 |
Sunrise Sovereign | R | Creature | Warrior, Giant | 3 | 7 |
and which cards are in the same decks most of the time:
Name | Colors | Primary Types | Secondary Types | Decks |
Urza's Tower | Land | Tower, Urza's | 396 | |
Urza's Mine | Land | Mine, Urza's | 395 | |
Urza's Power Plant | Land | Power-Plant, Urza's | 394 | |
Sanctum of Calm Waters | U | Enchantment | Shrine | 69 |
Sanctum of Fruitful Harvest | G | Enchantment | Shrine | 67 |
Sanctum of Fruitful Harvest | G | Enchantment | Shrine | 67 |
Sanctum of All | B, G, R, U, W | Enchantment | Shrine | 65 |
Sanctum of Fruitful Harvest | G | Enchantment | Shrine | 67 |
Go-Shintai of Shared Purpose | W | Creature, Enchantment | Shrine | 65 |
Go-Shintai of Ancient Wars | R | Creature, Enchantment | Shrine | 63 |
Go-Shintai of Lost Wisdom | U | Creature, Enchantment | Shrine | 61 |
Dwarven Scorcher | R | Creature | Dwarf | 56 |
Dwarven Trader | R | Creature | Dwarf | 55 |
Enslaved Dwarf | R | Creature | Dwarf | 52 |
Liberated Dwarf | R | Creature | Dwarf | 51 |