英雄聯盟想必大多數讀者不會陌生,這是一款來自拳頭,由騰訊代理的大型網絡遊戲,如今一進網吧,你就能發現一大片玩英雄聯盟的人。在2017年中國戰隊無緣鳥巢的世界總決賽後,一大片人選擇了棄遊,只是終究沒躲過「真香定理」,在2018年的中旬,又有大批戰友又回到熟悉的召喚師峽谷戰場,時至今日,英雄聯盟已經不只僅是一款遊戲,一個電競項目了,它已經成爲了咱們生活的快樂源泉了。python
問君能有幾多愁,輔助閃現搶人頭;問君能有幾多愁,卡牌千里送人頭。問君能有幾多愁,皇子開大關隊友;清明時節雨紛紛,各類隊友各類坑。別人笑我不買眼,我笑別人浪費錢;孤帆遠影碧空盡,草叢驚現蠻易信 。相見時難別亦難,遇見趙信菊花殘;我自橫刀向天笑,剁人只需用三刀。苦練盲僧千百次, 盲目對戰N 屢次;戰輸不下五十次, 砸得鼠標要出事;舉杯邀明月,草叢遇蓋倫。mysql
鑑於如今喜歡英雄聯盟的大佬如此之多,爲了幫助你們儘快的拿到首勝,小編爬取並分析了1982餘場LOL數據。很是神奇的是!在開局以前可以高几率的預測本局的勝負!讓你提早作好心理準備。算法
假設sql
假設沒有王者等大神代玩小號數據庫
假設沒有代練json
假設沒有由於半途被媳婦抓到而掛機的行爲網絡
假設沒有忽然掉網連不上去的行爲app
遊戲對戰數據獲取dom
國服:騰訊遊戲平臺非官方API - http://www.games-cube.com/機器學習
外服:Riot開發者平臺API- https://developer.riotgames.com/
import numpy as np import pymysql, random, json def connect_db(database): try: conn = pymysql.connect(host='localhost', port=3306, user='root', password='zandaoguang', db=database, charset='utf8') return conn except: print ('Exception: MySQL Connection') return None
分析和訓練數據
利用神經網絡(neural_network)、隨機森林(random_forest)和支持向量機(support_vector)等若干智能算法進行訓練和迴歸,最終進行比較效果。
下面爲神經網絡部分代碼:
from __future__ import print_function import numpy as np #np.random.seed(1337) # for reproducibility from keras.datasets import mnist from keras.models import Sequential, load_model from keras.layers import Dense, Dropout, Activation, Flatten from keras.layers import Convolution2D, MaxPooling2D from keras.utils import np_utils from keras import backend as K from keras.optimizers import SGD, Adam, RMSprop import gzip import sys from six.moves import cPickle from fetcher import * batch_size = 256 nb_classes = 2 nb_epoch = 100 champion_dict = fetch_champion_dict("champion136.json") champion_num = len(champion_dict) X_train = X_train.astype('int8') X_test = X_test.astype('int8') print('X_train shape:', X_train.shape) print(X_train.shape[0], 'train samples') print(X_test.shape[0], 'test samples') Y_train = np_utils.to_categorical(y_train, nb_classes) Y_test = np_utils.to_categorical(y_test, nb_classes) model = Sequential() model.add(Dense(1500, input_dim = champion_num, init='uniform')) model.add(Activation('sigmoid')) model.add(Dense(2)) model.add(Activation('softmax')) model.summary() model.compile(loss='categorical_crossentropy', optimizer=RMSprop(), metrics=['accuracy']) history = model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1, validation_data=(X_test, Y_test)) score = model.evaluate(X_test, Y_test, verbose=0) print('Test score:', score[0]) print('Test accuracy:', score[1])
隨機森林代碼:
from sklearn.ensemble import RandomForestClassifier from sklearn.externals import joblib from fetcher import * champion_dict = fetch_champion_dict("champion136.json") champion_num = len(champion_dict) X_train, y_train, X_test, y_test = fetch_one_side_riot('12', 'MATCHED_GAME', 'KING_PORO', 'KINGPORO', ('1492660800000', '1493740800000'), champion_dict) clf = RandomForestClassifier(n_estimators=500, n_jobs=2) clf.fit(X_train, y_train) train_score = clf.score(X_train, y_train) print ("Train Score = "+str(train_score)) test_score = clf.score(X_test, y_test) print ("Test Score = "+str(test_score))
支持向量機代碼:
from sklearn.externals import joblib from sklearn import svm from fetcher import * champion_dict = fetch_champion_dict("champion136.json") champion_num = len(champion_dict) X_train, y_train, X_test, y_test = fetch_one_side_riot('12', 'MATCHED_GAME', 'ARAM_UNRANKED_5x5', 'ARAM', ('1492660800000', '1493740800000'), champion_dict) clf = svm.SVC() clf.fit(X_train, y_train) train_score = clf.score(X_train, y_train) print ("Train Score = "+str(train_score)) test_score = clf.score(X_test, y_test) print ("Test Score = "+str(test_score))
遊戲對打敗負預測
根據雙方英雄陣容,預測獲勝方的準確率(%)
PS:因爲阿廣近期沒有玩英雄聯盟,因此分析的數據爲2017年的遊戲數據。
只根據本方英雄陣容,預測本方可否獲勝的準確率(%)
指望研究的問題
注:因爲數據量過小,之後能收集到更多的數據,是但願能夠對上面以及更多的方向進行研究。
結論
雖然咱們經過機器學習算法能夠預測這把的輸贏,可是這畢竟不是咱們最後的結果。玩英雄聯盟和愛情相似,明明知道是咱們不可能,卻堅持去追求,這正是愛的美麗。也許沒有什麼結果,可那過程自己的美麗便足夠用一輩子去品味。
遊戲原本的用意是給你們放鬆心情,釋放壓力的(職業選手就不一樣了)。因此咱們必定要把握好時間,對於沉迷遊戲這種的就大可沒必要了,好的遊戲應該是帶給咱們快樂,假如每天沉迷遊戲,墮落不已,那就落入了錯誤的深淵了。固然好的方面也不是沒有,看廠長、UZI這些選手就是好的表明啊!以上就是本文的所有內容,喜歡的小夥伴點個讚唄!
寫在最後:
若是你們在學習Python的路上,或者打算學習Python須要學習資料,能夠加羣571799375,羣裏學習資料免費贈送給你們喔!
本文來自網絡,若有侵權,請聯繫小編刪除!