{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"# PUBG Prediction Analysis"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ed32f5d14ed76752aded526938de805539d3d8bd"},"cell_type":"code","source":"pubg = pd.read_csv('../input/train_V2.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"382053172731de6e03f894ca1738362c63cc386d"},"cell_type":"code","source":"pubg.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8d2587cf0973a945588bce38230bb49c3c319bfe"},"cell_type":"code","source":"#Every column there is !\npubg.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f636ee2a4ae620206fa22c83bcafaca71f414a04"},"cell_type":"code","source":"#I am going to work on the first 1million rows of data since my kernel can't really handle 4.2m otherwise\npubg = pubg[:1000000]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4c1b5eb25c53355501463447b72b111e5fd50915"},"cell_type":"code","source":"pubg.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"466ba90b8897fe18511e5b285d1f00308da6a70b"},"cell_type":"markdown","source":"### Let's see if we have any missing data !"},{"metadata":{"trusted":true,"_uuid":"79e1710089138981f08f574673c9589556c8f2a9"},"cell_type":"code","source":"pubg.describe().iloc[0,:] ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b5b591f60c64c8fd50e0d411dfeed0e532db98f7"},"cell_type":"code","source":"%matplotlib inline # so that I don't have to type plt.show() everytime","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"dafb425f3456a6ee0c950a0228df3ab5e0701c1d"},"cell_type":"markdown","source":"### Visualising missing data if any !"},{"metadata":{"trusted":true,"_uuid":"8aa09fdc5df8023f736cfabf26ecffb5547351f4"},"cell_type":"code","source":"sns.heatmap(pubg.isnull(),yticklabels=False)\nf = plt.gcf()\nf.set_size_inches(10,8)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d21ba84ac391c27562f7812ed6b93b39ac4b8eb7"},"cell_type":"markdown","source":"Before starting with EDA or anything else, I am going to change the matchTypes to the three main ones which a pubg lover personally knows and loves !"},{"metadata":{"trusted":true,"_uuid":"330503d50d5b2bd850cb097799fa3c8bca266861"},"cell_type":"code","source":"pubg['matchType'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0aed40262bd24c615afb238979fe56c21dcb701d"},"cell_type":"code","source":"#converting them\npubg['matchType'].replace(['squad-fpp','duo-fpp','solo-fpp','normal-squad-fpp','crashfpp','normal-duo-fpp','flaretpp',\n                           'normal-solo-fpp','flarefpp','normal-squad','crashtpp','normal-solo','normal-duo'],\n                          ['squad','duo','solo','squad','others','duo','others','solo','others','squad',\n                          'others','solo','duo'],inplace=True)\n#others matchtype represent names of types which I can't personally distinguish as solo/squad/duo even after searching on kaggle","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aa702a665b146a244aa03f4d98e29f95409f6b75"},"cell_type":"code","source":"pubg['matchType'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a051ed210cfb70c145649d7d3d488841083be28d"},"cell_type":"markdown","source":"# 1. EDA (Exploratory Data Analysis)"},{"metadata":{"_uuid":"a528238e72a8206091da73598d561719ba625bf7"},"cell_type":"markdown","source":"## 1.1 Assists"},{"metadata":{"_uuid":"19e85701cd269d0acd029e7a0185439fb93cf4bc"},"cell_type":"markdown","source":"![Assists](http://cdn3-www.gamerevolution.com/assets/uploads/2018/09/pubg-mobile-cant-play-with-friends.jpg)"},{"metadata":{"_uuid":"990c74ca4a4031c3e632cb83fb46e967cbc2c3a0"},"cell_type":"markdown","source":"Assists : Number of enemy players this player damaged that were killed by teammates"},{"metadata":{"trusted":true,"_uuid":"47f5cee368d7329cc6dd51e9ec902ff8f2b393a6"},"cell_type":"code","source":"pubg['assists'].value_counts().to_frame().style.background_gradient(cmap='summer_r')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"922d56829fb81415efa9f28736956ca1693e4b94"},"cell_type":"code","source":"sns.factorplot('assists','winPlacePerc',hue='matchType',data=pubg)\nf = plt.gcf()\nf.set_size_inches(15,8)\nplt.title('Assists vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0e2fae57d77da009d3f16f2cc6a90453006f04c6"},"cell_type":"markdown","source":"Now personally speaking I don't really think assists should have been given importance in solos since you can't really knock someone is solos. I don't understand what it represents, maybe killing someone who has already been shot by someone else and has low health."},{"metadata":{"_uuid":"0d5346d6b8fb64b10d55895116afafc35fadd3b9"},"cell_type":"markdown","source":"Nevertheless, Having assists till 5-6 values is a good indication of having a good winPlacePercentage."},{"metadata":{"_uuid":"9d2d292cf528ceb1d3a108ddfd26071921caa7fd"},"cell_type":"markdown","source":"But that decreases after 8-9 assists. This could potentially represent players who are good only at assists than  killing and winning ! Remember this is going to matter more in squads since assists might help your team to go forward in the game but if you are only good at assisting and not killing chances of victory are substantially reduced !"},{"metadata":{"_uuid":"ee0f14b56918b7834162160576da83781ec5b67d"},"cell_type":"markdown","source":"## 1.2 Boosts\n"},{"metadata":{"_uuid":"428e827010c4647ffc87a266575f6fef8fff8de1"},"cell_type":"markdown","source":"Boosts : Number of boost items used. (Energy Drinks, PainKillers, Adrenaline Syringe)"},{"metadata":{"trusted":true,"_uuid":"81204fd80b0cc7b954bffc81676262fd5cf70ed6"},"cell_type":"code","source":"pd.crosstab(pubg.boosts,pubg.matchType).style.background_gradient(cmap='summer_r')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"94df737c31f3046ee95847081e6e8d3129667802"},"cell_type":"code","source":"x = pubg[pubg['boosts']<6].count()[0]/pubg.shape[0]*100\nprint('Percentage of players who used less than 6 boosts per game : ',x)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"5adc7ce0ee996b8e40715e6658928f3e407de386"},"cell_type":"markdown","source":"Majority of the people use less than 6 boosts per game ! "},{"metadata":{"trusted":true,"_uuid":"445fc21b91f872abb16fa35188c8b032826dc342"},"cell_type":"code","source":"sns.barplot('boosts','winPlacePerc',hue='matchType',data=pubg)\nplt.title('Boosts vs WinPlacePerc')\nf = plt.gcf()\nf.set_size_inches(15,8)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"b9fbcfdc3986b5fb326aed8e97d1aee443bd14d6"},"cell_type":"markdown","source":"From the graph and cross tab above, it is evident that players using more than 5-6 boosts per game are less in number but have higher chances of winning ! This is quite understandable in itself."},{"metadata":{"_uuid":"c8371c1516ed4e107fb7266fabfb61909fe8a521"},"cell_type":"markdown","source":"## 1.3 DamageDealt"},{"metadata":{"_uuid":"eeb50cdc3b62e8c30cbabaab63a4e0e35a55383c"},"cell_type":"markdown","source":"Damage Dealt : Total damage dealt. Note: Self inflicted damage is subtracted"},{"metadata":{"_uuid":"c0e58b6427e926e2a495cad203ca0d77e6dba407"},"cell_type":"markdown","source":"Damage dealt is a continuous feature. So plotting has to be in a similar fashion"},{"metadata":{"trusted":true,"_uuid":"eeb42a20105ab842cced06c7dec7001c6bb371ca"},"cell_type":"code","source":"f,ax=plt.subplots(1,2,figsize=(18,6))\nsns.distplot(pubg.damageDealt,kde=True,ax=ax[0])\nplt.title('Density Graph of DamageDealt')\nsns.scatterplot('damageDealt','winPlacePerc',hue='matchType',ax=ax[1],data=pubg)\nplt.title('DamageDealt vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1476c29dd043d6307f0b1fa4988b9d6d83ea0eb9"},"cell_type":"code","source":"pubg.groupby(['matchType'])['damageDealt'].mean()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2affa7f47df9d6df2862113cb766c4d67a223541"},"cell_type":"markdown","source":"There isn't much difference between the means of damage dealt between the major three classes of matchTypes. But there is one thing which can be noted from the scatter plot above. See below :"},{"metadata":{"trusted":true,"_uuid":"1c9c89741c8d9e7e848afb253e3e64bf8cf80ad2"},"cell_type":"code","source":"pubg[(pubg['matchType']=='solo')&(pubg['winPlacePerc']==0)&(pubg['damageDealt']>500)].count()[0]","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"a5ed53b999813160f5d2939c92157b29e2af8939"},"cell_type":"markdown","source":"So what I did in the above line is basically, all those players who have dealt more than 500 damage to enemies in solo match but still managed to have a winPlacePerc of 0.0. Is this badluck or a case of outliers ?"},{"metadata":{"trusted":true,"_uuid":"c470e46347e55d9353636634e8e2be9fb22d69b4"},"cell_type":"code","source":"pubg[(pubg['matchType']=='solo')&(pubg['winPlacePerc']==0)&(pubg['damageDealt']>1500)].count()[0]","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"776a557d1a82585e998b0e06a7c09ff2e0692983"},"cell_type":"markdown","source":"Well now the above one is just sheer badluck !"},{"metadata":{"trusted":true,"_uuid":"e64e5bfc967d03a7a743603a0ed248a2caccf2d1"},"cell_type":"code","source":"for i in range(5):    \n    plt.title('DamageDealt with winPlacePerc = '+str(0.4+(i/10))+' - '+str(0.4+(i+1)/10))\n    pubg[(pubg['winPlacePerc']>=0.4+(i/10))&(pubg['winPlacePerc']<0.4+((i+1)/10))].damageDealt.plot.hist(color='red',edgecolor='black',bins=20)\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"36c1af0375eafa0077eeb1410cfda4b0f290166c"},"cell_type":"markdown","source":"The data above shows people who didn't really deal a lot of damage but still ended up getting a good place ! This well might be because of people hiding themselves for majority of the game (proners and campers) !"},{"metadata":{"_uuid":"bbfc64e46f4b0b0fcf7918edc6fccf661de8ae6e"},"cell_type":"markdown","source":"## 1.4 HeadShot Kills"},{"metadata":{"_uuid":"362bc673fc87e874a4b75b846805e9a7b7ec1816"},"cell_type":"markdown","source":"![HeadshotKills](http://images2.minutemediacdn.com/image/upload/c_fill,w_912,h_516,f_auto,q_auto,g_auto/shape/cover/sport/5b2d10be3467ac14d0000006.jpeg)"},{"metadata":{"_uuid":"9f0cc204a0927583ef8d074c47db5c600757ced4"},"cell_type":"markdown","source":"HeadShotKills : Number of enemy players killed with headshots."},{"metadata":{"_uuid":"bd4683a4083304cca0e6c34869e5cd2bd08d599f"},"cell_type":"markdown","source":"This should give us a better idea of how much probability a player has at winning than other similar attributes like kills since headshots are generally difficult to take and are taken by more skilled players"},{"metadata":{"trusted":true,"_uuid":"562e39fb66af5d77dd5130f96d1b7f4b0cb006cf"},"cell_type":"code","source":"pubg['headshotKills'].value_counts().to_frame().style.background_gradient(cmap='summer_r')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4e346fb883113efec4c0d062e43197fff343abb8"},"cell_type":"code","source":"sns.factorplot('headshotKills','winPlacePerc',hue='matchType',data=pubg)\nf = plt.gcf()\nf.set_size_inches(10,8)\nplt.title('Headshot Kills vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"85303c03ec44f5399978445585cd62c2f14c96a1"},"cell_type":"markdown","source":"HeadshotKills is very informative. As can be seen from the plot above, the more the headshots people have, the better the chances of winning."},{"metadata":{"_uuid":"24bac2be433f0c7759bb9da082ffa5c4f1928391"},"cell_type":"markdown","source":"#### Skill speaks for itself"},{"metadata":{"trusted":true,"_uuid":"7deeca9a3febc9364257817e76358025879c1384"},"cell_type":"code","source":"x = pubg[(pubg['headshotKills']>5)&(pubg['winPlacePerc']>0.8)].count()[0]/pubg[pubg['headshotKills']>5].count()[0]*100\nprint('Percentage of people having more than 5 headshot kills and having winPlacePerc > 0.8 : ',x)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"188672219d58785987c9e8352ea9f8912bda4db2"},"cell_type":"markdown","source":"## 1.5 Heals"},{"metadata":{"_uuid":"f164d9e7ff75adc6a512fa5ee308846f07ab2ef3"},"cell_type":"markdown","source":"![FirstAid](https://d1nglqw9e0mrau.cloudfront.net/assets/images/game/icons/heal_firstaid-57fc8495.png)"},{"metadata":{"_uuid":"bb4dd3beb00220246af5bddacfe63061ed5991f9"},"cell_type":"markdown","source":"Heals : Number of healing items used.(First aids, Bandages,MediKits)"},{"metadata":{"trusted":true,"_uuid":"8e88c820a5645885cc1478be7fd5f3e36fea13e8"},"cell_type":"code","source":"sns.factorplot('heals','winPlacePerc',hue='matchType',data=pubg)\nf = plt.gcf()\nf.set_size_inches(25,15)\nplt.title('Heals vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"39878acfaa498f6fc143bb0100f6df76ecd439e0"},"cell_type":"markdown","source":"There are higher chances of ones winning if a person has used heals more than 0 times and understandably so ! Also solos have players using more healing items than duos or squads."},{"metadata":{"_uuid":"12279264572ecf75b41d68d09e642f6198ae9ac8"},"cell_type":"markdown","source":"## 1.6 Kill Place\n"},{"metadata":{"_uuid":"e4cf6d5c59279c88b7178d4a16b440f6687caa25"},"cell_type":"markdown","source":"KillPlace : Ranking in match of number of enemy players killed. (Rank 1 means most players killed in that match)"},{"metadata":{"trusted":true,"_uuid":"a38021a55d9a01a23ef5737fde85f69c6936cd8e"},"cell_type":"code","source":"sns.scatterplot('killPlace','winPlacePerc',data=pubg[pubg['matchType']=='solo'])\nf=plt.gcf()\nf.set_size_inches(10,8)\nplt.title('KillPlace vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"dbac3c83c424f35a971703e086406a553761c391"},"cell_type":"markdown","source":"There seems to be a negative correlation between the two features and understandably so since if I am at rank 1 in kills in a match, I probably have achieved a good rank overall !"},{"metadata":{"trusted":true,"_uuid":"9bee14151128ca25030463f192d779c136d4dd43"},"cell_type":"code","source":"sns.heatmap(pubg[['killPlace','winPlacePerc']].corr(),annot=True)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"48d0fcf5ba4192e1f8ce7d25e765ff959c4fd23e"},"cell_type":"markdown","source":"The negative correlation can be seen from the above heatmap. I mean obviously the more kills I have, the lesser killPlace rank I will have, and hence better will be my chances of winning !"},{"metadata":{"_uuid":"ce8aaa105841ba775c2ba72cf7dbf7c4e4d7fe2a"},"cell_type":"markdown","source":"### Kill Points is a feature which is calculated by rankpoints feature. RankPoints is inconsistent and will be deprecated so I won't be using both of these features !"},{"metadata":{"trusted":true,"_uuid":"5f111924af91ada28416930feda6ac0ff72c711d"},"cell_type":"code","source":"pubg.drop(['killPoints','rankPoints'],axis=1,inplace=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"240938c61d41825cf4979746dc26e51640af9779"},"cell_type":"code","source":"pubg.shape[1] #drop success !","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3133247ff33699b134b08c5023e14b8935cc6063"},"cell_type":"markdown","source":"## 1.7 Kill Streaks"},{"metadata":{"_uuid":"97b9ee4c508ee40018943d0095dfbbf9a882ee94"},"cell_type":"markdown","source":"KillStreaks : Max number of enemy players killed in a short amount of time"},{"metadata":{"trusted":true,"_uuid":"69ab47850eb56e77898b3700a238692d578c80e2"},"cell_type":"code","source":"sns.factorplot('killStreaks','winPlacePerc',hue='matchType',data=pubg)\nf = plt.gcf()\nf.set_size_inches(12,9)\nplt.title('KillStreaks vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"61da3a1d5c0f9c234f1b4f7eebece3795af5c411"},"cell_type":"markdown","source":"There isn't much that can be said about killstreaks since we can't really see a pattern ! I mean, I would expect someone with a killstream of 5 or above to have better chances of winning ! But the data doesn't follow the same intuition ! A lot of data who had 8 as killstreak only has < 0.3 as winPlacePerc"},{"metadata":{"_uuid":"d61155ef4d413de5cc560c2037994651bb65b9d9"},"cell_type":"markdown","source":"## 1.8 Kills"},{"metadata":{"_uuid":"1ec88719f5b0a9814738fe52a607da8c80748290"},"cell_type":"markdown","source":"Kills : Number of enemy players killed."},{"metadata":{"trusted":true,"_uuid":"b0dc4d7f6bfbca0c82f1b46f9c50af25b90c63a3"},"cell_type":"code","source":"f,ax = plt.subplots(2,2,figsize=(15,10))\nsns.barplot('kills','winPlacePerc',data=pubg[pubg['matchType']=='solo'],ax=ax[0,0],palette='Blues')\nax[0,0].set_title('Solos')\nsns.barplot('kills','winPlacePerc',data=pubg[pubg['matchType']=='duo'],ax=ax[0,1],palette='Blues_r')\nax[0,1].set_title('Duos')\nsns.barplot('kills','winPlacePerc',data=pubg[pubg['matchType']=='squad'],ax=ax[1,0],palette='OrRd')\nax[1,0].set_title('Squads')\nsns.barplot('kills','winPlacePerc',data=pubg[pubg['matchType']=='others'],ax=ax[1,1],palette= 'OrRd_r')\nax[1,1].set_title('Others')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"35ac448d82cfd5955724d650ecc9ce3d2dd28ed8"},"cell_type":"markdown","source":"In all the matches, having higher kills generally corresponds to higher chances of winning ! There are some inconsistencies after 15 kills or higher in solos, duos, squads but that might be becuase players who want to fight don't really play to win, they just want to kill !"},{"metadata":{"trusted":true,"_uuid":"76aaab1b9d8cfd0072ac3442ffea99f0acbd1a42"},"cell_type":"code","source":"pubg['kills'].max()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"640af85f6705b88858c3aa7e7f548e2432b7c2dd"},"cell_type":"markdown","source":"Someone killed 65 players in a single match !!!!!!!!! You gotta be kidding me ! Let's see who he is :"},{"metadata":{"trusted":true,"_uuid":"295f079f7adfdd3ca798d2852ea1d978931b0356"},"cell_type":"code","source":"pubg['kills'].argmax()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"310f7c223bea17496545b229ce5b3c9eb7bbf496"},"cell_type":"code","source":"pubg.iloc[334400].to_frame()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8bb899c2b256c4f798fccf83e6340b8faf9b8680"},"cell_type":"markdown","source":"DAMN DAWGGGG !!!!! You got a bright future in your scope !"},{"metadata":{"trusted":true,"_uuid":"cf831d05291e3ef37b4f438467852c4796282773"},"cell_type":"code","source":"sns.heatmap(pubg[['kills','winPlacePerc']].corr(),annot=True)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"cbbc46ae5ed7a45521cdd1ca915e7edef3c537be"},"cell_type":"markdown","source":"It is quite understandable to say the more kills you have the more chances you have to win/survive."},{"metadata":{"_uuid":"92d6000250939624b8e88ae857b4c748413767b7"},"cell_type":"markdown","source":"## 1.9 LongestKill"},{"metadata":{"_uuid":"073d49362a6efafd0815e294dcc96e8590f1de0e"},"cell_type":"markdown","source":"Longest Kill : The longest distance in meters a person has killed someone.\n\n"},{"metadata":{"_uuid":"3f1c748809b7b4bdb246a40250a69028f097ab9f"},"cell_type":"markdown","source":"Can be misleading sometimes since I can kill someone 1000m away who is knocked out ! But let's see"},{"metadata":{"trusted":true,"_uuid":"4ff4548598cf17ecf385e9f7d3ff92666f1b2e2f"},"cell_type":"code","source":"print('Longest Kill :',str(pubg['longestKill'].max()) + ' - AWM + 15x')\nprint('Shortest Kill :',str(pubg['longestKill'].min())+' - Pan Kill')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d830e4ee79545064b1bd35155d9adb33fa17e204"},"cell_type":"code","source":"sns.scatterplot('longestKill','winPlacePerc',data=pubg)\nf = plt.gcf()\nf.set_size_inches(12,9)\nplt.title('LongestKill vs WinPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"87be5063817cd39ee1f0a4570999ab40982e04ca"},"cell_type":"markdown","source":"Having high range kills would mean a better player and kinda understandably so!"},{"metadata":{"trusted":true,"_uuid":"aabac5bf136f8484c4028ecb68a1282f2c71aa1c"},"cell_type":"code","source":"x = pubg[(pubg['longestKill']>200)&(pubg['winPlacePerc']>0.8)].count()[0]/pubg[pubg['longestKill']>200].count()[0]*100\nprint('Percentage of people who had LongestKills > 200m and winPlacePerc > 0.8 :',x)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"b7e737db9ffb78c42ab9bb515cb750499c831169"},"cell_type":"markdown","source":"So people who had killed others with distance more than 200m have good chances of survival/winning !"},{"metadata":{"_uuid":"7e849d855291632c435fd7dc49c9d235e9235655"},"cell_type":"markdown","source":"## 1.10 MatchDuration"},{"metadata":{"_uuid":"6e3445f1c85bf4be1ca2685c59151ced65d3f802"},"cell_type":"markdown","source":"MatchDuration : Duration of match in seconds"},{"metadata":{"trusted":true,"_uuid":"658e2797396d208bce5166294e92e9654da645f9"},"cell_type":"code","source":"sns.distplot(pubg.matchDuration)\nf = plt.gcf()\nf.set_size_inches(10,8)\nplt.title('Match duration Density Graph')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"49d4b1f5bfe9a7cfca853171128cabbcedd75926"},"cell_type":"code","source":"1400/60,1800/60","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7913bb95cdd6595a018e1031d6302fc35d88895f"},"cell_type":"markdown","source":"So by data, the fights usually start at around 23 minutes of match start and majority of them die in this period as well(the first peak of the graph). This can be fourth or fixth last circle ! Then at 30 minutes, due to the last/second last circle, people have no other alternative apart from a one on one (see the second peak of the graph)"},{"metadata":{"_uuid":"6b8d527fbaf009cdd89c1dbf3b6cbaed514e5325"},"cell_type":"markdown","source":"## 1.11 Revives"},{"metadata":{"_uuid":"b86aaee0f2f95831735b4b375f056c3bc9fdc427"},"cell_type":"markdown","source":"![](https://cdn1.alphr.com/sites/alphr/files/styles/insert_main_wide_image/public/2018/01/pubg_guide_-_helping_a_team_mate.jpg?itok=kOzC7EQo)"},{"metadata":{"_uuid":"dbd678409c3daa84ecd3367d1cc1be35dc71043b"},"cell_type":"markdown","source":"Revives : Number of times this player revived teammates."},{"metadata":{"_uuid":"542c9f61a5484347fe2b3ad1c2ae236e10148e53"},"cell_type":"markdown","source":"NOTE : This is going to be meaningless for solos !"},{"metadata":{"trusted":true,"_uuid":"80b01cde1786fae4d17dfe959a2374501bec2cd0"},"cell_type":"code","source":"pubg.groupby(['matchType'])['revives'].value_counts().to_frame().style.background_gradient(cmap='summer_r')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"fdf987e2432cbcf297cee5280711ea75c4334bab"},"cell_type":"markdown","source":"Well it is easily understandable and can be verified by the above cross tab that squads are generally going to have moe revives than any other matchtype. Let's take a closer look at it !"},{"metadata":{"trusted":true,"_uuid":"353a03ca2f33938c466a4ede6bb76a6f0b8e1a17"},"cell_type":"code","source":"sns.catplot('revives','winPlacePerc',data=pubg[pubg.matchType=='squad'],jitter=False)\nf=plt.gcf()\nf.set_size_inches(10,8)\nplt.title('Squad revives vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"799f0c118e67d1ab2c880f9e8b03caeefa593556"},"cell_type":"markdown","source":"The more the revives a player performs, the better his chances becomes at winning. But after 6 revives per player, the winning percentage decreases or a specific pattern can't be observed. This may be because you are being knocked out more often than not would make you a NOOB !"},{"metadata":{"_uuid":"5a7336f6ed64f1b8e6cddbaaade390ea09a787a4"},"cell_type":"markdown","source":"## 1.12 RideDistance\n"},{"metadata":{"_uuid":"e606455774294ed48abd63950067c9a704eb06a3"},"cell_type":"markdown","source":"![](https://cdn1.alphr.com/sites/alphr/files/styles/insert_main_wide_image/public/2018/01/pubg_guide_-_vehicle_ride.jpg?itok=dO-nSud7)"},{"metadata":{"trusted":true,"_uuid":"a5f3884748a10ccef7e04c23fd6e1d79b0118da3"},"cell_type":"code","source":"print('The highest ride distance by a player :',pubg['rideDistance'].max())","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f6cc51e124e4bc652428e28a685e54e6df28a1f6"},"cell_type":"markdown","source":"How can someone travel 33KM in a single match ??? Can be a potential outlier !"},{"metadata":{"trusted":true,"_uuid":"6f0c873af14fb1d409b4cd8f8a81f68b3a38a50a"},"cell_type":"code","source":"sns.scatterplot('rideDistance','winPlacePerc',data=pubg)\nf=plt.gcf()\nf.set_size_inches(10,8)\nplt.title('rideDistance vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3e70987a339108de35635b027128a49f8a59e9e3"},"cell_type":"code","source":"for i in range(5):    \n    plt.title('RideDistance with winPlacePerc = '+str(0.4+(i/10))+' - '+str(0.4+(i+1)/10))\n    pubg[(pubg['winPlacePerc']>=0.4+(i/10))&(pubg['winPlacePerc']<0.4+((i+1)/10))&(pubg['rideDistance']<10000)].rideDistance.plot.hist(color='red',edgecolor='black',bins=20)\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"5939e6e087d2b9febc7db0e3a445cbfe34dfdeec"},"cell_type":"markdown","source":"Ride distance increases for the players with hgh winPlacePerc. The increase is not substantial but can be seen !"},{"metadata":{"trusted":true,"_uuid":"5abe1aa1653c9669c5a5c520c2dabf8ab0c12b55"},"cell_type":"code","source":"sns.heatmap(pubg[['rideDistance','winPlacePerc']].corr(),annot=True)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ec81b4ed859688ab154ed7d5e6228e0b47050372"},"cell_type":"markdown","source":"There is still a positive correlation between the two !"},{"metadata":{"_uuid":"3c86d4dc2874bd7a90b69ae7fd71b65bf63d0f54"},"cell_type":"markdown","source":"## 1.13 RoadKills\n"},{"metadata":{"_uuid":"dd884f026c8f71f3485984554f4f22706ec2a3fb"},"cell_type":"markdown","source":"RoadKills : Number of kills when in vehicle"},{"metadata":{"trusted":true,"_uuid":"401ceab0af702d6f210bfc5a6e7afade78ab9697"},"cell_type":"code","source":"pubg['roadKills'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1e6e1efcb553e63925e471060406bcf87aea91e5"},"cell_type":"code","source":"sns.catplot('roadKills','winPlacePerc',kind='boxen',data=pubg)\nf = plt.gcf()\nf.set_size_inches(12,9)\nplt.title('RoadKills vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"e98e38838b76216870c94062afb785aead98dedd"},"cell_type":"markdown","source":"Having higher roadkills means better chances of winning ! I didn't expect something like this. I personally have killed a lot of people and destroyed a lot of vehicles when in a vehicle, makes me a pro player I guess !"},{"metadata":{"_uuid":"8d9bf5d0a17c93e0a453aed40fb2d05e5069846f"},"cell_type":"markdown","source":"## 1.15 Team Kills\n"},{"metadata":{"_uuid":"8148612737229f79f190eecf23a4cfba11bd2115"},"cell_type":"markdown","source":"![](https://www.greenmangaming.com/blog/wp-content/uploads/2017/07/PUBG_blogbanner.jpg)"},{"metadata":{"_uuid":"4a528282ecbe241e008791ec8d62fdaa7cb067f5"},"cell_type":"markdown","source":"Team Kills : Number of times player killed team mates"},{"metadata":{"trusted":true,"_uuid":"fe2933128b38abd89f44c4930f4ab5430e2c6f18"},"cell_type":"code","source":"sns.violinplot('teamKills','winPlacePerc',hue='matchType',data=pubg[(pubg['matchType']=='squad')|(pubg['matchType']=='duo')],split=True)\nf = plt.gcf()\nf.set_size_inches(10,8)\nplt.title('TeamKills vs winPlacePerc (duos and squads only)')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"82c0a51c225263ae481a4bbc675154239393111d"},"cell_type":"markdown","source":"Players who do have some team kills are comparitively less in numbers who have higher winPlacePerc ! This is something I am glad to see, because of the traitors and my brothers also who have betrayed me in an otherwise great match !"},{"metadata":{"_uuid":"7817a72edc82bc68a01d9b2d79dbc505a9de4c37"},"cell_type":"markdown","source":"## 1.16 VehiclesDestroyed\n"},{"metadata":{"_uuid":"2789af53d1b00cf17aba95b039b9b2fe56d79fad"},"cell_type":"markdown","source":"VehiclesDestroyed : The number of vehicles destroyed by a single player !"},{"metadata":{"trusted":true,"_uuid":"a8483cd98832d75e6b3a8cc4fde7d0b40315995e"},"cell_type":"code","source":"sns.factorplot('vehicleDestroys','winPlacePerc',hue='matchType',data=pubg)\nf=plt.gcf()\nf.set_size_inches(10,8)\nplt.title('VehiclesDestroyed vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"14611ebeea946bcf3f34efef4df5eb0f03f58c3b"},"cell_type":"markdown","source":"Damn ! Someone who has destroyed even a single vehicle or more proves to be having a higher chance of survival and winPlacePercentage. Terminator !"},{"metadata":{"_uuid":"8efeb1af15159abb7ea8d2f8aa13de236ff1b908"},"cell_type":"markdown","source":"## 1.17 WalkDistance"},{"metadata":{"_uuid":"97a53597f8afb5c7ab33bb4006c478b09aefbfe7"},"cell_type":"markdown","source":"Walkdistance : Distance walked by player in metres"},{"metadata":{"trusted":true,"_uuid":"7877a53f61ce4e8c7996a48a10a20786539fb36f"},"cell_type":"code","source":"#below represents people who haven't moved a single step but still had more than 0 kill\npubg[(pubg['walkDistance']==0)&(pubg['kills']>0)].count()[0]","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"84c99bfa6a19f8c9aa160fbff4d01a6c08529fc1"},"cell_type":"markdown","source":"Cheaters ! Hackers ! Might even have one data row of my hacker brother !"},{"metadata":{"trusted":true,"_uuid":"edac11d0e7080ff6e6b15f387889fdedf92b616b"},"cell_type":"code","source":"pubg.drop(pubg[(pubg['walkDistance']==0)&(pubg['kills']>0)].index,inplace=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5b647c62b0b01f8be4d3517afcfa63fc7cc4beff"},"cell_type":"code","source":"sns.scatterplot('walkDistance','winPlacePerc',data=pubg)\nf = plt.gcf()\nf.set_size_inches(8,6)\nplt.title('WalkDistance vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"87a29fe43c1ed8ef6e1dc906b35999b52d98a199"},"cell_type":"code","source":"# Most of the data have walkdistance value < 10000m. So that's why I have put a limit on it in below code\npubg[(pubg['winPlacePerc']>0.9)&(pubg['walkDistance']<10000)].walkDistance.plot.hist(bins=50,edgecolor='black')\nf = plt.gcf()\nf.set_size_inches(12,9)\nplt.title('WalkDistance Frequency')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c284efd123e8bdbe686e894f4c2e53058404105a"},"cell_type":"markdown","source":"The above graph looks like a normal distribution. This checks with the fact that the circle forms randomly and by Central Limit Theoremm, half of the people actually have to walk towards the circle whereas other half are going to be inside ! This can be verified by the average distance walked. Let's see :"},{"metadata":{"trusted":true,"_uuid":"1f861ec55bfba05be86b8b787a6472c113c60830"},"cell_type":"code","source":"pubg['walkDistance'].mean()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"95c899d9b6b751ad981305b024af2e5789718c36"},"cell_type":"code","source":"print(pubg['walkDistance'].max())\nprint(\"How the hell can someone walk a fu****g 25 Km. Let's see who he actually is !\")\npubg[pubg['walkDistance']>25000].iloc[0,:].to_frame()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"445f82b7034d38f6b9a363fa37f0b40e98380aee"},"cell_type":"markdown","source":"Usain Bolt Bolt Bolt !!!!!!"},{"metadata":{"_uuid":"71c6a9a0c6743afaf89640fba32cca32ea9b597b"},"cell_type":"markdown","source":"## 1.18 Weapons Acquired"},{"metadata":{"_uuid":"f95a8a8e5ba81c045d47530870cb316fe46bf39a"},"cell_type":"markdown","source":"Weapon Acquired : Number of weapons picked up"},{"metadata":{"trusted":true,"_uuid":"6c13461563160b64bb169bcdf3d18281c299b998"},"cell_type":"code","source":"sns.catplot('weaponsAcquired','winPlacePerc',data=pubg, jitter=False)\nf=plt.gcf()\nf.set_size_inches(20,15)\nplt.title('Weapons Acquired vs winPlacePerc')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"97aa6423efc5c8641dbdac329f48168e59a6a5c8"},"cell_type":"markdown","source":"There seems to be a positive correlation between weapons acquired and winPlacePerc. Let's see !"},{"metadata":{"trusted":true,"_uuid":"4af3fdfcdae4b7997e07b9e7013eb8e6bcfa4b63"},"cell_type":"code","source":"sns.heatmap(pubg[['weaponsAcquired','winPlacePerc']].corr(),annot=True)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2cff1d5d097879660f03e27eccb3688efcd0afa2"},"cell_type":"markdown","source":"## 1.19 Correlation Matrix\n"},{"metadata":{"trusted":true,"_uuid":"c2305acb3bcb46fd9e5ad1bc2bb1d431012f190a"},"cell_type":"code","source":"sns.heatmap(pubg.corr(),annot=True,linewidths=0.5,cmap='RdYlGn')\nf = plt.gcf()\nf.set_size_inches(25,20)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"98fef15759259af8249e5478db3f2e2f011dccd6"},"cell_type":"markdown","source":"Correlation with winPlacePerc :"},{"metadata":{"_uuid":"c5d6c015ca1f7f4aaca1b8fdf1fe203b9de22e88"},"cell_type":"markdown","source":"1. Boosts have a higher correlation with winPlacePerc even more than heals.\n2. KillPlace and winPlacePerc have high negative correlation which is something we saw above !\n3. DamageDealt,Heals,Kills,KillStreaks,LongestKill,RideDistance,WeaponsAcquired all of these have considerable correlation with winPlacePerc as well.\n4. WalkDistance seems to have the highest correlation with winPlacePerc which can prove to be useful in a prediction model !"},{"metadata":{"_uuid":"518d7dc22cef168d0f73e4702dd39fc260c1679f"},"cell_type":"markdown","source":"# Tableau and Analysis"},{"metadata":{"trusted":true,"_uuid":"c2381eb2cff32e21fdec0162a5a03003d5f0f0cc"},"cell_type":"code","source":"%%html\n<div class='tableauPlaceholder' id='viz1548504873335' style='position: relative'><noscript><a href='#'><img alt=' ' src='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;26&#47;266JW6WP2&#47;1_rss.png' style='border: none' /></a></noscript><object class='tableauViz'  style='display:none;'><param name='host_url' value='https%3A%2F%2Fpublic.tableau.com%2F' /> <param name='embed_code_version' value='3' /> <param name='path' value='shared&#47;266JW6WP2' /> <param name='toolbar' value='yes' /><param name='static_image' value='https:&#47;&#47;public.tableau.com&#47;static&#47;images&#47;26&#47;266JW6WP2&#47;1.png' /> <param name='animate_transition' value='yes' /><param name='display_static_image' value='yes' /><param name='display_spinner' value='yes' /><param name='display_overlay' value='yes' /><param name='display_count' value='yes' /><param name='filter' value='publish=yes' /></object></div>                <script type='text/javascript'>                    var divElement = document.getElementById('viz1548504873335');                    var vizElement = divElement.getElementsByTagName('object')[0];                    vizElement.style.width='1029px';vizElement.style.height='722px';                    var scriptElement = document.createElement('script');                    scriptElement.src = 'https://public.tableau.com/javascripts/api/viz_v1.js';                   \nvizElement.parentNode.insertBefore(scriptElement, vizElement);    \n</script>","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c9975d74fc0b51139a8bbb1c1fd64fa65c8a5303"},"cell_type":"markdown","source":"The above is a tableau created dashboard. It is an interactive dashboard which you can interact with using hover or selecting a particular bubble. Do that to understand better !\n\nThe bigger the bubble is, the more the data it holds.\n\nWhat is particularly interesting about this workbook is, when you analyse this workbook, the amount of kills/weapons aqcuired etc. are going to be generally more for winPlacePerc = 1.0 and less for winPlacePerc = 0, giving an indication of positive correlation within the variables except for killPlace in which as we saw above, a negative correlation can be observed !"},{"metadata":{"_uuid":"de4f1d0e778326e2e57a465a2c9aa0257785c24f"},"cell_type":"markdown","source":"# 2. Feature Engineering"},{"metadata":{"_uuid":"1531f48084be9b1224daa8a32d12bb5f3c552eea"},"cell_type":"markdown","source":"## 2.1 Health"},{"metadata":{"_uuid":"5a334b5874443a43a2bea7d138068df3effa248e"},"cell_type":"markdown","source":"The first thing I am going to do is to combine heals and boosts since survival in a game is mostly governed by these two !"},{"metadata":{"trusted":true,"_uuid":"3038f0e0b97ba66e89b15999184a88ac311f4716"},"cell_type":"code","source":"pubg['health'] = pubg['heals'] + pubg['boosts']","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"839d9e706416a5c879fc45b635b230233d567dcc"},"cell_type":"markdown","source":"Let's see how the combined correlation compares to that of individual heals and boosts :"},{"metadata":{"trusted":true,"_uuid":"1bd6aae20c3518aaa8e471439ee236beb9a04e89"},"cell_type":"code","source":"sns.heatmap(pubg[['health','heals','boosts','winPlacePerc']].corr(),annot=True)\nf=plt.gcf()\nf.set_size_inches(8,6)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"08c43f3fbfdbd398b2768b6f02ff0dac06d1d14a"},"cell_type":"markdown","source":"Correlation of health with winPlacePerc is comaparitively lower than just with boosts. But this helps us with two things. Our model won't overfit with keeping just boosts as the prime feature winPlacePerc is based on and also heals and boosts combined together will make for a more robust prediction ! You can see afterwards if just keeping boosts instead of our new feature health has more impact on our predictions or not !"},{"metadata":{"_uuid":"abf229120b01ee4d4a1e76b94a977d9ab29e520b"},"cell_type":"markdown","source":"## 2.2 HeadshotSkill"},{"metadata":{"_uuid":"e18344a7ce181b875c08100afce88369bfd6e429"},"cell_type":"markdown","source":"As I talked about in the above section, a player who is known to take more headshots will generally be a more skilled and a worthy winner indeed. Now headshot kills represent the number of enemies killed by headshots. This generally can be misleading since if I killed only one player that too by headshot, this might have happened out of sheer chance ! Also if I killed 5 people out of which only 1 was by headshot, I may not be skilled enough. So I am going to create a feature HeadshotSkill which would accurately depict my skill level based on data and is formed below :"},{"metadata":{"trusted":true,"_uuid":"3635d82cede47e1f7fcb3df20bc93951d5ff3993"},"cell_type":"code","source":"def head(c):\n    if(c[0]==0):\n        return 0\n    elif(c[1]==0):\n        return 0\n    else:\n        return c[0]/c[1]\npubg['headshotSkill'] = pubg[['headshotKills','kills']].apply(head,axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ed912de6d790c471b38d93cf7c18f141ddf99940"},"cell_type":"code","source":"pubg.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0ffe1b84063e08d90861592be803c98886e2921d"},"cell_type":"code","source":"sns.heatmap(pubg[['headshotKills','headshotSkill','kills','winPlacePerc']].corr(),annot=True)\nf=plt.gcf()\nf.set_size_inches(8,6)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ba041335be590583b53b1b25d455f105e97265a6"},"cell_type":"markdown","source":"A correlation though not substantial can be seen !"},{"metadata":{"_uuid":"97b542ab7e5f09d709573038d369e7de9f66d61a"},"cell_type":"markdown","source":"## 2.3 DistanceCovered"},{"metadata":{"trusted":true,"_uuid":"c94c86113ac02eaa85f9e1bde578f0bd638fb190"},"cell_type":"code","source":"pubg['distanceCovered'] = pubg['walkDistance']+pubg['rideDistance']+pubg['swimDistance']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fea56cd1ef44c72f285552abd40eae54c51bc4ca"},"cell_type":"code","source":"sns.heatmap(pubg[['distanceCovered','walkDistance','rideDistance','swimDistance','winPlacePerc']].corr(),annot=True)\nf=plt.gcf()\nf.set_size_inches(8,6)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0a8fb38d805582b9c9c4444f43c789b3d799e92a"},"cell_type":"markdown","source":"## 2.4 ActualKills"},{"metadata":{"_uuid":"31bf9c8907a7c938bbf74e507de94dd6e70f1910"},"cell_type":"markdown","source":"I personally despise team kills a lot and obviously if a match is based on team vs team, having lesser membes is a disadvantage !"},{"metadata":{"trusted":true,"_uuid":"bcf52a2b625b41bed4936beaea274346b044fa4a"},"cell_type":"code","source":"pubg['actualKills'] = pubg['kills'] - pubg['teamKills']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"36cd08dfdff8c5cd773c819cdf8da03f80e65c7f"},"cell_type":"code","source":"sns.heatmap(pubg[['kills','actualKills','teamKills','winPlacePerc']].corr(),annot=True)\nf=plt.gcf()\nf.set_size_inches(8,6)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c3515ca35d896e9c692b1c009831ec1b7a6f829b"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}