Oh-Seung-Rok

안녕하세요. 정량적인 분석을 통해 제품-서비스를 개선하고 소비자들의 욕구를 먼저 파악하는 분석가가 되고 싶은 오승록입니다. 포트폴리오 [https://seungrok0317.com]

Kaggle - League of Legends

19 Mar 2021 » Kaggle

League of Legends

라이브러리 설정, 데이터 읽어들이기

  • 데이터 셋 : https://www.kaggle.com/bobbyscience/league-of-legends-diamond-ranked-games-10-min

  • League of Legends 게임 시작 10분이내 일어나는 여러 상황을 통해 승패를 예측하는 데이터 셋이다.

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv('high_diamond_ranked_10min.csv')
pd.set_option('display.max_columns', None)
df.sample(10)
gameIdblueWinsblueWardsPlacedblueWardsDestroyedblueFirstBloodblueKillsblueDeathsblueAssistsblueEliteMonstersblueDragonsblueHeraldsblueTowersDestroyedblueTotalGoldblueAvgLevelblueTotalExperienceblueTotalMinionsKilledblueTotalJungleMinionsKilledblueGoldDiffblueExperienceDiffblueCSPerMinblueGoldPerMinredWardsPlacedredWardsDestroyedredFirstBloodredKillsredDeathsredAssistsredEliteMonstersredDragonsredHeraldsredTowersDestroyedredTotalGoldredAvgLevelredTotalExperienceredTotalMinionsKilledredTotalJungleMinionsKilledredGoldDiffredExperienceDiffredCSPerMinredGoldPerMin
45554445985804119417281100174597.219021231642929129623.11745.915102720000145307.01772519164-2929-129619.11453.0
37564505375338121305582110167097.01885522268728209522.21670.915715580000159816.81676022444-728-209522.41598.1
52224495636315113114350000172627.018608248521673120024.81726.212103422110155896.81740819769-1673-120019.71558.9
21044490390200113307521100172477.219189249632152257524.91724.717215770000150956.81661417840-2152-257517.81509.5
24004381068813042117381100161466.616204196432037-28119.61614.619503730000141096.41648517257-203728117.21410.9
35124419275391015206650000158567.01772322447-4606022.41585.616216671100163166.81766323836460-6023.81631.6
57494464945993015118782110178987.41941123258942130023.21789.816207860000169567.01811124543-942-130024.51695.6
9082451844403101651108121100173577.01838819159-31057019.11735.7272081091010176677.21781819456310-57019.41766.7
72604479460532121303431100148506.81796722657-85884722.61485.021314350000157086.81712023944858-84723.91570.8
42724504894173017118190000167636.617181209363371117320.91676.318101820000133926.41600819550-3371-117319.51339.2
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 9879 entries, 0 to 9878
Data columns (total 40 columns):
 #   Column                        Non-Null Count  Dtype  
---  ------                        --------------  -----  
 0   gameId                        9879 non-null   int64  
 1   blueWins                      9879 non-null   int64  
 2   blueWardsPlaced               9879 non-null   int64  
 3   blueWardsDestroyed            9879 non-null   int64  
 4   blueFirstBlood                9879 non-null   int64  
 5   blueKills                     9879 non-null   int64  
 6   blueDeaths                    9879 non-null   int64  
 7   blueAssists                   9879 non-null   int64  
 8   blueEliteMonsters             9879 non-null   int64  
 9   blueDragons                   9879 non-null   int64  
 10  blueHeralds                   9879 non-null   int64  
 11  blueTowersDestroyed           9879 non-null   int64  
 12  blueTotalGold                 9879 non-null   int64  
 13  blueAvgLevel                  9879 non-null   float64
 14  blueTotalExperience           9879 non-null   int64  
 15  blueTotalMinionsKilled        9879 non-null   int64  
 16  blueTotalJungleMinionsKilled  9879 non-null   int64  
 17  blueGoldDiff                  9879 non-null   int64  
 18  blueExperienceDiff            9879 non-null   int64  
 19  blueCSPerMin                  9879 non-null   float64
 20  blueGoldPerMin                9879 non-null   float64
 21  redWardsPlaced                9879 non-null   int64  
 22  redWardsDestroyed             9879 non-null   int64  
 23  redFirstBlood                 9879 non-null   int64  
 24  redKills                      9879 non-null   int64  
 25  redDeaths                     9879 non-null   int64  
 26  redAssists                    9879 non-null   int64  
 27  redEliteMonsters              9879 non-null   int64  
 28  redDragons                    9879 non-null   int64  
 29  redHeralds                    9879 non-null   int64  
 30  redTowersDestroyed            9879 non-null   int64  
 31  redTotalGold                  9879 non-null   int64  
 32  redAvgLevel                   9879 non-null   float64
 33  redTotalExperience            9879 non-null   int64  
 34  redTotalMinionsKilled         9879 non-null   int64  
 35  redTotalJungleMinionsKilled   9879 non-null   int64  
 36  redGoldDiff                   9879 non-null   int64  
 37  redExperienceDiff             9879 non-null   int64  
 38  redCSPerMin                   9879 non-null   float64
 39  redGoldPerMin                 9879 non-null   float64
dtypes: float64(6), int64(34)
memory usage: 3.0 MB

EDA 및 기초 통계 분석

df.describe()
gameIdblueWinsblueWardsPlacedblueWardsDestroyedblueFirstBloodblueKillsblueDeathsblueAssistsblueEliteMonstersblueDragonsblueHeraldsblueTowersDestroyedblueTotalGoldblueAvgLevelblueTotalExperienceblueTotalMinionsKilledblueTotalJungleMinionsKilledblueGoldDiffblueExperienceDiffblueCSPerMinblueGoldPerMinredWardsPlacedredWardsDestroyedredFirstBloodredKillsredDeathsredAssistsredEliteMonstersredDragonsredHeraldsredTowersDestroyedredTotalGoldredAvgLevelredTotalExperienceredTotalMinionsKilledredTotalJungleMinionsKilledredGoldDiffredExperienceDiffredCSPerMinredGoldPerMin
count9.879000e+039879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.0000009879.000000
mean4.500084e+090.49903822.2882882.8248810.5048086.1839256.1376666.6451060.5499540.3619800.1879740.05142216503.4555126.91600417928.110133216.69956550.50966714.414111-33.62030621.6699561650.34555122.3679522.7231500.4951926.1376666.1839256.6621120.5731350.4130980.1600360.04302116489.0414016.92531617961.730438217.34922651.313088-14.41411133.62030621.7349231648.904140
std2.757328e+070.50002418.0191772.1749980.5000023.0110282.9338184.0645200.6255270.4805970.3907120.2443691535.4466360.3051461200.52376421.8584379.8982822453.3491791920.3704382.185844153.54466418.4574272.1383560.5000022.9338183.0110284.0606120.6264820.4924150.3666580.2169001490.8884060.3053111198.58391221.91166810.0278852453.3491791920.3704382.191167149.088841
min4.295358e+090.0000005.0000000.0000000.0000000.0000000.0000000.0000000.0000000.0000000.0000000.00000010730.0000004.60000010098.00000090.0000000.000000-10830.000000-9333.0000009.0000001073.0000006.0000000.0000000.0000000.0000000.0000000.0000000.0000000.0000000.0000000.00000011212.0000004.80000010465.000000107.0000004.000000-11467.000000-8348.00000010.7000001121.200000
25%4.483301e+090.00000014.0000001.0000000.0000004.0000004.0000004.0000000.0000000.0000000.0000000.00000015415.5000006.80000017168.000000202.00000044.000000-1585.500000-1290.50000020.2000001541.55000014.0000001.0000000.0000004.0000004.0000004.0000000.0000000.0000000.0000000.00000015427.5000006.80000017209.500000203.00000044.000000-1596.000000-1212.00000020.3000001542.750000
50%4.510920e+090.00000016.0000003.0000001.0000006.0000006.0000006.0000000.0000000.0000000.0000000.00000016398.0000007.00000017951.000000218.00000050.00000014.000000-28.00000021.8000001639.80000016.0000002.0000000.0000006.0000006.0000006.0000000.0000000.0000000.0000000.00000016378.0000007.00000017974.000000218.00000051.000000-14.00000028.00000021.8000001637.800000
75%4.521733e+091.00000020.0000004.0000001.0000008.0000008.0000009.0000001.0000001.0000000.0000000.00000017459.0000007.20000018724.000000232.00000056.0000001596.0000001212.00000023.2000001745.90000020.0000004.0000001.0000008.0000008.0000009.0000001.0000001.0000000.0000000.00000017418.5000007.20000018764.500000233.00000057.0000001585.5000001290.50000023.3000001741.850000
max4.527991e+091.000000250.00000027.0000001.00000022.00000022.00000029.0000002.0000001.0000001.0000004.00000023701.0000008.00000022224.000000283.00000092.00000011467.0000008348.00000028.3000002370.100000276.00000024.0000001.00000022.00000022.00000028.0000002.0000001.0000001.0000002.00000022732.0000008.20000022269.000000289.00000092.00000010830.0000009333.00000028.9000002273.200000
  • 당장 보이는 것은 blue 경우 정글에서 red보다 herald를 죽일 확률이 높고 red는 그 반대.
# correlation 히트맵 시각화

fig = plt.figure(figsize=(4,10))
sns.heatmap(df.corr()[['blueWins']], annot=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1d802aed648>

output_11_1

  • 전체 골드 수급량, 골드-경험치 수급이 승리로 이어질 가능성이 높다.
df.corr()
gameIdblueWinsblueWardsPlacedblueWardsDestroyedblueFirstBloodblueKillsblueDeathsblueAssistsblueEliteMonstersblueDragonsblueHeraldsblueTowersDestroyedblueTotalGoldblueAvgLevelblueTotalExperienceblueTotalMinionsKilledblueTotalJungleMinionsKilledblueGoldDiffblueExperienceDiffblueCSPerMinblueGoldPerMinredWardsPlacedredWardsDestroyedredFirstBloodredKillsredDeathsredAssistsredEliteMonstersredDragonsredHeraldsredTowersDestroyedredTotalGoldredAvgLevelredTotalExperienceredTotalMinionsKilledredTotalJungleMinionsKilledredGoldDiffredExperienceDiffredCSPerMinredGoldPerMin
gameId1.0000000.0009850.005361-0.012057-0.011577-0.038993-0.013160-0.0233290.0165990.0089620.015551-0.007467-0.033754-0.040956-0.040852-0.002917-0.004193-0.014670-0.012315-0.002917-0.0337540.007405-0.0011970.011577-0.013160-0.038993-0.0086640.0172960.0174160.0061630.003557-0.010622-0.012419-0.021187-0.0051180.0060400.0146700.012315-0.005118-0.010622
blueWins0.0009851.0000000.0000870.0442470.2017690.337358-0.3392970.2766850.2219440.2137680.0923850.1155660.4172130.3578200.3961410.2249090.1314450.5111190.4895580.2249090.417213-0.023671-0.055400-0.201769-0.3392970.337358-0.271047-0.221551-0.209516-0.097172-0.103696-0.411396-0.352127-0.387588-0.212171-0.110994-0.511119-0.489558-0.212171-0.411396
blueWardsPlaced0.0053610.0000871.0000000.0344470.0032280.018138-0.0026120.0332170.0198920.0176760.0101040.0094620.0197250.0343490.031719-0.0339250.0105010.0158000.027943-0.0339250.019725-0.0129060.115549-0.003228-0.0026120.018138-0.009009-0.022817-0.020121-0.011964-0.008225-0.005685-0.008882-0.013000-0.0123950.001224-0.015800-0.027943-0.012395-0.005685
blueWardsDestroyed-0.0120570.0442470.0344471.0000000.0177170.033748-0.0731820.0677930.0417000.0405040.016940-0.0091500.0600540.0602940.0674620.111028-0.0234520.0785850.0779460.1110280.0600540.1359660.123919-0.017717-0.0731820.033748-0.046212-0.034509-0.034439-0.012712-0.023943-0.067467-0.059090-0.0573140.040023-0.035732-0.078585-0.0779460.040023-0.067467
blueFirstBlood-0.0115770.2017690.0032280.0177171.0000000.269425-0.2479290.2294850.1516030.1343090.0775090.0833160.3120580.1776170.1903650.1256420.0181900.3785110.2406650.1256420.312058-0.019142-0.043304-1.000000-0.2479290.269425-0.201140-0.141627-0.135327-0.060246-0.069584-0.301479-0.182602-0.194920-0.156711-0.024559-0.378511-0.240665-0.156711-0.301479
blueKills-0.0389930.3373580.0181380.0337480.2694251.0000000.0040440.8136670.1785400.1704360.0761950.1803140.8887510.4348670.472155-0.030880-0.1125060.6541480.583730-0.0308800.888751-0.034239-0.092278-0.2694250.0040441.000000-0.020344-0.224564-0.207949-0.104423-0.082491-0.161127-0.412219-0.462333-0.472203-0.214454-0.654148-0.583730-0.472203-0.161127
blueDeaths-0.013160-0.339297-0.002612-0.073182-0.2479290.0040441.000000-0.026372-0.204764-0.188852-0.095527-0.071441-0.162572-0.414755-0.460122-0.468560-0.228102-0.640000-0.577613-0.468560-0.1625720.0081020.0386720.2479291.0000000.0040440.8040230.1633400.1507460.0766390.1567800.8857280.4333830.464584-0.040521-0.1002710.6400000.577613-0.0405210.885728
blueAssists-0.0233290.2766850.0332170.0677930.2294850.813667-0.0263721.0000000.1490430.1708730.0284340.1236630.7483520.2926610.303022-0.062035-0.1340230.5497610.437002-0.0620350.748352-0.032474-0.064501-0.229485-0.0263720.813667-0.007481-0.182985-0.189563-0.058074-0.060880-0.133948-0.356928-0.396652-0.337515-0.160915-0.549761-0.437002-0.337515-0.133948
blueEliteMonsters0.0165990.2219440.0198920.0417000.1516030.178540-0.2047640.1490431.0000000.7810390.6402710.1666440.2393960.2035300.2327740.1187620.1983780.2814640.2639910.1187620.239396-0.017292-0.005288-0.151603-0.2047640.178540-0.156764-0.455139-0.471754-0.144104-0.052029-0.216616-0.169649-0.189816-0.074838-0.087893-0.281464-0.263991-0.074838-0.216616
blueDragons0.0089620.2137680.0176760.0405040.1343090.170436-0.1888520.1708730.7810391.0000000.0203810.0397500.1864130.1606830.1790830.0866860.1595950.2338750.2114960.0866860.186413-0.027102-0.023049-0.134309-0.1888520.170436-0.162406-0.506546-0.631930-0.016827-0.032865-0.192871-0.149806-0.159485-0.059803-0.098446-0.233875-0.211496-0.059803-0.192871
blueHeralds0.0155510.0923850.0101040.0169400.0775090.076195-0.0955270.0284340.6402710.0203811.0000000.2179010.1539740.1282010.1523860.0835090.1212910.1629430.1624960.0835090.1539740.0056530.019885-0.077509-0.0955270.076195-0.051209-0.1055930.022035-0.210012-0.042872-0.109557-0.087337-0.107718-0.046253-0.019622-0.162943-0.162496-0.046253-0.109557
blueTowersDestroyed-0.0074670.1155660.009462-0.0091500.0833160.180314-0.0714410.1236630.1666440.0397500.2179011.0000000.3509410.1244530.1393980.0922910.0081650.2940600.2183200.0922910.3509410.003660-0.038623-0.083316-0.0714410.180314-0.036254-0.041099-0.028482-0.0319730.011738-0.122465-0.204429-0.210167-0.186879-0.038505-0.294060-0.218320-0.186879-0.122465
blueTotalGold-0.0337540.4172130.0197250.0600540.3120580.888751-0.1625720.7483520.2393960.1864130.1539740.3509411.0000000.6169680.6761930.2849020.0907690.8168030.7293450.2849021.000000-0.020069-0.090611-0.312058-0.1625720.888751-0.128921-0.227236-0.201794-0.117257-0.119579-0.314212-0.447049-0.491268-0.452593-0.175275-0.816803-0.729345-0.452593-0.314212
blueAvgLevel-0.0409560.3578200.0343490.0602940.1776170.434867-0.4147550.2926610.2035300.1606830.1282010.1244530.6169681.0000000.9012970.5062790.3713710.6535380.7188220.5062790.6169680.001020-0.052770-0.177617-0.4147550.434867-0.366039-0.167348-0.137854-0.100798-0.183090-0.440031-0.228466-0.248941-0.123316-0.013128-0.653538-0.718822-0.123316-0.440031
blueTotalExperience-0.0408520.3961410.0317190.0674620.1903650.472155-0.4601220.3030220.2327740.1790830.1523860.1393980.6761930.9012971.0000000.5708500.4129670.7179680.8008150.5708500.676193-0.006032-0.057446-0.190365-0.4601220.472155-0.397254-0.186937-0.145501-0.124000-0.187414-0.485059-0.254508-0.281446-0.141276-0.010528-0.717968-0.800815-0.141276-0.485059
blueTotalMinionsKilled-0.0029170.224909-0.0339250.1110280.125642-0.030880-0.468560-0.0620350.1187620.0866860.0835090.0922910.2849020.5062790.5708501.0000000.1722820.4504970.4472641.0000000.2849020.0142100.030234-0.125642-0.468560-0.030880-0.337314-0.069986-0.053958-0.047115-0.145974-0.447904-0.142399-0.1448320.0004840.092225-0.450497-0.4472640.000484-0.447904
blueTotalJungleMinionsKilled-0.0041930.1314450.010501-0.0234520.018190-0.112506-0.228102-0.1340230.1983780.1595950.1212910.0081650.0907690.3713710.4129670.1722821.0000000.1675100.2654430.1722820.0907690.004671-0.018008-0.018190-0.228102-0.112506-0.169318-0.075076-0.053295-0.056702-0.048078-0.182167-0.013881-0.0116570.109806-0.026363-0.167510-0.2654430.109806-0.182167
blueGoldDiff-0.0146700.5111190.0158000.0785850.3785110.654148-0.6400000.5497610.2814640.2338750.1629430.2940600.8168030.6535380.7179680.4504970.1675101.0000000.8947290.4504970.816803-0.019042-0.099725-0.378511-0.6400000.654148-0.528081-0.281296-0.234566-0.165611-0.273861-0.804347-0.652929-0.714405-0.452633-0.172066-1.000000-0.894729-0.452633-0.804347
blueExperienceDiff-0.0123150.4895580.0279430.0779460.2406650.583730-0.5776130.4370020.2639910.2114960.1624960.2183200.7293450.7188220.8008150.4472640.2654430.8947291.0000000.4472640.729345-0.026556-0.085829-0.240665-0.5776130.583730-0.422972-0.269283-0.218872-0.166162-0.197678-0.721190-0.721925-0.800089-0.437205-0.273224-0.894729-1.000000-0.437205-0.721190
blueCSPerMin-0.0029170.224909-0.0339250.1110280.125642-0.030880-0.468560-0.0620350.1187620.0866860.0835090.0922910.2849020.5062790.5708501.0000000.1722820.4504970.4472641.0000000.2849020.0142100.030234-0.125642-0.468560-0.030880-0.337314-0.069986-0.053958-0.047115-0.145974-0.447904-0.142399-0.1448320.0004840.092225-0.450497-0.4472640.000484-0.447904
blueGoldPerMin-0.0337540.4172130.0197250.0600540.3120580.888751-0.1625720.7483520.2393960.1864130.1539740.3509411.0000000.6169680.6761930.2849020.0907690.8168030.7293450.2849021.000000-0.020069-0.090611-0.312058-0.1625720.888751-0.128921-0.227236-0.201794-0.117257-0.119579-0.314212-0.447049-0.491268-0.452593-0.175275-0.816803-0.729345-0.452593-0.314212
redWardsPlaced0.007405-0.023671-0.0129060.135966-0.019142-0.0342390.008102-0.032474-0.017292-0.0271020.0056530.003660-0.0200690.001020-0.0060320.0142100.004671-0.019042-0.0265560.014210-0.0200691.0000000.0197840.0191420.008102-0.0342390.0237910.0274520.0187170.021769-0.0062300.0106660.0417370.036506-0.0218420.0046660.0190420.026556-0.0218420.010666
redWardsDestroyed-0.001197-0.0554000.1155490.123919-0.043304-0.0922780.038672-0.064501-0.005288-0.0230490.019885-0.038623-0.090611-0.052770-0.0574460.030234-0.018008-0.099725-0.0858290.030234-0.0906110.0197841.0000000.0433040.038672-0.0922780.0557980.0393350.0461320.0052550.0038550.0707840.0755370.0799750.128062-0.0093130.0997250.0858290.1280620.070784
redFirstBlood0.011577-0.201769-0.003228-0.017717-1.000000-0.2694250.247929-0.229485-0.151603-0.134309-0.077509-0.083316-0.312058-0.177617-0.190365-0.125642-0.018190-0.378511-0.240665-0.125642-0.3120580.0191420.0433041.0000000.247929-0.2694250.2011400.1416270.1353270.0602460.0695840.3014790.1826020.1949200.1567110.0245590.3785110.2406650.1567110.301479
redKills-0.013160-0.339297-0.002612-0.073182-0.2479290.0040441.000000-0.026372-0.204764-0.188852-0.095527-0.071441-0.162572-0.414755-0.460122-0.468560-0.228102-0.640000-0.577613-0.468560-0.1625720.0081020.0386720.2479291.0000000.0040440.8040230.1633400.1507460.0766390.1567800.8857280.4333830.464584-0.040521-0.1002710.6400000.577613-0.0405210.885728
redDeaths-0.0389930.3373580.0181380.0337480.2694251.0000000.0040440.8136670.1785400.1704360.0761950.1803140.8887510.4348670.472155-0.030880-0.1125060.6541480.583730-0.0308800.888751-0.034239-0.092278-0.2694250.0040441.000000-0.020344-0.224564-0.207949-0.104423-0.082491-0.161127-0.412219-0.462333-0.472203-0.214454-0.654148-0.583730-0.472203-0.161127
redAssists-0.008664-0.271047-0.009009-0.046212-0.201140-0.0203440.804023-0.007481-0.156764-0.162406-0.051209-0.036254-0.128921-0.366039-0.397254-0.337314-0.169318-0.528081-0.422972-0.337314-0.1289210.0237910.0557980.2011400.804023-0.0203441.0000000.1296980.1426710.0300000.1074250.7362150.2770400.279788-0.078234-0.1304170.5280810.422972-0.0782340.736215
redEliteMonsters0.017296-0.221551-0.022817-0.034509-0.141627-0.2245640.163340-0.182985-0.455139-0.506546-0.105593-0.041099-0.227236-0.167348-0.186937-0.069986-0.075076-0.281296-0.269283-0.069986-0.2272360.0274520.0393350.1416270.163340-0.2245640.1296981.0000000.8112340.6191530.1589990.2288610.2225370.2442050.1297050.2169690.2812960.2692830.1297050.228861
redDragons0.017416-0.209516-0.020121-0.034439-0.135327-0.2079490.150746-0.189563-0.471754-0.6319300.022035-0.028482-0.201794-0.137854-0.145501-0.053958-0.053295-0.234566-0.218872-0.053958-0.2017940.0187170.0461320.1353270.150746-0.2079490.1426710.8112341.0000000.0431140.0269500.1781680.1914970.2049410.1031510.2141870.2345660.2188720.1031510.178168
redHeralds0.006163-0.097172-0.011964-0.012712-0.060246-0.1044230.076639-0.058074-0.144104-0.016827-0.210012-0.031973-0.117257-0.100798-0.124000-0.047115-0.056702-0.165611-0.166162-0.047115-0.1172570.0217690.0052550.0602460.076639-0.1044230.0300000.6191530.0431141.0000000.2354750.1517620.1230560.1420240.0830870.0830680.1656110.1661620.0830870.151762
redTowersDestroyed0.003557-0.103696-0.008225-0.023943-0.069584-0.0824910.156780-0.060880-0.052029-0.032865-0.0428720.011738-0.119579-0.183090-0.187414-0.145974-0.048078-0.273861-0.197678-0.145974-0.119579-0.0062300.0038550.0695840.156780-0.0824910.1074250.1589990.0269500.2354751.0000000.3275030.1130350.1290020.0925640.0063740.2738610.1976780.0925640.327503
redTotalGold-0.010622-0.411396-0.005685-0.067467-0.301479-0.1611270.885728-0.133948-0.216616-0.192871-0.109557-0.122465-0.314212-0.440031-0.485059-0.447904-0.182167-0.804347-0.721190-0.447904-0.3142120.0106660.0707840.3014790.885728-0.1611270.7362150.2288610.1781680.1517620.3275031.0000000.6140250.6696460.2787150.1026320.8043470.7211900.2787151.000000
redAvgLevel-0.012419-0.352127-0.008882-0.059090-0.182602-0.4122190.433383-0.356928-0.169649-0.149806-0.087337-0.204429-0.447049-0.228466-0.254508-0.142399-0.013881-0.652929-0.721925-0.142399-0.4470490.0417370.0755370.1826020.433383-0.4122190.2770400.2225370.1914970.1230560.1130350.6140251.0000000.9017480.4896720.3820090.6529290.7219250.4896720.614025
redTotalExperience-0.021187-0.387588-0.013000-0.057314-0.194920-0.4623330.464584-0.396652-0.189816-0.159485-0.107718-0.210167-0.491268-0.248941-0.281446-0.144832-0.011657-0.714405-0.800089-0.144832-0.4912680.0365060.0799750.1949200.464584-0.4623330.2797880.2442050.2049410.1420240.1290020.6696460.9017481.0000000.5589850.4272140.7144050.8000890.5589850.669646
redTotalMinionsKilled-0.005118-0.212171-0.0123950.040023-0.156711-0.472203-0.040521-0.337515-0.074838-0.059803-0.046253-0.186879-0.452593-0.123316-0.1412760.0004840.109806-0.452633-0.4372050.000484-0.452593-0.0218420.1280620.156711-0.040521-0.472203-0.0782340.1297050.1031510.0830870.0925640.2787150.4896720.5589851.0000000.1656520.4526330.4372051.0000000.278715
redTotalJungleMinionsKilled0.006040-0.1109940.001224-0.035732-0.024559-0.214454-0.100271-0.160915-0.087893-0.098446-0.019622-0.038505-0.175275-0.013128-0.0105280.092225-0.026363-0.172066-0.2732240.092225-0.1752750.004666-0.0093130.024559-0.100271-0.214454-0.1304170.2169690.2141870.0830680.0063740.1026320.3820090.4272140.1656521.0000000.1720660.2732240.1656520.102632
redGoldDiff0.014670-0.511119-0.015800-0.078585-0.378511-0.6541480.640000-0.549761-0.281464-0.233875-0.162943-0.294060-0.816803-0.653538-0.717968-0.450497-0.167510-1.000000-0.894729-0.450497-0.8168030.0190420.0997250.3785110.640000-0.6541480.5280810.2812960.2345660.1656110.2738610.8043470.6529290.7144050.4526330.1720661.0000000.8947290.4526330.804347
redExperienceDiff0.012315-0.489558-0.027943-0.077946-0.240665-0.5837300.577613-0.437002-0.263991-0.211496-0.162496-0.218320-0.729345-0.718822-0.800815-0.447264-0.265443-0.894729-1.000000-0.447264-0.7293450.0265560.0858290.2406650.577613-0.5837300.4229720.2692830.2188720.1661620.1976780.7211900.7219250.8000890.4372050.2732240.8947291.0000000.4372050.721190
redCSPerMin-0.005118-0.212171-0.0123950.040023-0.156711-0.472203-0.040521-0.337515-0.074838-0.059803-0.046253-0.186879-0.452593-0.123316-0.1412760.0004840.109806-0.452633-0.4372050.000484-0.452593-0.0218420.1280620.156711-0.040521-0.472203-0.0782340.1297050.1031510.0830870.0925640.2787150.4896720.5589851.0000000.1656520.4526330.4372051.0000000.278715
redGoldPerMin-0.010622-0.411396-0.005685-0.067467-0.301479-0.1611270.885728-0.133948-0.216616-0.192871-0.109557-0.122465-0.314212-0.440031-0.485059-0.447904-0.182167-0.804347-0.721190-0.447904-0.3142120.0106660.0707840.3014790.885728-0.1611270.7362150.2288610.1781680.1517620.3275031.0000000.6140250.6696460.2787150.1026320.8043470.7211900.2787151.000000

-blue kill 과 red death (반대도 마찬가지), firstblood 간의 관계는 대척 관계이므로 모두 변수에 넣는다면 다중공선성 발생

sns.histplot(data=df, x='blueGoldDiff', hue='blueWins', palette='RdBu', kde=True)
<matplotlib.axes._subplots.AxesSubplot at 0x1d802543a08>

output_15_1

  • blueGoldDiff 변수에 따라 승패가 명확하게 갈린다.
sns.histplot(data=df, x='blueKills', hue='blueWins', palette='RdBu', kde=True, bins=8)
<matplotlib.axes._subplots.AxesSubplot at 0x1d803583308>

output_17_1

  • blue kills 어느정도 상관성이 있음
sns.jointplot(data=df, x='blueKills', y='blueGoldDiff', hue='blueWins')
<seaborn.axisgrid.JointGrid at 0x1d8036438c8>

output_19_1

  • 두 가지 feature가 상보적이다. 상관성이 높다.
sns.jointplot(data=df, x='blueExperienceDiff', y='blueGoldDiff', hue='blueWins')
<seaborn.axisgrid.JointGrid at 0x1d80376dbc8>

output_21_1

  • 골드 수급과 경험치 수급은 상관관계가 아주 높다. (당연하게도)
sns.countplot(data=df, x='blueDragons', hue='blueWins', palette='RdBu')
<matplotlib.axes._subplots.AxesSubplot at 0x1d804886508>

output_23_1

sns.countplot(data=df, x='redDragons', hue='blueWins', palette='RdBu')
<matplotlib.axes._subplots.AxesSubplot at 0x1d8048ca0c8>

output_24_1

  • blue가 Dragons을 죽였을때 승리확률이 높음
  • red는 Dragons 죽이든 죽이지 않든 승패에 크게 영향을 미치지 않음. Dragons의 경우 red보다 Blue에 더 영향을 미침.
sns.countplot(data=df, x='blueFirstBlood', hue='blueWins',palette='RdBu')
<matplotlib.axes._subplots.AxesSubplot at 0x1d80493b848>

output_26_1

  • blue 첫 킬을 달성한다면 blue가 이기는 사건이 많음. 반대도 마찬가지, 균형이 맞는 변수.

데이터 전처리

# 수치형 데이터 표준화
from sklearn.preprocessing import StandardScaler

df.columns
Index(['gameId', 'blueWins', 'blueWardsPlaced', 'blueWardsDestroyed',
       'blueFirstBlood', 'blueKills', 'blueDeaths', 'blueAssists',
       'blueEliteMonsters', 'blueDragons', 'blueHeralds',
       'blueTowersDestroyed', 'blueTotalGold', 'blueAvgLevel',
       'blueTotalExperience', 'blueTotalMinionsKilled',
       'blueTotalJungleMinionsKilled', 'blueGoldDiff', 'blueExperienceDiff',
       'blueCSPerMin', 'blueGoldPerMin', 'redWardsPlaced', 'redWardsDestroyed',
       'redFirstBlood', 'redKills', 'redDeaths', 'redAssists',
       'redEliteMonsters', 'redDragons', 'redHeralds', 'redTowersDestroyed',
       'redTotalGold', 'redAvgLevel', 'redTotalExperience',
       'redTotalMinionsKilled', 'redTotalJungleMinionsKilled', 'redGoldDiff',
       'redExperienceDiff', 'redCSPerMin', 'redGoldPerMin'],
      dtype='object')
# 다중공선성을 불러일으킬만한 변수 제거
df.drop(['gameId','redFirstBlood', 'redKills', 'redDeaths', 'redAssists',
       'redTotalGold', 'redTotalExperience', 'redGoldDiff','redExperienceDiff'], axis=1, inplace=True)

df.columns
Index(['blueWins', 'blueWardsPlaced', 'blueWardsDestroyed', 'blueFirstBlood',
       'blueKills', 'blueDeaths', 'blueAssists', 'blueEliteMonsters',
       'blueDragons', 'blueHeralds', 'blueTowersDestroyed', 'blueTotalGold',
       'blueAvgLevel', 'blueTotalExperience', 'blueTotalMinionsKilled',
       'blueTotalJungleMinionsKilled', 'blueGoldDiff', 'blueExperienceDiff',
       'blueCSPerMin', 'blueGoldPerMin', 'redWardsPlaced', 'redWardsDestroyed',
       'redEliteMonsters', 'redDragons', 'redHeralds', 'redTowersDestroyed',
       'redAvgLevel', 'redTotalMinionsKilled', 'redTotalJungleMinionsKilled',
       'redCSPerMin', 'redGoldPerMin'],
      dtype='object')
X_num = df[['blueWardsPlaced', 'blueWardsDestroyed', 
       'blueKills', 'blueDeaths', 'blueAssists', 'blueEliteMonsters',
      'blueTowersDestroyed', 'blueTotalGold',
       'blueAvgLevel', 'blueTotalExperience', 'blueTotalMinionsKilled',
       'blueTotalJungleMinionsKilled', 'blueGoldDiff', 'blueExperienceDiff',
       'blueCSPerMin', 'blueGoldPerMin', 'redWardsPlaced', 'redWardsDestroyed',
       'redEliteMonsters', 'redTowersDestroyed',
       'redAvgLevel', 'redTotalMinionsKilled', 'redTotalJungleMinionsKilled',
       'redCSPerMin', 'redGoldPerMin']]
X_cat = df[['blueFirstBlood', 'blueDragons', 'blueHeralds', 'redDragons', 'redHeralds']]

scaler = StandardScaler()
scaler.fit(X_num)
X_scaled = scaler.transform(X_num)
X_scaled = pd.DataFrame(X_scaled, index=X_num.index, columns=X_num.columns)

X = pd.concat([X_scaled, X_cat], axis=1) 
y = df['blueWins']

X
blueWardsPlacedblueWardsDestroyedblueKillsblueDeathsblueAssistsblueEliteMonstersblueTowersDestroyedblueTotalGoldblueAvgLevelblueTotalExperienceblueTotalMinionsKilledblueTotalJungleMinionsKilledblueGoldDiffblueExperienceDiffblueCSPerMinblueGoldPerMinredWardsPlacedredWardsDestroyedredEliteMonstersredTowersDestroyedredAvgLevelredTotalMinionsKilledredTotalJungleMinionsKilledredCSPerMinredGoldPerMinblueFirstBloodblueDragonsblueHeraldsredDragonsredHeralds
00.316996-0.3792750.935301-0.0469261.071495-0.879231-0.2104390.460179-1.035635-0.740639-0.992782-1.4659510.2562280.013342-0.9927820.460179-0.3992071.532493-0.914893-0.198353-0.410475-0.9287410.367685-0.9287410.05229310000
1-0.570992-0.839069-0.393216-0.387796-0.404768-0.879231-0.210439-1.166792-1.035635-1.385391-1.953558-0.758722-1.191254-0.593342-1.953558-1.166792-0.561751-0.8058702.2777004.412301-0.4104751.0337840.0685041.0337840.75861900011
2-0.404494-1.2988630.2710421.657424-0.6508120.719503-0.210439-0.254307-1.691092-1.422043-1.404543-0.455624-0.483614-0.520436-1.404543-0.254307-0.3992070.129475-0.914893-0.198353-0.410475-0.654900-2.324944-0.6549000.53390901000
31.149484-0.839069-0.725346-0.387796-0.4047680.719503-0.210439-0.8769590.2752800.021567-0.7182750.453671-0.5443500.013863-0.718275-0.876959-0.399207-0.338198-0.914893-0.1983530.2446270.805583-0.4301310.805583-0.00740600100
42.9254600.540312-0.061087-0.046926-0.158724-0.879231-0.210439-0.0673820.2752800.512211-0.3065130.655736-0.4151330.137283-0.306513-0.067382-0.290844-0.3381980.681403-0.1983530.2446270.3491821.5644080.3491820.61373100010
.............................................................................................
9874-0.293496-0.3792750.271042-0.728666-0.4047680.719503-0.2104390.8216560.9307380.865408-0.2607621.8681291.0209361.303263-0.2607620.8216561.2804190.129475-0.914893-0.198353-0.4104750.531742-1.7265820.531742-0.83380111000
98751.759976-1.298863-0.061087-0.7286660.3333640.719503-0.210439-0.1728940.9307381.1053150.745765-0.2535590.3128880.4799420.745765-0.172894-0.5617518.547582-0.914893-0.1983530.244627-0.5179800.467412-0.517980-0.69293801000
98760.039499-0.839069-0.0610870.293944-0.404768-0.879231-0.210439-0.3910820.2752800.086541-0.306513-0.556657-0.990702-0.959957-0.306513-0.391082-0.453388-1.2735430.681403-0.1983531.5548311.9922260.8663191.9922261.22749000010
9877-0.4599940.540312-1.389604-1.069536-0.8968560.719503-0.210439-1.331573-1.035635-0.5823670.334004-0.253559-0.347874-0.5475160.334004-1.3315732.3640490.597148-0.914893-0.1983530.8997291.353264-1.1282201.353264-0.79892111000
9878-0.237997-1.298863-0.061087-0.046926-0.404768-0.879231-0.210439-0.1546570.275280-0.505730-0.443767-0.6576900.371994-0.012696-0.443767-0.154657-0.724295-0.3381980.681403-0.198353-0.410475-0.746180-0.529858-0.746180-0.77141910010

9879 rows × 30 columns

학습 테스트 데이터 분리

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)

분류하기

회귀분석 모델

from sklearn.linear_model import LogisticRegression

model_lr = LogisticRegression()
model_lr.fit(X_train, y_train)
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
                   intercept_scaling=1, l1_ratio=None, max_iter=100,
                   multi_class='auto', n_jobs=None, penalty='l2',
                   random_state=None, solver='lbfgs', tol=0.0001, verbose=0,
                   warm_start=False)
