{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":false,"_kg_hide-output":false},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n# Any results you write to the current directory are saved as output.\n#setting display height,max_rows,max_columns and width to desired\npd.set_option('display.max_rows',500)\npd.set_option('display.max_columns',500)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train  = pd.read_csv('../input/train_V2.csv')\ntest = pd.read_csv('../input/test_V2.csv')\nprint (\"Train Head -->\")\ndisplay(train.head())\nprint (\"Test Head -->\")\ndisplay(test.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"82d8b9e8d64433fa36880b09e4435506dd1cd4f7"},"cell_type":"code","source":"print (train.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"15b76a3e1a047d8dc4ca89affa6f9f7ab704923f"},"cell_type":"code","source":"print (test.shape)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-output":false,"_kg_hide-input":false,"trusted":true,"_uuid":"2e7430637d5e5ded31472508a9056189144c36d8","scrolled":true},"cell_type":"code","source":"train.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"46fad941e2d8f6cb4bde8dced456b6e84565f20f"},"cell_type":"code","source":"train.isna().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5c1be993f2066b74309fdf38e5373aa8ef7f0568"},"cell_type":"code","source":"train[train['winPlacePerc'].isnull()]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d0cbda5d0d52f7ec5bc7d12cab7f0d58e83318bd"},"cell_type":"code","source":"#lets drop that NaN entry\ntrain.drop(2744604,inplace = True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2613c15179d1be7d7785af272302a9ea27c86c22"},"cell_type":"code","source":"test.isna().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d1d4ba484ef5c9730a97a933ef23ba5947f190aa"},"cell_type":"code","source":"print (\"Longest Kill Recored {} Average Kill Distance {}\".format(train['longestKill'].max(),train['longestKill'].mean()))\nprint (\"Max Assists Recorded {} Average Assists {}\".format(train['assists'].max(),train['assists'].mean()))\nprint (\"Max Boost Items used {} Average Boost Items Used {}\".format(train['boosts'].max(),train['boosts'].mean()))\nprint (\"Maximum DamageDealt  {} Average Damage Dealt {}\".format(train['damageDealt'].max(),train['damageDealt'].mean()))\nprint (\"Max Boost Items used {} Average Boost Items Used {}\".format(train['boosts'].max(),train['boosts'].mean()))\nprint (\"Max Heal Items used {} Average Heal Items Used {}\".format(train['heals'].max(),train['heals'].mean()))\nprint (\"Longest Kill Streak {} Average Kill Streak Used {}\".format(train['killStreaks'].max(),train['killStreaks'].mean()))\nprint (\"Maximum Kills {} Average Kills {}\".format(train['kills'].max(),train['kills'].mean()))\nprint (\"Maximum Revives {} Average Revives {}\".format(train['revives'].max(),train['revives'].mean()))\nprint (\"Maximum Team Kills {} Average Team Kills {}\".format(train['teamKills'].max(),train['teamKills'].mean()))\nprint (\"Maximum vehicleDestroys {} Average vehicleDestroys {}\".format(train['vehicleDestroys'].max(),train['vehicleDestroys'].mean()))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"caa19cf37a322a7f83b0fc449ef92aa34808594f"},"cell_type":"markdown","source":"**Check Number of Players Joined in Game**"},{"metadata":{"trusted":true,"_uuid":"05bede15c827ddd5175a5edfa730fa9ff5df4641","scrolled":true},"cell_type":"code","source":"train['playerJoined'] = train.groupby('matchId')['matchId'].transform('count')\nplt.figure(figsize = (15,10))\nsns.countplot(train[train['playerJoined']>=60]['playerJoined'])\nplt.title(\"Players Joined\")\nplt.show()\nplt.figure(figsize = (15,10))\nsns.countplot(train[train['playerJoined']<=60]['playerJoined'])\nplt.title(\"Players Joined\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7077c594a5e8ba4474db035751725b19853e03d7"},"cell_type":"code","source":"# I think matches with less than 50 are not worth considering\n# so gonna drop those rows\ntrain.drop(train[train['playerJoined']<=50].index,inplace = True)\ntrain.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"3abdb40b56be28483cc77435871633e31bd2a766"},"cell_type":"markdown","source":"**Number of Player in Group**"},{"metadata":{"trusted":true,"_uuid":"531457c3d0fc1358033f1b114e6a7a5194387d3a"},"cell_type":"code","source":"train['playersInGroup'] = train.groupby('groupId')['groupId'].transform('count')\nplt.figure(figsize=(15,10))\nsns.countplot(train[train['playersInGroup']>=0]['playersInGroup'])\nplt.title(\"Number of Players in Single Group\")\nplt.show()\ntrain[train['playersInGroup']>4].shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1abdfaa63e991194ef69462af3208a1f9e2766a3"},"cell_type":"code","source":"#Groups with players greater than 4 are not valid\n# as in PUBG max size of Group is 4 so we remove them\ntrain.drop(train[train['playersInGroup']>4].index, inplace = True)\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"9128d736826c3de80f7923d47ba12736b2189d61"},"cell_type":"markdown","source":"**Killing**"},{"metadata":{"trusted":true,"_uuid":"7263f04813008a81222c4c0ebc8f9e5fbcabec37"},"cell_type":"code","source":"#lets find some interesting things from data\nprint ('Max Kills Recored {} Average Kills person kills {} while 99% people kills {}'.format(train['kills'].max(),train['kills'].mean(),train['kills'].quantile(0.99)))\n# 72 kills seems suspicious lets Plot","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6fcd4797b2d161e7b02a1a298d3d1576d61a2bd5"},"cell_type":"code","source":"plt.figure(figsize=(15,10))\nsns.countplot(train[train['kills']>=1]['kills'])\nplt.title(\"Number of Kills\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"82832cd2f14b1dca8459002b7a74972d3bd2d7b9"},"cell_type":"code","source":"#lets check killing with winPlacePerc\n# plt.figure(figsize = (15,10))\nsns.jointplot(x=\"winPlacePerc\",y=\"kills\",data=train,height=10,ratio=3)\nplt.title(\"WinplacePerc vs Number of Kills\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0887b455e426bd506ebcf78fc76a7533550231ee"},"cell_type":"markdown","source":"There seems to be relation between kills and winplaceperc . the more the number of kills more the winplacePerc"},{"metadata":{"trusted":true,"_uuid":"25af9cacb2227648fc67b6794e5b44f0deac7c24"},"cell_type":"code","source":"#Team kills cannot be 4 or more so we have to remove this\nplt.figure(figsize=(15,10))\nsns.countplot(train[train['teamKills']>=4]['teamKills'])\nplt.title(\"TeamMate Kills\")\nplt.show()\ntrain[train['teamKills']>=4].shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8e2d85f1a0ab8d579d8781c76782f50c407c5d24"},"cell_type":"code","source":"#removing teamKills outliers\ntrain.drop(train[train['teamKills']>=4].index, inplace = True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e71997d7838a319aded7b25002968a0a397e9654"},"cell_type":"code","source":"print(\"Max number of HeadShots by Single Person {} Average Headshots {} While 99% percent people {} \".format(train['headshotKills'].max(),train['headshotKills'].mean(),train['headshotKills'].quantile(0.99)))\n### remove  outlier headshots ###","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7e119becdc462d615a392c354ee079bd797b7a66"},"cell_type":"markdown","source":"**Match Duration**"},{"metadata":{"trusted":true,"_uuid":"3eed8b2b072888608c7754cbf3c92c4cc645afbf"},"cell_type":"code","source":"######### has to do something with MatchDuration for match duration with less than 5min to 10 minutes######\n# train['check'] = train[train['matchDuration']<600]\nplt.figure(figsize=(15,10))\nsns.countplot(train[train['matchDuration']<600]['matchDuration'])\nplt.title(\"Match With Duration less tha 10 Minutes\")\nplt.show()\ntrain[train['matchDuration']<600].shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"09e298b2a4070c4d09ababf94243e38c3ca34799"},"cell_type":"code","source":"#we will drop the rows with match Duration less than 10 minutes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"b52124c33daa11e7a6969d76fc7ff4090e93618d"},"cell_type":"code","source":"print (\"Unique id counts {} while data shape {}\".format(train['Id'].nunique(),train.shape))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"99da1d152f31da4b434fe08de9ad5f7135c99f8c"},"cell_type":"code","source":"print(\"Max Number of Weapons acquired by individual {} Average Number of Weapons Acquired {} while 99% percentile {}\".format(train['weaponsAcquired'].max(),train['weaponsAcquired'].mean(),train['weaponsAcquired'].quantile(0.99)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1e14da7d16c4a6eba927a4ebbd6fe85375ede652"},"cell_type":"code","source":"#236 weapons acquired by an individual is of course an outlier\n#lets find outliers using weapons acquired\nplt.figure(figsize=(15,10))\nsns.countplot(train[train['weaponsAcquired']>50]['weaponsAcquired'])\nplt.show()\ntrain[train['weaponsAcquired']>50].shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"35fc1e22af05a4a33a7e084f1f9a67d2785fb251"},"cell_type":"code","source":"#we will remove rows with weapons acquired more than 40 as they seems suspicious\ntrain.drop(train[train['weaponsAcquired']>50].index, inplace = True)\n#lets plot WeaponsAcquired vs winPlacePerc\n# plt.figure(figsize=(15,10))\nsns.jointplot(x=\"winPlacePerc\",y=\"weaponsAcquired\",data=train,height=10,ratio=3,color=\"blue\")\nplt.title(\"WinPlacePerc vs WeaponsAcquired Realtion\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2506c0cc1add9ae45a010aa27c40c624045dedea","scrolled":true},"cell_type":"code","source":"# train.sort_values(by = ['groupId']).head()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ec80fe5d433d3c7b7595fed93f98da4e9fec20ff"},"cell_type":"markdown","source":"Lets Check If There are no entries with MatchType solo but has assists and Players Knocked"},{"metadata":{"trusted":true,"_uuid":"9263e6366367f9c99ece8f18c86ae6450d167c19"},"cell_type":"code","source":"# train['checkSolo'] = [1 if (x == \"solo\" or x == \"solo-fpp\") else 0 for x in train['matchType']]\ntrain['assistsCheck'] = [\"false\" if ((x == \"solo\" or x == \"solo-fpp\") and y!=0) else \"true\" for x,y in zip(train['matchType'],train['assists'])]\nprint (\"Number of assists in Solo :\",train[train['assistsCheck']==\"false\"].shape)\ntrain['DBNOCheck'] = [\"false\" if ((x == \"solo\" or x == \"solo-fpp\") and y!=0) else \"true\" for x,y in zip(train['matchType'],train['DBNOs'])]\nprint (\"Number of Knocks in Solos\",train[train['DBNOCheck']==\"false\"].shape)\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c6f3d013bb8d768835bae07d61152a468d0761e2"},"cell_type":"markdown","source":"There are 38848 assists in solo that can't be possible as there are no teammates in solo."},{"metadata":{"trusted":true,"_uuid":"dfa00a6059d3e52666c8a81347f57f823dca3c1b"},"cell_type":"code","source":"#lets remove these outliers from dataset\ntrain.drop(train[train['assistsCheck']==\"false\"].index, inplace = True)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"049910641df6661a6009def5bda6a65bf7ff9de1"},"cell_type":"markdown","source":"Let's Check WinplacePerc with Vehicle Destroys"},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"c41b8bfc3e26aa080a4ef2d37074f2de56a430cf"},"cell_type":"code","source":"# #plot winPlacePerc with Vehicle Destroyed\n# plt.figure(figsize = (15,10))\n# sns.countplot(train[train['vehicleDestroys']>0]['vehicleDestroys'])\n# plt.title(\"Vehicle Destroyed\")\n# plt.show()\n# # plt.figure(figsize = (15,10))\n# sns.jointplot(x=\"winPlacePerc\",y=\"vehicleDestroys\",data=train,height=10,ratio=3,color=\"lime\")\n# plt.title(\"Vehicle Destroyed jointplot\")\n# plt.show()\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7ff5318856ff15fa5a60ece83797f5471fcc0828"},"cell_type":"markdown","source":"Let's Look for Players with Kills but has not travelled a bit in the match and Players won the match with no distance Travelled"},{"metadata":{"trusted":true,"_uuid":"90a957af53df800aba2e2ccbb6091bf94015b723"},"cell_type":"code","source":"print (\"Maximum walk Distance Tracelled {} Average walk Distance Travelled {}\".format(train['walkDistance'].max(),train['walkDistance'].mean()))\nprint (\"Maximum ride Distance Tracelled {} Average ride Distance Travelled {}\".format(train['rideDistance'].max(),train['rideDistance'].mean()))\nprint (\"Maximum swim Distance Tracelled {} Average swim Distance Travelled {}\".format(train['swimDistance'].max(),train['swimDistance'].mean()))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"33977f3a3c9bcc33462ae309fa48cf154df3888d"},"cell_type":"code","source":"print (\"Maximum Total Distance Travelled by a Person in Single Match {} Average Total Distance Travelled {}\".format((train['walkDistance']+train['swimDistance']+train['rideDistance']).max(),(train['walkDistance']+train['swimDistance']+train['rideDistance']).mean()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9e9dc7b8846e0cc6e55bf7db31082aee4366a319"},"cell_type":"markdown","source":"Let's Plot the distance travelled"},{"metadata":{"trusted":true,"_uuid":"25e15ded490ced6262065c1d7c1c72b2ac9a7cc1"},"cell_type":"code","source":"plt.figure(figsize = (15,10))\nsns.countplot(train[train['walkDistance']>5000]['walkDistance'])\nplt.title(\"Distance Covered by Foot\")\nplt.show()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ba03eb039de675bb432825415b1be4d0be3f8cb4"},"cell_type":"code","source":"plt.figure(figsize = (15,10))\nsns.countplot(train[train['rideDistance']>1200]['rideDistance'])\nplt.title(\"Distance Covered by Ride\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e2663e1e8b49bac2eb0aca69d3bb73cdfd3306e9"},"cell_type":"code","source":"plt.figure(figsize = (15,10))\nsns.countplot(train[train['swimDistance']>1200]['swimDistance'])\nplt.title(\"Distance Covered by Swimming\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b6445bb19cfb115a05a2ea70834df8255a96be14"},"cell_type":"code","source":"#lets find jointplot for WinPlacePerc vs all distances\n#first Walk Distance\nsns.jointplot(x=\"winPlacePerc\",y=\"walkDistance\",data=train,height=10,ratio=3)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e5ace5f13788ec8192dfbb8d3c38a38b07626560"},"cell_type":"code","source":"#now check ride distance\nsns.jointplot(x=\"winPlacePerc\",y=\"rideDistance\",data=train,height=10,ratio=3,color=\"black\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5bfcc7195f8264b6e335c6d30b5592754e4d0349"},"cell_type":"code","source":"#now check swim distance\nsns.jointplot(x=\"winPlacePerc\",y=\"swimDistance\",data=train,height=10,ratio=3,color=\"pink\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"22017643248d6fca684e47960c5a6ced721f703c"},"cell_type":"code","source":"#at last total distancce\ntrain['totalDistance'] = train['walkDistance'] + train['rideDistance'] + train['swimDistance']\nsns.jointplot(x=\"winPlacePerc\",y=\"totalDistance\",data=train,height=10,ratio=3,color=\"green\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"86ebbce847c8e0f28522cc66d2196fc66ef1ef83"},"cell_type":"markdown","source":"from all those distance plot we can observe more you travel the higher is your WinPlacePerc i.e winning chances increaase the more you travel"},{"metadata":{"_uuid":"ccf1f2749e595403dc8edfca6f21fcb54ea06aba"},"cell_type":"markdown","source":"Let's check people with Total Distance travelled 0 and weapons Acquired and Kills for outliers in the data"},{"metadata":{"trusted":true,"_uuid":"68d9cf24ee2ae24abe067bbe15f759094f4e5a42"},"cell_type":"code","source":"df = train.copy()\ndf = df[(df['totalDistance']==0) & (df['weaponsAcquired']>=4)]\nprint (\"{} peoples cheated who donot move a bit but acquired weapons \".format(df['Id'].count()))\n# df.sort_values(by=['groupId']).head()\ntrain[train['groupId']==\"082950bbdd1d97\"].head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cb27b8474e0b27d4d1b095356674665bbb708191"},"cell_type":"markdown","source":"These data are no outliers as there teammates increased thier winPlacePerc not cheated"},{"metadata":{"trusted":true,"_uuid":"02f0e16a13bd6caea085ee52e0b8078b464e0343"},"cell_type":"code","source":"# df = train.copy()\n# df = df[(df['totalDistance']==0) & (df['kills']!=0)]\n# df.shape\n# df.head()\ndf = train.copy()\ndf = df[(df['totalDistance']==0) & (df['kills']!=0)]\nprint (\"{} peoples cheated who donot move a bit but acquired weapons \".format(df['Id'].count()))\ndf.sort_values(by=['groupId']).head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"65c90c2d9a4b4f5e8dc2bf9cc34d197c91b5b30f"},"cell_type":"code","source":"#lets see an entry and observe\ntrain[train['groupId']==\"0000a9f58703c5\"].head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ff7c792cc77173ea2b4fc1596c66b28b0cb47a64","collapsed":true},"cell_type":"code","source":"plt.figure(figsize=(15,10))\nsns.countplot(train[train['numGroups']>1]['numGroups'])\nplt.title(\"Number of Groups\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"15f463d8534f2207ff98a18809831025fdcc1b5f"},"cell_type":"markdown","source":"Let's Change Categorical Data"},{"metadata":{"trusted":true,"_uuid":"9192e5d38fb7eddc2804ae18bd2a36cfdb612a85"},"cell_type":"code","source":"# train['matchType'] = [1 if match ==\"solos\" 2 elif match ==\"duos\" else 3 for match in train['matchType']]\n# df.loc[df.set_of_numbers <= 4, 'equal_or_lower_than_4?'] = 'True' \n# df.loc[df.set_of_numbers > 4, 'equal_or_lower_than_4?'] = 'False' \ntrain.loc[train.matchType == \"solo\",'matchType'] = 1\ntrain.loc[train.matchType == \"duo\",'matchType'] = 2\ntrain.loc[train.matchType == \"squad\",'matchType'] = 3\ntrain.loc[train.matchType == \"solo-fpp\",'matchType'] = 4\ntrain.loc[train.matchType == \"duo-fpp\",'matchType'] = 5\ntrain.loc[train.matchType == \"squad-fpp\",'matchType'] = 6\ntrain.loc[(train.matchType != \"solo\") & (train.matchType != \"duo\") & (train.matchType != \"squad\") & (train.matchType != \"solo-fpp\") & (train.matchType != \"duo-fpp\") & (train.matchType != \"squad-fpp\"),'matchType'] = 7\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0b23c8087357dce5def3cb6b43905d711d70b526"},"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}