Example #1
0
def draw_wr_hist(save=False):
    # Load the winrate matrix
    wr_matrix = load_data('Winrate')
    winrate_count = [round(rate[0] * 100, 2) for rate in wr_matrix]

    # Setup the x-axis values
    index = np.arange(len(heroes_list))

    plt.figure(figsize=(20, 30), dpi=100)
    plt.barh(index, winrate_count, height=0.5, color='peru')
    plt.ylabel('Heroes', fontsize=30, labelpad=20)
    plt.xlabel('Win Rate', fontsize=30, labelpad=20)
    plt.xlim(35,60, 1)
    plt.yticks(index, heroes_list, fontsize=12, rotation='horizontal', style='italic')
    plt.margins(y=0.01)
    plt.title('Win Rate of Each Hero', fontsize=50)
    ax = plt.gca()
    # Moidfy the title
    ax.title.set_position([.5, 1.01])

    # Make the count values to show next to the bars
    for i, v in enumerate(winrate_count):
        ax.text(v + 0.5, i - 0.3, str(v), color='darkred')
    if not save:
        plt.show()
    else:
        plt.savefig('hero_win_rate.png')
Example #2
0
def draw_heatmap(save=False):
    syn_matrix, coun_matrix = load_data('SynCoun')
    matrices = {'syn_matrix': syn_matrix, 'coun_matrix': coun_matrix}

    # Draw syn matrix
    for key in matrices:
        annotation = np.round(matrices[key], 2)
        sns.set(font_scale=2)
        fig, ax = plt.subplots(figsize=(60, 60))

        # Set pallette for colorbar
        if key == 'syn_matrix':
            cmap = "YlGnBu"
        else:
            cmap = "OrRd"
        ax = sns.heatmap(matrices[key], square=True,
                         linewidths=.1, cmap=cmap, cbar_kws={"shrink": .80},
                         xticklabels=heroes_list, yticklabels=heroes_list, annot_kws={"size": 8})
        plt.xlabel('Hero 2', fontsize=150, labelpad=40)
        plt.ylabel('Hero 1', fontsize=150, labelpad=40)

        # Modify colorbar labels
        cax = plt.gcf().axes[-1]
        cax.tick_params(labelsize=50)
        if not save:
            plt.show()
        else:
            plt.savefig(key + '.png')
Example #3
0
def draw_heroes_hist(save=False):
    X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data('Base')
    # A list of the total amount of matches for hero ID i which correspond to the index of this list
    heroes_count = []
    for i in range(TOTAL_NUM_HEROES):
        heroes_count.append(np.count_nonzero(X_matrix[:, i]) / X_matrix.shape[0])

    # Setup the x-axis values
    index = np.arange(len(heroes_list))

    plt.figure(figsize=(20, 30), dpi=100)
    plt.barh(index, heroes_count, height=0.5)
    plt.ylabel('Heroes', fontsize=30, labelpad=20)
    plt.xlabel('Percentage', fontsize=30, labelpad=20)
    plt.yticks(index, heroes_list, fontsize=12, rotation='horizontal', style='italic')
    plt.margins(y=0.01)
    plt.title('Percentage of matches where a hero is present', fontsize=50)
    ax = plt.gca()
    # Moidfy the title
    ax.title.set_position([.5, 1.01])

    # Make the count values to show next to the bars
    for i, v in enumerate(heroes_count):
        percent = round(v * 100, 2)
        ax.text(v + 0.01, i - 0.3, str(percent), color='blue')
    if not save:
        plt.show()
    else:
        plt.savefig('hero_num_matches.png')
Example #4
0
def draw_rf_trees():
    X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data('Base')
    number_trees = np.linspace(100, 1000, 10, dtype=int)
    results = []

    for tree in tqdm(number_trees):
        rf = RandomForestClassifier(random_state=1411, n_estimators=tree, warm_start=True)
        rf.fit(X_train, y_train)
        results.append(rf.score(X_test, y_test))

    plt.plot(number_trees, results)
    plt.xlabel('Number of trees')
    plt.ylabel('Test Accuracy')
    plt.savefig('RF tree.png')
Example #5
0
def web_heatmap():
    syn_matrix, coun_matrix = load_data('SynCoun')
    matrices = {'syn_matrix': syn_matrix, 'coun_matrix': coun_matrix}

    for key in matrices:
        if key == 'syn_matrix':
            cmap = "YlGnBu"
            title = 'Heatmap of synergistic relationship between heroes'
        else:
            cmap = "YlOrRd"
            title = 'Heatmap of antagonistic relationship of Hero 1 (y) against Hero 2 (x)'

        trace = [go.Heatmap(z=matrices[key], x=heroes_list, y=heroes_list, colorscale=cmap)]
        layout = go.Layout(title=title, xaxis=dict(title='Hero 2'),
                           yaxis=dict(title='Hero 1', autorange='reversed'))
        fig = go.Figure(data=trace, layout=layout)

        py.iplot(fig, filename=key + "_heatmap")
Example #6
0
    except ValueError:
        print("Invalid input")
        exit()
    else:
        data_name = which_data
        if which_data == 1:
            data_name = 'Base'
        elif which_data == 2:
            data_name = 'Perf'
        else:
            print("Invalid input")
            exit()

    # Load data file and define matrices
    try:
        X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data(
            data_name)
    except:
        print('Could not locate data, run "preprocess_data.py" first.')
        exit()
    else:
        while True:
            try:
                user_input = int(
                    input(
                        "Lists of options to input:\n1. Fill syn and coun matrices and save them \n"
                        "2. Load the %s dataset and append the synergy counter matrices\n3. Exit\n"
                        % data_name))
            except ValueError:
                print("Invalid input")
                continue