from sklearn.metrics import classification_report

pred = model_lr.predict(X_test)
print(classification_report(y_test, pred))
              precision    recall  f1-score   support

           0       0.73      0.75      0.74      1469
           1       0.75      0.73      0.74      1495

    accuracy                           0.74      2964
   macro avg       0.74      0.74      0.74      2964
weighted avg       0.74      0.74      0.74      2964

앙상블 모델 적용(XGBoost)

from xgboost import XGBClassifier

model_xgb = XGBClassifier()
model_xgb.fit(X_train, y_train)
C:\Users\dissi\anaconda31\lib\site-packages\xgboost\sklearn.py:888: UserWarning: The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1].
  warnings.warn(label_encoder_deprecation_msg, UserWarning)


[15:25:49] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.3.0/src/learner.cc:1061: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.





XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
              colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1,
              importance_type='gain', interaction_constraints='',
              learning_rate=0.300000012, max_delta_step=0, max_depth=6,
              min_child_weight=1, missing=nan, monotone_constraints='()',
              n_estimators=100, n_jobs=4, num_parallel_tree=1,
              objective='binary:logistic', random_state=0, reg_alpha=0,
              reg_lambda=1, scale_pos_weight=1, subsample=1,
              tree_method='exact', use_label_encoder=True,
              validate_parameters=1, verbosity=None)
pred = model_xgb.predict(X_test)
print(classification_report(y_test, pred))
              precision    recall  f1-score   support

           0       0.71      0.71      0.71      1469
           1       0.72      0.72      0.72      1495

    accuracy                           0.72      2964
   macro avg       0.72      0.72      0.72      2964
weighted avg       0.72      0.72      0.72      2964

모델평가

회귀분석 모델

model_coef = pd.DataFrame(data=model_lr.coef_[0], index=X.columns, columns=['model coefficient'])
model_coef.sort_values(by='model coefficient', inplace=True)
plt.figure(figsize=(12, 10))
plt.barh(model_coef.index, model_coef['model coefficient'])
plt.show()

output_43_0

xgboost 모델

plt.figure(figsize=(12,10))
plt.barh(X.columns, model_xgb.feature_importances_)
plt.show()

output_45_0