728x90
바로 위에 업로드한 코드를 돌려서 생성된 csv 파일을 가지고
가장 승률이 좋은 조합들을 찾는 코드입니다.
import numpy as np
import pandas as pd
from google.cloud import bigquery
from google.oauth2 import service_account
from google.cloud import storage
import pprint
import json
credentials = service_account.Credentials.from_service_account_file('admin.json')
bigquery_client = bigquery.Client(credentials=credentials, project='cslee-323908')
storage_client = storage.Client(credentials=credentials, project='cslee-323908')
qry = "select id, key from cslee.ChampData"
champdata = bigquery_client.query(qry).to_dataframe()
champname = champdata.drop('key', axis=1)
allcham = champdata.drop('id', axis=1)
allcham2 = np.array(allcham)
chamlist = np.array(allcham2).flatten().tolist()
champname = np.array(champname)
champname = np.array(champname).flatten().tolist()
def f2(x):
return x[1]
win_df = pd.read_csv("C:/RiotProject/practice/finalwin.csv")
lose_df = pd.read_csv("C:/RiotProject/practice/finallose.csv")
all_df = pd.concat([win_df, lose_df])
def best_bottom():
win_bot = win_df.groupby(['BOT','SUP'])
win_bot = win_bot.size()
win_bot = pd.DataFrame(win_bot).reset_index()
win_bot.columns = ['BOT','SUP', 'win_count']
win_bot = win_bot.sort_values(by=['win_count'], axis=0, ascending=False)
win_bot.reset_index(inplace=True)
all_bot = all_df.groupby(['BOT','SUP'])
all_bot = all_bot.size()
all_bot = pd.DataFrame(all_bot).reset_index()
all_bot.columns = ['BOT','SUP', 'all_count']
all_bot = all_bot.sort_values(by=['all_count'], axis=0, ascending=False)
all_bot.reset_index(inplace=True)
final = win_bot.copy()
final['WinRate'] = ((win_bot['win_count'] / all_bot['all_count'])*100)
final2 = final[final['win_count']>10000]
final2 = final2.sort_values(by=['WinRate'], ascending=False)
final2.reset_index(inplace=True)
for _ in final2.index:
for i, j in zip(chamlist, champname):
try:
final2.loc[final2['BOT'] == i, 'BOT'] = j
final2.loc[final2['SUP'] == i, 'SUP'] = j
except:
pass
final2 = final2[['BOT','SUP','win_count','WinRate']]
return final2
def best_jugmid():
win_bot = win_df.groupby(['JUG','MID'])
win_bot = win_bot.size()
win_bot = pd.DataFrame(win_bot).reset_index()
win_bot.columns = ['JUG','MID', 'win_count']
win_bot = win_bot.sort_values(by=['win_count'], axis=0, ascending=False)
win_bot.reset_index(inplace=True)
all_bot = all_df.groupby(['JUG','MID'])
all_bot = all_bot.size()
all_bot = pd.DataFrame(all_bot).reset_index()
all_bot.columns = ['JUG','MID', 'all_count']
all_bot = all_bot.sort_values(by=['all_count'], axis=0, ascending=False)
all_bot.reset_index(inplace=True)
final = win_bot.copy()
final['WinRate'] = ((win_bot['win_count'] / all_bot['all_count'])*100)
final2 = final[final['win_count']>5000]
final2 = final2.sort_values(by=['WinRate'], ascending=False)
final2.reset_index(inplace=True)
for _ in final2.index:
for i, j in zip(chamlist, champname):
try:
final2.loc[final2['JUG'] == i, 'JUG'] = j
final2.loc[final2['MID'] == i, 'MID'] = j
except:
pass
final2 = final2[['JUG','MID','win_count','WinRate']]
return final2
def best_team():
win_bot = win_df.groupby(['TOP','JUG','MID','BOT','SUP'])
win_bot = win_bot.size()
win_bot = pd.DataFrame(win_bot).reset_index()
win_bot.columns = ['TOP','JUG','MID','BOT','SUP', 'win_count']
win_bot = win_bot.sort_values(by=['win_count'], axis=0, ascending=False)
win_bot.reset_index(inplace=True)
all_bot = all_df.groupby(['TOP','JUG','MID','BOT','SUP'])
all_bot = all_bot.size()
all_bot = pd.DataFrame(all_bot).reset_index()
all_bot.columns = ['TOP','JUG','MID','BOT','SUP', 'all_count']
all_bot = all_bot.sort_values(by=['all_count'], axis=0, ascending=False)
all_bot.reset_index(inplace=True)
final = win_bot.copy()
final['WinRate'] = ((win_bot['win_count'] / all_bot['all_count'])*100)
final2 = final[final['win_count']>20]
final2 = final2.sort_values(by=['WinRate'], ascending=False)
final2.reset_index(inplace=True)
for _ in final2.index:
for i, j in zip(chamlist, champname):
try:
final2.loc[final2['TOP'] == i, 'TOP'] = j
final2.loc[final2['JUG'] == i, 'JUG'] = j
final2.loc[final2['MID'] == i, 'MID'] = j
final2.loc[final2['BOT'] == i, 'BOT'] = j
final2.loc[final2['SUP'] == i, 'SUP'] = j
except:
pass
final2 = final2[['TOP','JUG','MID','BOT','SUP','win_count','WinRate']]
return final2
print(best_jugmid())
print(best_bottom())
print(best_team())
25분 이상 게임만 수집했기 때문에 데이터가 부족할 수 있지만 그부분을 조정하고 원하는 포지션을 추가하거나 제거하면서 베스트 조합을 찾아낼 수 있습니다.
728x90
'프로젝트 > Riot LoL' 카테고리의 다른 글
챔피언 티어정보 만들기 (0) | 2021.10.19 |
---|---|
RiotAPI를 가지고 인게임데이터 csv로 저장하는 자동화 코드 (0) | 2021.10.19 |
포지션정보넣으면 승률+밴픽률순서로 출력 (0) | 2021.10.19 |
챔피언 별 밴픽률을 구해보자 (0) | 2021.09.24 |
Modeling을 위한 전처리를 해보자 (0) | 2021.09.15 |