Example #7
0
    print(
        'ROC AUC score of logistic regression classifier on test set: {:.2f} \n'
        .format(roc_auc_score(y_test, y_pred)))
    print("Classification Report:\n")
    print(classification_report(y_test, y_pred))
    print("Confusion Matrix: \n")
    print(confusion_matrix(y_test, y_pred))
    return clf


if __name__ == '__main__':
    np.random.seed(1411)

    dataset = input("What dataset to use: \n")
    number_cv = int(input("How many cv folds: \n"))
    X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data(
        type=dataset, scale=False)

    # Output results to txt
    text_file = os.path.join(BASE_DIR, TRAINED_MODEL_DIR,
                             dataset + 'LogModel.txt')
    sys.stdout = open(text_file, "w")

    print("Fitting model: \n")
    # Fitting basic model
    logreg = fit_model()

    predict(logreg, X_test, y_test)
    cross_validation(logreg, X_matrix, y_matrix, cv=number_cv)

    print()
    print("#" * 100)
Example #8
0
    tmp_threshold = model.score(X_test_new, y_test_new)
    print("Number of matches where " + text + " are removed: %s" % X_new.shape[0])
    print("Test accuracy is: %s" % tmp_threshold)
    print("#" * 100)
    print()

    return tmp_threshold




if __name__ == '__main__':
    np.random.seed(1411)
    model = LogisticRegression()

    X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data('Base')
    model.fit(X_train, y_train)

    highest_coefs = np.argsort(model.coef_[0])[::-1]
    heroes_list = get_heroes_names()

    # Base threshold
    threshold = model.score(X_test, y_test)
    wr_matrix = load_data('Winrate')
    print("Test accuracy of base: %s" % threshold)
    print("#" * 100)
    print()

    # Setup simluation test information
    sim_count = 1
    num_simulations = 100
Example #9
0
    def client_exit(self):
        exit()


class ChooseModels:
    def __init__(self, master):
        Frame.__init__(master)


if __name__ == '__main__':
    # Get the list of heroes and list of core and support heroes
    heroes_list, heroes_dict, core_list, support_list = get_heroes()
    get_heroes_img()
    # Load features data
    syn_matrix, coun_matrix = load_data('SynCoun')
    wr_matrix = load_data('Winrate')
    time_matrix, pick_matrix = load_data('TimePickWr')

    root = Tk()

    root.wm_state('zoomed')
    rows, columns = 0, 0
    while rows < 40:
        root.grid_rowconfigure(rows, weight=20)
        rows += 1

    while columns < 80:
        root.grid_columnconfigure(columns, weight=20)
        columns += 1
Example #10
0
            team_wr.append(hero_pick_wr)
        return np.mean(team_wr)
    else:
        return 0


if __name__ == '__main__':
    # Create new matrices
    win_pick_matrix = np.zeros((TOTAL_NUM_HEROES, 5))
    total_pick_matrix = np.zeros((TOTAL_NUM_HEROES, 5))

    win_time_matrix = np.zeros((TOTAL_NUM_HEROES, 5))
    total_time_matrix = np.zeros((TOTAL_NUM_HEROES, 5))

    # Load the base data with match duration, pick order information
    X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data('TimePickBase')
    X_matrix2, y_matrix2, X_train2, X_test2, y_train2, y_test2 = load_data('TimePickPerfBase')

    # Filling the matrices
    pick_matrix = fill_pick_matrix()
    print("#" * 100)
    time_matrix = fill_time_matrix()
    print("#" * 100)

    # Add 4 new columns for the pick order and match duration feature,, 2 for each team
    extra_columns = np.zeros((len(X_matrix), 4))
    X_matrix = np.append(X_matrix, extra_columns, axis=1)
    X_matrix2 = np.append(X_matrix2, extra_columns, axis=1)

    for match in range(len(X_matrix)):
        # Get the heroes in both teams
Example #11
0
                            "\n9. Test accuracy vs Number of trees in BaseRF\n"))
 except ValueError:
     print("Invalid input")
     continue
 else:
     if user_input not in list_of_options:
         print("Invalid input")
     elif user_input == 1:
         draw_heroes_hist(save=True)
     elif user_input == 2:
         draw_heatmap(save=True)
     elif user_input == 3:
         web_heatmap()
     elif user_input == 4:
         which_data = input("Which data to load?\n")
         X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data(which_data)
         which_model = input("Which model to load?\n")
         model = load_model(which_data + which_model)
         graph_name = input("Enter model name\n")
         draw_lc_cv(model, graph_name,
                             10, X_matrix, y_matrix, save=True)
     elif user_input == 5:
         pass
     elif user_input == 6:
         pass
     elif user_input == 7:
         draw_wr_hist(save=True)
     elif user_input == 8:
         which_data = input("Which data to load?\n")
         X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data(which_data)
         which_model = input("XGB or RF?\n")
Example #12
0
import time
from src.Models.load_data import *
"""
Measure the time taken for each model to perform 1000 predictions
"""
models = ['Log', 'RF', 'SVC', 'MLP', 'XGB']
results = {}
X_matrix, y_matrix, X_train, X_test, y_train, y_test = load_data('Base')

for model_name in models:
    estimator = load_model('Base' + model_name)
    start = time.time()
    for i in range(1000):
        estimator.predict(X_test[i].reshape(1, -1))
    runtimes = time.time() - start
    results[model_name] = runtimes

print(results)