diff --git a/Prediction Models/PUBG_Game_Prediciton/pubg-game-predicition.ipynb b/Prediction Models/PUBG_Game_Prediciton/pubg-game-predicition.ipynb new file mode 100644 index 000000000..9bc66903d --- /dev/null +++ b/Prediction Models/PUBG_Game_Prediciton/pubg-game-predicition.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"code","execution_count":8,"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2024-06-24T05:27:50.917809Z","iopub.status.busy":"2024-06-24T05:27:50.917327Z","iopub.status.idle":"2024-06-24T05:27:51.387832Z","shell.execute_reply":"2024-06-24T05:27:51.386543Z","shell.execute_reply.started":"2024-06-24T05:27:50.917743Z"},"trusted":true},"outputs":[],"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\n","\n","import numpy as np # linear algebra\n","import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n","\n","# Input data files are available in the read-only \"../input/\" directory\n","# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n","\n","import os\n","for dirname, _, filenames in os.walk('/kaggle/input'):\n"," for filename in filenames:\n"," print(os.path.join(dirname, filename))\n","\n","# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n","# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"]},{"cell_type":"markdown","metadata":{},"source":["
PUBG Game Prediction
"]},{"cell_type":"markdown","metadata":{},"source":["
"]},{"cell_type":"markdown","metadata":{},"source":["Importing Libraries"]},{"cell_type":"code","execution_count":9,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:27:51.390449Z","iopub.status.busy":"2024-06-24T05:27:51.389993Z","iopub.status.idle":"2024-06-24T05:27:54.045873Z","shell.execute_reply":"2024-06-24T05:27:54.044659Z","shell.execute_reply.started":"2024-06-24T05:27:51.390419Z"},"trusted":true},"outputs":[],"source":["import pandas as pd\n","import numpy as np\n","\n","import matplotlib.pyplot as plt\n","%matplotlib inline\n","plt.rcParams[\"figure.figsize\"]=(16,6)\n","import seaborn as sns\n","\n","import warnings\n","warnings.filterwarnings(\"ignore\")\n","\n","from sklearn.preprocessing import StandardScaler\n","from sklearn.model_selection import train_test_split\n","\n","import catboost as cb\n","from sklearn.metrics import mean_squared_error\n","from sklearn.metrics import r2_score\n"]},{"cell_type":"markdown","metadata":{},"source":["Reading Data"]},{"cell_type":"code","execution_count":10,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:27:54.047905Z","iopub.status.busy":"2024-06-24T05:27:54.047444Z","iopub.status.idle":"2024-06-24T05:28:26.776651Z","shell.execute_reply":"2024-06-24T05:28:26.775455Z","shell.execute_reply.started":"2024-06-24T05:27:54.047866Z"},"trusted":true},"outputs":[],"source":["\n","df=pd.read_csv(\"PUBG_Game_Prediction_data.csv\")"]},{"cell_type":"code","execution_count":11,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:26.778662Z","iopub.status.busy":"2024-06-24T05:28:26.778202Z","iopub.status.idle":"2024-06-24T05:28:26.828048Z","shell.execute_reply":"2024-06-24T05:28:26.826713Z","shell.execute_reply.started":"2024-06-24T05:28:26.778622Z"},"trusted":true},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
IdgroupIdmatchIdassistsboostsdamageDealtDBNOsheadshotKillshealskillPlace...revivesrideDistanceroadKillsswimDistanceteamKillsvehicleDestroyswalkDistanceweaponsAcquiredwinPointswinPlacePerc
07f96b2f878858a4d4b580de459bea10357fd1a4a91000.0000060...00.000000.0000244.80114660.4444
1eef90569b9d03c684d5656442f9eaeb375fc57110c0091.4700057...00.0045011.04001434.00500.6400
21eaf90ac73de726a4a42c3245a74110163d8bb94ae1068.0000047...00.000000.0000161.80200.7755
34616d365dd2853a930a9c79cd721f1f1f4ef412d7e0032.9000075...00.000000.0000202.70300.1667
4315c96c26c9aacde04010b3458dd6dc8ff871e21e600100.0000045...00.000000.000049.75200.1875
\n","

5 rows × 29 columns

\n","
"],"text/plain":[" Id groupId matchId assists boosts \\\n","0 7f96b2f878858a 4d4b580de459be a10357fd1a4a91 0 0 \n","1 eef90569b9d03c 684d5656442f9e aeb375fc57110c 0 0 \n","2 1eaf90ac73de72 6a4a42c3245a74 110163d8bb94ae 1 0 \n","3 4616d365dd2853 a930a9c79cd721 f1f1f4ef412d7e 0 0 \n","4 315c96c26c9aac de04010b3458dd 6dc8ff871e21e6 0 0 \n","\n"," damageDealt DBNOs headshotKills heals killPlace ... revives \\\n","0 0.00 0 0 0 60 ... 0 \n","1 91.47 0 0 0 57 ... 0 \n","2 68.00 0 0 0 47 ... 0 \n","3 32.90 0 0 0 75 ... 0 \n","4 100.00 0 0 0 45 ... 0 \n","\n"," rideDistance roadKills swimDistance teamKills vehicleDestroys \\\n","0 0.0000 0 0.00 0 0 \n","1 0.0045 0 11.04 0 0 \n","2 0.0000 0 0.00 0 0 \n","3 0.0000 0 0.00 0 0 \n","4 0.0000 0 0.00 0 0 \n","\n"," walkDistance weaponsAcquired winPoints winPlacePerc \n","0 244.80 1 1466 0.4444 \n","1 1434.00 5 0 0.6400 \n","2 161.80 2 0 0.7755 \n","3 202.70 3 0 0.1667 \n","4 49.75 2 0 0.1875 \n","\n","[5 rows x 29 columns]"]},"execution_count":11,"metadata":{},"output_type":"execute_result"}],"source":["df.head()"]},{"cell_type":"code","execution_count":12,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:26.832349Z","iopub.status.busy":"2024-06-24T05:28:26.831969Z","iopub.status.idle":"2024-06-24T05:28:26.861241Z","shell.execute_reply":"2024-06-24T05:28:26.859916Z","shell.execute_reply.started":"2024-06-24T05:28:26.832310Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["\n","RangeIndex: 4446966 entries, 0 to 4446965\n","Data columns (total 29 columns):\n"," # Column Dtype \n","--- ------ ----- \n"," 0 Id object \n"," 1 groupId object \n"," 2 matchId object \n"," 3 assists int64 \n"," 4 boosts int64 \n"," 5 damageDealt float64\n"," 6 DBNOs int64 \n"," 7 headshotKills int64 \n"," 8 heals int64 \n"," 9 killPlace int64 \n"," 10 killPoints int64 \n"," 11 kills int64 \n"," 12 killStreaks int64 \n"," 13 longestKill float64\n"," 14 matchDuration int64 \n"," 15 matchType object \n"," 16 maxPlace int64 \n"," 17 numGroups int64 \n"," 18 rankPoints int64 \n"," 19 revives int64 \n"," 20 rideDistance float64\n"," 21 roadKills int64 \n"," 22 swimDistance float64\n"," 23 teamKills int64 \n"," 24 vehicleDestroys int64 \n"," 25 walkDistance float64\n"," 26 weaponsAcquired int64 \n"," 27 winPoints int64 \n"," 28 winPlacePerc float64\n","dtypes: float64(6), int64(19), object(4)\n","memory usage: 983.9+ MB\n"]}],"source":["df.info()"]},{"cell_type":"code","execution_count":13,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:26.863316Z","iopub.status.busy":"2024-06-24T05:28:26.862911Z","iopub.status.idle":"2024-06-24T05:28:26.878124Z","shell.execute_reply":"2024-06-24T05:28:26.876893Z","shell.execute_reply.started":"2024-06-24T05:28:26.863281Z"},"trusted":true},"outputs":[{"data":{"text/plain":["(4446966, 29)"]},"execution_count":13,"metadata":{},"output_type":"execute_result"}],"source":["df.shape"]},{"cell_type":"code","execution_count":14,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:26.880738Z","iopub.status.busy":"2024-06-24T05:28:26.880271Z","iopub.status.idle":"2024-06-24T05:28:28.873923Z","shell.execute_reply":"2024-06-24T05:28:28.872842Z","shell.execute_reply.started":"2024-06-24T05:28:26.880696Z"},"trusted":true},"outputs":[{"data":{"text/plain":["Id 0\n","groupId 0\n","matchId 0\n","assists 0\n","boosts 0\n","damageDealt 0\n","DBNOs 0\n","headshotKills 0\n","heals 0\n","killPlace 0\n","killPoints 0\n","kills 0\n","killStreaks 0\n","longestKill 0\n","matchDuration 0\n","matchType 0\n","maxPlace 0\n","numGroups 0\n","rankPoints 0\n","revives 0\n","rideDistance 0\n","roadKills 0\n","swimDistance 0\n","teamKills 0\n","vehicleDestroys 0\n","walkDistance 0\n","weaponsAcquired 0\n","winPoints 0\n","winPlacePerc 1\n","dtype: int64"]},"execution_count":14,"metadata":{},"output_type":"execute_result"}],"source":["df.isnull().sum()"]},{"cell_type":"markdown","metadata":{},"source":["Data Wrangling "]},{"cell_type":"markdown","metadata":{},"source":["**Check for the rows with missing win prediciton value**"]},{"cell_type":"code","execution_count":15,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:28.875765Z","iopub.status.busy":"2024-06-24T05:28:28.875398Z","iopub.status.idle":"2024-06-24T05:28:28.908285Z","shell.execute_reply":"2024-06-24T05:28:28.906959Z","shell.execute_reply.started":"2024-06-24T05:28:28.875721Z"},"trusted":true},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
IdgroupIdmatchIdassistsboostsdamageDealtDBNOsheadshotKillshealskillPlace...revivesrideDistanceroadKillsswimDistanceteamKillsvehicleDestroyswalkDistanceweaponsAcquiredwinPointswinPlacePerc
2744604f70c74418bb06412dfbede33f92b224a123c53e008000.00001...00.000.0000.000NaN
\n","

1 rows × 29 columns

\n","
"],"text/plain":[" Id groupId matchId assists boosts \\\n","2744604 f70c74418bb064 12dfbede33f92b 224a123c53e008 0 0 \n","\n"," damageDealt DBNOs headshotKills heals killPlace ... revives \\\n","2744604 0.0 0 0 0 1 ... 0 \n","\n"," rideDistance roadKills swimDistance teamKills vehicleDestroys \\\n","2744604 0.0 0 0.0 0 0 \n","\n"," walkDistance weaponsAcquired winPoints winPlacePerc \n","2744604 0.0 0 0 NaN \n","\n","[1 rows x 29 columns]"]},"execution_count":15,"metadata":{},"output_type":"execute_result"}],"source":["df[df['winPlacePerc'].isnull()]"]},{"cell_type":"code","execution_count":16,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:28.910104Z","iopub.status.busy":"2024-06-24T05:28:28.909719Z","iopub.status.idle":"2024-06-24T05:28:29.674919Z","shell.execute_reply":"2024-06-24T05:28:29.673791Z","shell.execute_reply.started":"2024-06-24T05:28:28.910071Z"},"trusted":true},"outputs":[],"source":["df.drop(2744604,inplace=True)"]},{"cell_type":"markdown","metadata":{},"source":["**Understanding Player Distribution in game**"]},{"cell_type":"code","execution_count":17,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:29.676775Z","iopub.status.busy":"2024-06-24T05:28:29.676414Z","iopub.status.idle":"2024-06-24T05:28:31.397237Z","shell.execute_reply":"2024-06-24T05:28:31.396150Z","shell.execute_reply.started":"2024-06-24T05:28:29.676727Z"},"trusted":true},"outputs":[],"source":["# Prepare new parameter to count how many new players are in game\n","df['PlayersJoined']=df.groupby('matchId')['matchId'].transform('count') "]},{"cell_type":"code","execution_count":18,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:31.398711Z","iopub.status.busy":"2024-06-24T05:28:31.398372Z","iopub.status.idle":"2024-06-24T05:28:31.425196Z","shell.execute_reply":"2024-06-24T05:28:31.423833Z","shell.execute_reply.started":"2024-06-24T05:28:31.398683Z"},"trusted":true},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
IdgroupIdmatchIdassistsboostsdamageDealtDBNOsheadshotKillshealskillPlace...rideDistanceroadKillsswimDistanceteamKillsvehicleDestroyswalkDistanceweaponsAcquiredwinPointswinPlacePercPlayersJoined
07f96b2f878858a4d4b580de459bea10357fd1a4a91000.0000060...0.000000.0000244.80114660.444496
1eef90569b9d03c684d5656442f9eaeb375fc57110c0091.4700057...0.0045011.04001434.00500.640091
21eaf90ac73de726a4a42c3245a74110163d8bb94ae1068.0000047...0.000000.0000161.80200.775598
34616d365dd2853a930a9c79cd721f1f1f4ef412d7e0032.9000075...0.000000.0000202.70300.166791
4315c96c26c9aacde04010b3458dd6dc8ff871e21e600100.0000045...0.000000.000049.75200.187597
\n","

5 rows × 30 columns

\n","
"],"text/plain":[" Id groupId matchId assists boosts \\\n","0 7f96b2f878858a 4d4b580de459be a10357fd1a4a91 0 0 \n","1 eef90569b9d03c 684d5656442f9e aeb375fc57110c 0 0 \n","2 1eaf90ac73de72 6a4a42c3245a74 110163d8bb94ae 1 0 \n","3 4616d365dd2853 a930a9c79cd721 f1f1f4ef412d7e 0 0 \n","4 315c96c26c9aac de04010b3458dd 6dc8ff871e21e6 0 0 \n","\n"," damageDealt DBNOs headshotKills heals killPlace ... rideDistance \\\n","0 0.00 0 0 0 60 ... 0.0000 \n","1 91.47 0 0 0 57 ... 0.0045 \n","2 68.00 0 0 0 47 ... 0.0000 \n","3 32.90 0 0 0 75 ... 0.0000 \n","4 100.00 0 0 0 45 ... 0.0000 \n","\n"," roadKills swimDistance teamKills vehicleDestroys walkDistance \\\n","0 0 0.00 0 0 244.80 \n","1 0 11.04 0 0 1434.00 \n","2 0 0.00 0 0 161.80 \n","3 0 0.00 0 0 202.70 \n","4 0 0.00 0 0 49.75 \n","\n"," weaponsAcquired winPoints winPlacePerc PlayersJoined \n","0 1 1466 0.4444 96 \n","1 5 0 0.6400 91 \n","2 2 0 0.7755 98 \n","3 3 0 0.1667 91 \n","4 2 0 0.1875 97 \n","\n","[5 rows x 30 columns]"]},"execution_count":18,"metadata":{},"output_type":"execute_result"}],"source":["df.head()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:31.427572Z","iopub.status.busy":"2024-06-24T05:28:31.427095Z","iopub.status.idle":"2024-06-24T05:28:32.526412Z","shell.execute_reply":"2024-06-24T05:28:32.524981Z","shell.execute_reply.started":"2024-06-24T05:28:31.427509Z"},"trusted":true},"outputs":[],"source":["sns.countplot(df[df['PlayersJoined']>=75]['PlayersJoined'])\n","plt.show()"]},{"cell_type":"markdown","metadata":{},"source":["Analysing data"]},{"cell_type":"markdown","metadata":{},"source":["**Kills Without Moving ?**"]},{"cell_type":"markdown","metadata":{},"source":["
"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:32.528191Z","iopub.status.busy":"2024-06-24T05:28:32.527814Z","iopub.status.idle":"2024-06-24T05:28:32.570818Z","shell.execute_reply":"2024-06-24T05:28:32.569536Z","shell.execute_reply.started":"2024-06-24T05:28:32.528159Z"},"trusted":true},"outputs":[],"source":["#prepare new data parameter to gather the total distance travelled\n","df['totalDistance']=df['rideDistance'] +df['swimDistance']+df['walkDistance'] \n","\n","#Preparing the data parameter to check for anmoly detection \n","# that the person has not moved but still manages to do the kills\n","\n","df['KillsWithoutMoving']=((df['kills']>0) & (df['totalDistance']==0))"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:32.577398Z","iopub.status.busy":"2024-06-24T05:28:32.576997Z","iopub.status.idle":"2024-06-24T05:28:32.612637Z","shell.execute_reply":"2024-06-24T05:28:32.611312Z","shell.execute_reply.started":"2024-06-24T05:28:32.577363Z"},"trusted":true},"outputs":[],"source":["# Here we can see that there are\n","df[df['KillsWithoutMoving']==True].head()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:32.614357Z","iopub.status.busy":"2024-06-24T05:28:32.614015Z","iopub.status.idle":"2024-06-24T05:28:32.630860Z","shell.execute_reply":"2024-06-24T05:28:32.629676Z","shell.execute_reply.started":"2024-06-24T05:28:32.614321Z"},"trusted":true},"outputs":[],"source":["df[df['KillsWithoutMoving']==True].index"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:32.632729Z","iopub.status.busy":"2024-06-24T05:28:32.632269Z","iopub.status.idle":"2024-06-24T05:28:32.650062Z","shell.execute_reply":"2024-06-24T05:28:32.648848Z","shell.execute_reply.started":"2024-06-24T05:28:32.632684Z"},"trusted":true},"outputs":[],"source":["# here \n","df[df['KillsWithoutMoving']==True].shape"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:32.652007Z","iopub.status.busy":"2024-06-24T05:28:32.651529Z","iopub.status.idle":"2024-06-24T05:28:33.739951Z","shell.execute_reply":"2024-06-24T05:28:33.738797Z","shell.execute_reply.started":"2024-06-24T05:28:32.651961Z"},"trusted":true},"outputs":[],"source":["#drop the table\n","df.drop(df[df['KillsWithoutMoving']==True].index,inplace=True)"]},{"cell_type":"markdown","metadata":{},"source":["**EXTRA ORDINARY ROAD KILLS ??**"]},{"cell_type":"markdown","metadata":{},"source":["
"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:33.742037Z","iopub.status.busy":"2024-06-24T05:28:33.741647Z","iopub.status.idle":"2024-06-24T05:28:33.775781Z","shell.execute_reply":"2024-06-24T05:28:33.774539Z","shell.execute_reply.started":"2024-06-24T05:28:33.742004Z"},"trusted":true},"outputs":[],"source":["df[df['roadKills']>5].head()\n"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:33.778585Z","iopub.status.busy":"2024-06-24T05:28:33.778126Z","iopub.status.idle":"2024-06-24T05:28:33.791572Z","shell.execute_reply":"2024-06-24T05:28:33.790025Z","shell.execute_reply.started":"2024-06-24T05:28:33.778545Z"},"trusted":true},"outputs":[],"source":["print(df[df['roadKills']>5].shape)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:33.793824Z","iopub.status.busy":"2024-06-24T05:28:33.793306Z","iopub.status.idle":"2024-06-24T05:28:35.142063Z","shell.execute_reply":"2024-06-24T05:28:35.140793Z","shell.execute_reply.started":"2024-06-24T05:28:33.793779Z"},"trusted":true},"outputs":[],"source":["#Dropping the Extraordinary road kills\n","df.drop(df[df['roadKills']>5].index,inplace=True)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:35.144500Z","iopub.status.busy":"2024-06-24T05:28:35.144032Z","iopub.status.idle":"2024-06-24T05:28:35.154841Z","shell.execute_reply":"2024-06-24T05:28:35.153492Z","shell.execute_reply.started":"2024-06-24T05:28:35.144455Z"},"trusted":true},"outputs":[],"source":["# cleared all the extraordinary road kills\n","print(df[df['roadKills']>5].shape)"]},{"cell_type":"markdown","metadata":{},"source":["## SO Many KILLS -HOW ??"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:35.156578Z","iopub.status.busy":"2024-06-24T05:28:35.156219Z","iopub.status.idle":"2024-06-24T05:28:35.195175Z","shell.execute_reply":"2024-06-24T05:28:35.193965Z","shell.execute_reply.started":"2024-06-24T05:28:35.156546Z"},"trusted":true},"outputs":[],"source":["df[df['kills']>20].head()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:35.196896Z","iopub.status.busy":"2024-06-24T05:28:35.196526Z","iopub.status.idle":"2024-06-24T05:28:37.785039Z","shell.execute_reply":"2024-06-24T05:28:37.783824Z","shell.execute_reply.started":"2024-06-24T05:28:35.196865Z"},"trusted":true},"outputs":[],"source":["sns.countplot(data=df,x=df['kills']).set_title(\"Distribution of KILLS by a player\")\n","plt.xlabel(\"Number of Kills\")\n","plt.ylabel(\"Count of players\")\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:37.786859Z","iopub.status.busy":"2024-06-24T05:28:37.786455Z","iopub.status.idle":"2024-06-24T05:28:37.802907Z","shell.execute_reply":"2024-06-24T05:28:37.801550Z","shell.execute_reply.started":"2024-06-24T05:28:37.786824Z"},"trusted":true},"outputs":[],"source":["df[df['kills']>15].shape"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:37.804646Z","iopub.status.busy":"2024-06-24T05:28:37.804266Z","iopub.status.idle":"2024-06-24T05:28:38.419430Z","shell.execute_reply":"2024-06-24T05:28:38.418031Z","shell.execute_reply.started":"2024-06-24T05:28:37.804612Z"},"trusted":true},"outputs":[],"source":["# Upto 15 kills can ne normal \n","sns.countplot(x=df[df['kills']>=15][\"kills\"]).set_title(\"Distribution of KILLS by a player\")\n","plt.xlabel(\"Number of Kills\")\n","plt.ylabel(\"Count of players\")\n","plt.show()"]},{"cell_type":"markdown","metadata":{},"source":["## Removing Kills greater than 20 from dataset"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:38.421721Z","iopub.status.busy":"2024-06-24T05:28:38.421025Z","iopub.status.idle":"2024-06-24T05:28:38.437521Z","shell.execute_reply":"2024-06-24T05:28:38.435024Z","shell.execute_reply.started":"2024-06-24T05:28:38.421676Z"},"trusted":true},"outputs":[],"source":["df[df['kills']>20].shape"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:38.439961Z","iopub.status.busy":"2024-06-24T05:28:38.439524Z","iopub.status.idle":"2024-06-24T05:28:39.644898Z","shell.execute_reply":"2024-06-24T05:28:39.643509Z","shell.execute_reply.started":"2024-06-24T05:28:38.439926Z"},"trusted":true},"outputs":[],"source":["# Dropping all 417 vlaues from given dataset\n","df.drop(df[df['kills']>20].index,inplace =True)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:39.646949Z","iopub.status.busy":"2024-06-24T05:28:39.646510Z","iopub.status.idle":"2024-06-24T05:28:39.659911Z","shell.execute_reply":"2024-06-24T05:28:39.658836Z","shell.execute_reply.started":"2024-06-24T05:28:39.646913Z"},"trusted":true},"outputs":[],"source":["df[df['kills']>20].shape"]},{"cell_type":"markdown","metadata":{},"source":["## HeadShot"]},{"cell_type":"markdown","metadata":{},"source":["
\n"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:39.662120Z","iopub.status.busy":"2024-06-24T05:28:39.661662Z","iopub.status.idle":"2024-06-24T05:28:39.715627Z","shell.execute_reply":"2024-06-24T05:28:39.714290Z","shell.execute_reply.started":"2024-06-24T05:28:39.662073Z"},"trusted":true},"outputs":[],"source":["df['Headshot_rate']=df['headshotKills']/df['kills']\n","df['Headshot_rate']=df['Headshot_rate'].fillna(0)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:28:39.717532Z","iopub.status.busy":"2024-06-24T05:28:39.717170Z","iopub.status.idle":"2024-06-24T05:29:00.358870Z","shell.execute_reply":"2024-06-24T05:29:00.357305Z","shell.execute_reply.started":"2024-06-24T05:28:39.717502Z"},"trusted":true},"outputs":[],"source":["sns.distplot(df['Headshot_rate'],bins=10).set_title(\"Histogram showing the distribuyion of headshot rate\")\n","plt.ylabel(\"Count of Players\")\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:00.361128Z","iopub.status.busy":"2024-06-24T05:29:00.360641Z","iopub.status.idle":"2024-06-24T05:29:00.387290Z","shell.execute_reply":"2024-06-24T05:29:00.385963Z","shell.execute_reply.started":"2024-06-24T05:29:00.361084Z"},"trusted":true},"outputs":[],"source":["df[(df['Headshot_rate']==1)& (df['kills']>5)].shape"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:00.389147Z","iopub.status.busy":"2024-06-24T05:29:00.388763Z","iopub.status.idle":"2024-06-24T05:29:01.666440Z","shell.execute_reply":"2024-06-24T05:29:01.665414Z","shell.execute_reply.started":"2024-06-24T05:29:00.389112Z"},"trusted":true},"outputs":[],"source":["df.drop(df[(df['Headshot_rate']==1)& (df['kills']>6)].index,inplace=True)"]},{"cell_type":"markdown","metadata":{},"source":["## Longest Shot"]},{"cell_type":"markdown","metadata":{},"source":["
"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:01.668205Z","iopub.status.busy":"2024-06-24T05:29:01.667851Z","iopub.status.idle":"2024-06-24T05:29:20.428228Z","shell.execute_reply":"2024-06-24T05:29:20.426953Z","shell.execute_reply.started":"2024-06-24T05:29:01.668164Z"},"trusted":true},"outputs":[],"source":["sns.distplot(df['longestKill'],bins=50).set_title(\"Histogram Shoeing Longest Kill Distribution\")\n","plt.ylabel('Count of Players')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:20.430125Z","iopub.status.busy":"2024-06-24T05:29:20.429740Z","iopub.status.idle":"2024-06-24T05:29:20.450581Z","shell.execute_reply":"2024-06-24T05:29:20.449400Z","shell.execute_reply.started":"2024-06-24T05:29:20.430092Z"},"trusted":true},"outputs":[],"source":["df[df['longestKill']>500].shape"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:20.452250Z","iopub.status.busy":"2024-06-24T05:29:20.451808Z","iopub.status.idle":"2024-06-24T05:29:21.665356Z","shell.execute_reply":"2024-06-24T05:29:21.664262Z","shell.execute_reply.started":"2024-06-24T05:29:20.452216Z"},"trusted":true},"outputs":[],"source":["df.drop(df[df['longestKill']>500].index,inplace=True)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:21.667153Z","iopub.status.busy":"2024-06-24T05:29:21.666807Z","iopub.status.idle":"2024-06-24T05:29:21.682046Z","shell.execute_reply":"2024-06-24T05:29:21.680736Z","shell.execute_reply.started":"2024-06-24T05:29:21.667122Z"},"trusted":true},"outputs":[],"source":["df[df['longestKill']>500].shape"]},{"cell_type":"markdown","metadata":{},"source":["## Weapon Change"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:21.684349Z","iopub.status.busy":"2024-06-24T05:29:21.683903Z","iopub.status.idle":"2024-06-24T05:29:40.484302Z","shell.execute_reply":"2024-06-24T05:29:40.482858Z","shell.execute_reply.started":"2024-06-24T05:29:21.684307Z"},"trusted":true},"outputs":[],"source":["sns.distplot(df['weaponsAcquired'],bins=100).set_title(\"Weapon Distribution\")\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:40.486560Z","iopub.status.busy":"2024-06-24T05:29:40.486165Z","iopub.status.idle":"2024-06-24T05:29:40.509393Z","shell.execute_reply":"2024-06-24T05:29:40.507795Z","shell.execute_reply.started":"2024-06-24T05:29:40.486524Z"},"trusted":true},"outputs":[],"source":["# Dropping the weapons changed more than 50 times\n","df[df['weaponsAcquired']>15].shape"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:40.511865Z","iopub.status.busy":"2024-06-24T05:29:40.511346Z","iopub.status.idle":"2024-06-24T05:29:41.940720Z","shell.execute_reply":"2024-06-24T05:29:41.939514Z","shell.execute_reply.started":"2024-06-24T05:29:40.511821Z"},"trusted":true},"outputs":[],"source":["df.drop(df[df['weaponsAcquired']>15].index,inplace=True)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:41.942801Z","iopub.status.busy":"2024-06-24T05:29:41.942380Z","iopub.status.idle":"2024-06-24T05:29:41.955956Z","shell.execute_reply":"2024-06-24T05:29:41.954378Z","shell.execute_reply.started":"2024-06-24T05:29:41.942764Z"},"trusted":true},"outputs":[],"source":["df[df['weaponsAcquired']>15].shape"]},{"cell_type":"markdown","metadata":{},"source":["## EDA\n"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:41.967753Z","iopub.status.busy":"2024-06-24T05:29:41.967323Z","iopub.status.idle":"2024-06-24T05:29:41.976874Z","shell.execute_reply":"2024-06-24T05:29:41.975451Z","shell.execute_reply.started":"2024-06-24T05:29:41.967721Z"},"trusted":true},"outputs":[],"source":["df.shape"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:41.978900Z","iopub.status.busy":"2024-06-24T05:29:41.978488Z","iopub.status.idle":"2024-06-24T05:29:44.046289Z","shell.execute_reply":"2024-06-24T05:29:44.044937Z","shell.execute_reply.started":"2024-06-24T05:29:41.978867Z"},"trusted":true},"outputs":[],"source":["df.isnull().sum()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.048701Z","iopub.status.busy":"2024-06-24T05:29:44.048214Z","iopub.status.idle":"2024-06-24T05:29:44.064332Z","shell.execute_reply":"2024-06-24T05:29:44.062917Z","shell.execute_reply.started":"2024-06-24T05:29:44.048656Z"},"trusted":true},"outputs":[],"source":["df.info()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.066740Z","iopub.status.busy":"2024-06-24T05:29:44.066280Z","iopub.status.idle":"2024-06-24T05:29:44.075617Z","shell.execute_reply":"2024-06-24T05:29:44.074432Z","shell.execute_reply.started":"2024-06-24T05:29:44.066700Z"},"trusted":true},"outputs":[],"source":["###sns.heatmap(df.corr(),annot=True)\n","#pplt.show()"]},{"cell_type":"markdown","metadata":{},"source":["## Feature Engineering"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.077981Z","iopub.status.busy":"2024-06-24T05:29:44.077507Z","iopub.status.idle":"2024-06-24T05:29:44.108245Z","shell.execute_reply":"2024-06-24T05:29:44.106877Z","shell.execute_reply.started":"2024-06-24T05:29:44.077940Z"},"trusted":true},"outputs":[],"source":["normalising_factor=(100 - df['PlayersJoined']/100)+1"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.110275Z","iopub.status.busy":"2024-06-24T05:29:44.109869Z","iopub.status.idle":"2024-06-24T05:29:44.120275Z","shell.execute_reply":"2024-06-24T05:29:44.119064Z","shell.execute_reply.started":"2024-06-24T05:29:44.110243Z"},"trusted":true},"outputs":[],"source":["normalising_factor"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.122717Z","iopub.status.busy":"2024-06-24T05:29:44.122065Z","iopub.status.idle":"2024-06-24T05:29:44.262274Z","shell.execute_reply":"2024-06-24T05:29:44.261022Z","shell.execute_reply.started":"2024-06-24T05:29:44.122664Z"},"trusted":true},"outputs":[],"source":["df['killsNorm']=df['kills'] * normalising_factor\n","df['damageDealtNorm']=df['damageDealt'] * normalising_factor\n","df['maxPlaceNorm']=df['maxPlace']* normalising_factor\n","df['matchDurationNorm']=df['matchDuration']* normalising_factor\n","\n","df['travelDistance']=df['rideDistance'] +df['swimDistance']+df['walkDistance'] \n","df['healsnboost']=df['heals'] + df['boosts']\n","df['assist']=df['assists'] + df['revives']\n"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.264789Z","iopub.status.busy":"2024-06-24T05:29:44.264011Z","iopub.status.idle":"2024-06-24T05:29:44.274725Z","shell.execute_reply":"2024-06-24T05:29:44.273507Z","shell.execute_reply.started":"2024-06-24T05:29:44.264713Z"},"trusted":true},"outputs":[],"source":["df.columns"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.277433Z","iopub.status.busy":"2024-06-24T05:29:44.276217Z","iopub.status.idle":"2024-06-24T05:29:44.726195Z","shell.execute_reply":"2024-06-24T05:29:44.724951Z","shell.execute_reply.started":"2024-06-24T05:29:44.277384Z"},"trusted":true},"outputs":[],"source":["data=df.drop(columns=['Id','groupId','matchId','assists','boosts','walkDistance','swimDistance','rideDistance','heals','revives','kills','damageDealt','matchDuration','maxPlace'])"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.728237Z","iopub.status.busy":"2024-06-24T05:29:44.727865Z","iopub.status.idle":"2024-06-24T05:29:44.759187Z","shell.execute_reply":"2024-06-24T05:29:44.757717Z","shell.execute_reply.started":"2024-06-24T05:29:44.728208Z"},"trusted":true},"outputs":[],"source":["data.head()"]},{"cell_type":"markdown","metadata":{},"source":["
ML - Catboost Model
"]},{"cell_type":"markdown","metadata":{},"source":["## Handling Categorical Values"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:44.761646Z","iopub.status.busy":"2024-06-24T05:29:44.761140Z","iopub.status.idle":"2024-06-24T05:29:45.324541Z","shell.execute_reply":"2024-06-24T05:29:45.323220Z","shell.execute_reply.started":"2024-06-24T05:29:44.761602Z"},"trusted":true},"outputs":[],"source":["x=data.drop(['winPlacePerc'],axis=1)\n","y=data['winPlacePerc']"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:45.326530Z","iopub.status.busy":"2024-06-24T05:29:45.326163Z","iopub.status.idle":"2024-06-24T05:29:45.331930Z","shell.execute_reply":"2024-06-24T05:29:45.330529Z","shell.execute_reply.started":"2024-06-24T05:29:45.326496Z"},"trusted":true},"outputs":[],"source":["features=x.columns"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:45.334381Z","iopub.status.busy":"2024-06-24T05:29:45.333995Z","iopub.status.idle":"2024-06-24T05:29:47.527957Z","shell.execute_reply":"2024-06-24T05:29:47.526484Z","shell.execute_reply.started":"2024-06-24T05:29:45.334340Z"},"trusted":true},"outputs":[],"source":["x=pd.get_dummies(x,columns=['matchType','KillsWithoutMoving'])"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:47.529907Z","iopub.status.busy":"2024-06-24T05:29:47.529500Z","iopub.status.idle":"2024-06-24T05:29:47.556181Z","shell.execute_reply":"2024-06-24T05:29:47.554778Z","shell.execute_reply.started":"2024-06-24T05:29:47.529874Z"},"trusted":true},"outputs":[],"source":["x.head()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:47.558586Z","iopub.status.busy":"2024-06-24T05:29:47.558180Z","iopub.status.idle":"2024-06-24T05:29:47.569111Z","shell.execute_reply":"2024-06-24T05:29:47.567823Z","shell.execute_reply.started":"2024-06-24T05:29:47.558550Z"},"trusted":true},"outputs":[],"source":["x.shape"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:47.571248Z","iopub.status.busy":"2024-06-24T05:29:47.570853Z","iopub.status.idle":"2024-06-24T05:29:47.582955Z","shell.execute_reply":"2024-06-24T05:29:47.581827Z","shell.execute_reply.started":"2024-06-24T05:29:47.571214Z"},"trusted":true},"outputs":[],"source":["features=x.columns"]},{"cell_type":"markdown","metadata":{},"source":["## Scaling The data"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:29:47.584610Z","iopub.status.busy":"2024-06-24T05:29:47.584244Z","iopub.status.idle":"2024-06-24T05:30:02.020932Z","shell.execute_reply":"2024-06-24T05:30:02.019763Z","shell.execute_reply.started":"2024-06-24T05:29:47.584570Z"},"trusted":true},"outputs":[],"source":["sc=StandardScaler()\n","sc.fit(x)\n","x=pd.DataFrame(sc.transform(x))"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:30:02.022585Z","iopub.status.busy":"2024-06-24T05:30:02.022241Z","iopub.status.idle":"2024-06-24T05:30:02.051541Z","shell.execute_reply":"2024-06-24T05:30:02.050191Z","shell.execute_reply.started":"2024-06-24T05:30:02.022555Z"},"trusted":true},"outputs":[],"source":["x.head()"]},{"cell_type":"markdown","metadata":{},"source":["## Splitting Data"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:30:02.053405Z","iopub.status.busy":"2024-06-24T05:30:02.053014Z","iopub.status.idle":"2024-06-24T05:30:05.305503Z","shell.execute_reply":"2024-06-24T05:30:05.304041Z","shell.execute_reply.started":"2024-06-24T05:30:02.053333Z"},"trusted":true},"outputs":[],"source":["xtrain,xtest,ytrain,ytest=train_test_split(x,y,test_size=0.3,random_state=0)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:30:05.307425Z","iopub.status.busy":"2024-06-24T05:30:05.307047Z","iopub.status.idle":"2024-06-24T05:30:05.314273Z","shell.execute_reply":"2024-06-24T05:30:05.313036Z","shell.execute_reply.started":"2024-06-24T05:30:05.307392Z"},"trusted":true},"outputs":[],"source":["print(xtrain.shape, ytrain.shape)\n","print(xtest.shape, ytest.shape)"]},{"cell_type":"markdown","metadata":{},"source":["## CatBOOST MODEL"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:30:05.316497Z","iopub.status.busy":"2024-06-24T05:30:05.315984Z","iopub.status.idle":"2024-06-24T05:30:05.324343Z","shell.execute_reply":"2024-06-24T05:30:05.323143Z","shell.execute_reply.started":"2024-06-24T05:30:05.316453Z"},"trusted":true},"outputs":[],"source":["import catboost as cb"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:30:05.325986Z","iopub.status.busy":"2024-06-24T05:30:05.325604Z","iopub.status.idle":"2024-06-24T05:30:05.369908Z","shell.execute_reply":"2024-06-24T05:30:05.368695Z","shell.execute_reply.started":"2024-06-24T05:30:05.325956Z"},"trusted":true},"outputs":[],"source":["train_dataset=cb.Pool(xtrain,ytrain)\n","test_dataset=cb.Pool(xtest,ytest)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:30:05.371621Z","iopub.status.busy":"2024-06-24T05:30:05.371260Z","iopub.status.idle":"2024-06-24T05:30:05.378979Z","shell.execute_reply":"2024-06-24T05:30:05.377716Z","shell.execute_reply.started":"2024-06-24T05:30:05.371590Z"},"trusted":true},"outputs":[],"source":["model=cb.CatBoostRegressor(loss_function='RMSE')"]},{"cell_type":"markdown","metadata":{},"source":["## GRID SEARCH"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:30:05.380858Z","iopub.status.busy":"2024-06-24T05:30:05.380426Z","iopub.status.idle":"2024-06-24T05:45:05.574011Z","shell.execute_reply":"2024-06-24T05:45:05.572613Z","shell.execute_reply.started":"2024-06-24T05:30:05.380811Z"},"trusted":true},"outputs":[],"source":["grid={'iterations':[100, 150],\n"," 'learning_rate':[0.03,0.1],\n"," 'depth':[2 ,4, 6, 8]}\n","\n","model.grid_search(grid, train_dataset)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:45:05.576194Z","iopub.status.busy":"2024-06-24T05:45:05.575687Z","iopub.status.idle":"2024-06-24T05:45:05.586392Z","shell.execute_reply":"2024-06-24T05:45:05.585118Z","shell.execute_reply.started":"2024-06-24T05:45:05.576148Z"},"trusted":true},"outputs":[],"source":["feature_importance_df=pd.DataFrame()\n","feature_importance_df['features']=features\n","feature_importance_df['importance']=model.feature_importances_\n","\n","feature_importance_df=feature_importance_df.sort_values(by=['importance'],ascending=False)"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:45:05.588226Z","iopub.status.busy":"2024-06-24T05:45:05.587864Z","iopub.status.idle":"2024-06-24T05:45:05.614008Z","shell.execute_reply":"2024-06-24T05:45:05.612681Z","shell.execute_reply.started":"2024-06-24T05:45:05.588193Z"},"trusted":true},"outputs":[],"source":["feature_importance_df"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:45:05.616121Z","iopub.status.busy":"2024-06-24T05:45:05.615638Z","iopub.status.idle":"2024-06-24T05:45:06.271364Z","shell.execute_reply":"2024-06-24T05:45:06.270095Z","shell.execute_reply.started":"2024-06-24T05:45:05.616079Z"},"trusted":true},"outputs":[],"source":["plt.bar(feature_importance_df.features,feature_importance_df.importance,color='turquoise')\n","plt.ylabel(\"CatBoost Feature Importance\")\n","plt.xticks(rotation=90)\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:45:06.273460Z","iopub.status.busy":"2024-06-24T05:45:06.273020Z","iopub.status.idle":"2024-06-24T05:45:06.729433Z","shell.execute_reply":"2024-06-24T05:45:06.728240Z","shell.execute_reply.started":"2024-06-24T05:45:06.273418Z"},"trusted":true},"outputs":[],"source":["pred=model.predict(xtest)\n"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-06-24T05:45:06.731785Z","iopub.status.busy":"2024-06-24T05:45:06.731306Z","iopub.status.idle":"2024-06-24T05:45:06.759408Z","shell.execute_reply":"2024-06-24T05:45:06.758377Z","shell.execute_reply.started":"2024-06-24T05:45:06.731725Z"},"trusted":true},"outputs":[],"source":["rmse=np.sqrt(mean_squared_error(ytest,pred))\n","r2=r2_score(ytest,pred)\n","\n","print(\"TEsting Performance\")\n","\n","print(\"RMSE: {:.2f}\".format(rmse))\n","print(\"R2{:.2f}\".format(r2))"]},{"cell_type":"markdown","metadata":{},"source":["# Rmse is 0.08 which says that our model prediction is only 8 % wrong whhich is good\n","# R2 is 0.93 very much close to 1 \n","# Model performance is good and it is not overfitting"]},{"cell_type":"markdown","metadata":{},"source":["
"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":[]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":2634885,"sourceId":4508299,"sourceType":"datasetVersion"}],"dockerImageVersionId":30558,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.12.1"}},"nbformat":4,"nbformat_minor":4}