It's not the example of usage, just me trying to make something intresting with the data (failed in this version).
Would be nice to find how good one hero works in combination with another. I thought it is possible to count such metric by doing the following:
In [1]:
import json
import numpy as np
import networkx as nx
from pprint import pprint
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
# I extracted picks and result from huge dumb of matches
with open('../atod/data/picks.json', 'r') as fp:
matches = json.load(fp)
print(len(matches))
In [3]:
n_heroes = 115
C = [[0 for _ in range(n_heroes)] for _ in range(n_heroes)]
# the "small wright" what would be added and subtracted
w = 1 / len(matches)
In [4]:
def add_weight(C, heroes, w):
done = False
for i, hero1 in enumerate(heroes):
for hero2 in heroes[i+1:]:
C[hero1][hero2] += w
C[hero2][hero1] += w
In [5]:
for match_id, match in matches.items():
if not isinstance(match, dict):
continue
# get winner side id. Radiant is 0, Dire is 1
winner = 0 if match['radiant_win'] else 1
# add w to all the pairs of winner heroes
add_weight(C, match[str(winner)], w)
# subtract from all the loser pairs w
add_weight(C, match[str(abs(winner-1))], -w)
In [6]:
heroes_connections = np.array(C)
heroes_graph = nx.from_numpy_matrix(heroes_connections)
# heroes_connections = heroes_connections[1:,1:] + heroes_connections.min()
positive_edges = [(u, v) for u, v, d in
heroes_graph.edges(data=True) if d['weight'] >0]
In [7]:
pos=nx.spring_layout(heroes_graph)
nx.draw_networkx_nodes(heroes_graph, pos, node_size=20)
nx.draw_networkx_edges(heroes_graph, pos, edgelist=positive_edges,
width=.1)
# matplotlib.rcParams['figure.figsize'] = (18, 16)
plt.show()
In [ ]: