英雄联盟想必大多数读者不会陌生,这是一款来自拳头,由腾讯代理的大型网络游戏,如今一进网吧,你就能发现一大片玩英雄联盟的人。在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,群里学习资料免费赠送给你们喔!
本文来自网络,若有侵权,请联系小编删除!