Sahitya77/IPLWinPredictor
0
1{2 "nbformat": 4,3 "nbformat_minor": 0,4 "metadata": {5 "colab": {6 "provenance": []7 },8 "kernelspec": {9 "name": "python3",10 "display_name": "Python 3"11 },12 "language_info": {13 "name": "python"14 }15 },16 "cells": [17 {18 "cell_type": "code",19 "execution_count": 29,20 "metadata": {21 "id": "fNQEcD01-COc"22 },23 "outputs": [],24 "source": [25 "import numpy as np\n",26 "import pandas as pd\n",27 "from google.colab import drive"28 ]29 },30 {31 "cell_type": "code",32 "source": [33 "import numpy; print(\"NumPy\", numpy.__version__)\n",34 "import scipy; print(\"SciPy\", scipy.__version__)\n",35 "import sklearn; print(\"Scikit-Learn\", sklearn.__version__)"36 ],37 "metadata": {38 "colab": {39 "base_uri": "https://localhost:8080/"40 },41 "id": "eGuCWj7ucHo0",42 "outputId": "24ce6394-b3cc-40b7-9a4d-91630b87a870"43 },44 "execution_count": 2,45 "outputs": [46 {47 "output_type": "stream",48 "name": "stdout",49 "text": [50 "NumPy 1.21.6\n",51 "SciPy 1.7.3\n",52 "Scikit-Learn 1.0.2\n"53 ]54 }55 ]56 },57 {58 "cell_type": "code",59 "source": [60 "drive.mount('/content/MyDrive',force_remount=True)"61 ],62 "metadata": {63 "colab": {64 "base_uri": "https://localhost:8080/"65 },66 "id": "Q-9ahH5r-ImU",67 "outputId": "b81f7f39-b298-4df7-8e66-4b26856333b0"68 },69 "execution_count": 30,70 "outputs": [71 {72 "output_type": "stream",73 "name": "stdout",74 "text": [75 "Mounted at /content/MyDrive\n"76 ]77 }78 ]79 },80 {81 "cell_type": "code",82 "source": [83 "match=pd.read_csv('/content/MyDrive/MyDrive/IPLDataset/matches.csv')\n",84 "delivery=pd.read_csv('/content/MyDrive/MyDrive/IPLDataset/deliveries.csv')"85 ],86 "metadata": {87 "id": "-7f2Rw4w-aBg"88 },89 "execution_count": 31,90 "outputs": []91 },92 {93 "cell_type": "code",94 "source": [95 "match.shape"96 ],97 "metadata": {98 "colab": {99 "base_uri": "https://localhost:8080/"100 },101 "id": "VH8DbC1Y-7Id",102 "outputId": "22ae8ae9-6990-4904-f96e-c59f86bddf10"103 },104 "execution_count": 32,105 "outputs": [106 {107 "output_type": "execute_result",108 "data": {109 "text/plain": [110 "(756, 18)"111 ]112 },113 "metadata": {},114 "execution_count": 32115 }116 ]117 },118 {119 "cell_type": "code",120 "source": [121 "match.head()"122 ],123 "metadata": {124 "colab": {125 "base_uri": "https://localhost:8080/",126 "height": 496127 },128 "id": "9CwjVYNN_k8v",129 "outputId": "6a560a4c-3d30-499a-a0bf-8ef45f91f4d3"130 },131 "execution_count": 33,132 "outputs": [133 {134 "output_type": "execute_result",135 "data": {136 "text/plain": [137 " id Season city date team1 \\\n",138 "0 1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n",139 "1 2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n",140 "2 3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n",141 "3 4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n",142 "4 5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n",143 "\n",144 " team2 toss_winner toss_decision \\\n",145 "0 Royal Challengers Bangalore Royal Challengers Bangalore field \n",146 "1 Rising Pune Supergiant Rising Pune Supergiant field \n",147 "2 Kolkata Knight Riders Kolkata Knight Riders field \n",148 "3 Kings XI Punjab Kings XI Punjab field \n",149 "4 Delhi Daredevils Royal Challengers Bangalore bat \n",150 "\n",151 " result dl_applied winner win_by_runs \\\n",152 "0 normal 0 Sunrisers Hyderabad 35 \n",153 "1 normal 0 Rising Pune Supergiant 0 \n",154 "2 normal 0 Kolkata Knight Riders 0 \n",155 "3 normal 0 Kings XI Punjab 0 \n",156 "4 normal 0 Royal Challengers Bangalore 15 \n",157 "\n",158 " win_by_wickets player_of_match venue \\\n",159 "0 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n",160 "1 7 SPD Smith Maharashtra Cricket Association Stadium \n",161 "2 10 CA Lynn Saurashtra Cricket Association Stadium \n",162 "3 6 GJ Maxwell Holkar Cricket Stadium \n",163 "4 0 KM Jadhav M Chinnaswamy Stadium \n",164 "\n",165 " umpire1 umpire2 umpire3 \n",166 "0 AY Dandekar NJ Llong NaN \n",167 "1 A Nand Kishore S Ravi NaN \n",168 "2 Nitin Menon CK Nandan NaN \n",169 "3 AK Chaudhary C Shamshuddin NaN \n",170 "4 NaN NaN NaN "171 ],172 "text/html": [173 "\n",174 " <div id=\"df-e68083bf-2bf2-4252-bd1f-e325f170ef32\">\n",175 " <div class=\"colab-df-container\">\n",176 " <div>\n",177 "<style scoped>\n",178 " .dataframe tbody tr th:only-of-type {\n",179 " vertical-align: middle;\n",180 " }\n",181 "\n",182 " .dataframe tbody tr th {\n",183 " vertical-align: top;\n",184 " }\n",185 "\n",186 " .dataframe thead th {\n",187 " text-align: right;\n",188 " }\n",189 "</style>\n",190 "<table border=\"1\" class=\"dataframe\">\n",191 " <thead>\n",192 " <tr style=\"text-align: right;\">\n",193 " <th></th>\n",194 " <th>id</th>\n",195 " <th>Season</th>\n",196 " <th>city</th>\n",197 " <th>date</th>\n",198 " <th>team1</th>\n",199 " <th>team2</th>\n",200 " <th>toss_winner</th>\n",201 " <th>toss_decision</th>\n",202 " <th>result</th>\n",203 " <th>dl_applied</th>\n",204 " <th>winner</th>\n",205 " <th>win_by_runs</th>\n",206 " <th>win_by_wickets</th>\n",207 " <th>player_of_match</th>\n",208 " <th>venue</th>\n",209 " <th>umpire1</th>\n",210 " <th>umpire2</th>\n",211 " <th>umpire3</th>\n",212 " </tr>\n",213 " </thead>\n",214 " <tbody>\n",215 " <tr>\n",216 " <th>0</th>\n",217 " <td>1</td>\n",218 " <td>IPL-2017</td>\n",219 " <td>Hyderabad</td>\n",220 " <td>05-04-2017</td>\n",221 " <td>Sunrisers Hyderabad</td>\n",222 " <td>Royal Challengers Bangalore</td>\n",223 " <td>Royal Challengers Bangalore</td>\n",224 " <td>field</td>\n",225 " <td>normal</td>\n",226 " <td>0</td>\n",227 " <td>Sunrisers Hyderabad</td>\n",228 " <td>35</td>\n",229 " <td>0</td>\n",230 " <td>Yuvraj Singh</td>\n",231 " <td>Rajiv Gandhi International Stadium, Uppal</td>\n",232 " <td>AY Dandekar</td>\n",233 " <td>NJ Llong</td>\n",234 " <td>NaN</td>\n",235 " </tr>\n",236 " <tr>\n",237 " <th>1</th>\n",238 " <td>2</td>\n",239 " <td>IPL-2017</td>\n",240 " <td>Pune</td>\n",241 " <td>06-04-2017</td>\n",242 " <td>Mumbai Indians</td>\n",243 " <td>Rising Pune Supergiant</td>\n",244 " <td>Rising Pune Supergiant</td>\n",245 " <td>field</td>\n",246 " <td>normal</td>\n",247 " <td>0</td>\n",248 " <td>Rising Pune Supergiant</td>\n",249 " <td>0</td>\n",250 " <td>7</td>\n",251 " <td>SPD Smith</td>\n",252 " <td>Maharashtra Cricket Association Stadium</td>\n",253 " <td>A Nand Kishore</td>\n",254 " <td>S Ravi</td>\n",255 " <td>NaN</td>\n",256 " </tr>\n",257 " <tr>\n",258 " <th>2</th>\n",259 " <td>3</td>\n",260 " <td>IPL-2017</td>\n",261 " <td>Rajkot</td>\n",262 " <td>07-04-2017</td>\n",263 " <td>Gujarat Lions</td>\n",264 " <td>Kolkata Knight Riders</td>\n",265 " <td>Kolkata Knight Riders</td>\n",266 " <td>field</td>\n",267 " <td>normal</td>\n",268 " <td>0</td>\n",269 " <td>Kolkata Knight Riders</td>\n",270 " <td>0</td>\n",271 " <td>10</td>\n",272 " <td>CA Lynn</td>\n",273 " <td>Saurashtra Cricket Association Stadium</td>\n",274 " <td>Nitin Menon</td>\n",275 " <td>CK Nandan</td>\n",276 " <td>NaN</td>\n",277 " </tr>\n",278 " <tr>\n",279 " <th>3</th>\n",280 " <td>4</td>\n",281 " <td>IPL-2017</td>\n",282 " <td>Indore</td>\n",283 " <td>08-04-2017</td>\n",284 " <td>Rising Pune Supergiant</td>\n",285 " <td>Kings XI Punjab</td>\n",286 " <td>Kings XI Punjab</td>\n",287 " <td>field</td>\n",288 " <td>normal</td>\n",289 " <td>0</td>\n",290 " <td>Kings XI Punjab</td>\n",291 " <td>0</td>\n",292 " <td>6</td>\n",293 " <td>GJ Maxwell</td>\n",294 " <td>Holkar Cricket Stadium</td>\n",295 " <td>AK Chaudhary</td>\n",296 " <td>C Shamshuddin</td>\n",297 " <td>NaN</td>\n",298 " </tr>\n",299 " <tr>\n",300 " <th>4</th>\n",301 " <td>5</td>\n",302 " <td>IPL-2017</td>\n",303 " <td>Bangalore</td>\n",304 " <td>08-04-2017</td>\n",305 " <td>Royal Challengers Bangalore</td>\n",306 " <td>Delhi Daredevils</td>\n",307 " <td>Royal Challengers Bangalore</td>\n",308 " <td>bat</td>\n",309 " <td>normal</td>\n",310 " <td>0</td>\n",311 " <td>Royal Challengers Bangalore</td>\n",312 " <td>15</td>\n",313 " <td>0</td>\n",314 " <td>KM Jadhav</td>\n",315 " <td>M Chinnaswamy Stadium</td>\n",316 " <td>NaN</td>\n",317 " <td>NaN</td>\n",318 " <td>NaN</td>\n",319 " </tr>\n",320 " </tbody>\n",321 "</table>\n",322 "</div>\n",323 " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-e68083bf-2bf2-4252-bd1f-e325f170ef32')\"\n",324 " title=\"Convert this dataframe to an interactive table.\"\n",325 " style=\"display:none;\">\n",326 " \n",327 " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",328 " width=\"24px\">\n",329 " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",330 " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",331 " </svg>\n",332 " </button>\n",333 " \n",334 " <style>\n",335 " .colab-df-container {\n",336 " display:flex;\n",337 " flex-wrap:wrap;\n",338 " gap: 12px;\n",339 " }\n",340 "\n",341 " .colab-df-convert {\n",342 " background-color: #E8F0FE;\n",343 " border: none;\n",344 " border-radius: 50%;\n",345 " cursor: pointer;\n",346 " display: none;\n",347 " fill: #1967D2;\n",348 " height: 32px;\n",349 " padding: 0 0 0 0;\n",350 " width: 32px;\n",351 " }\n",352 "\n",353 " .colab-df-convert:hover {\n",354 " background-color: #E2EBFA;\n",355 " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",356 " fill: #174EA6;\n",357 " }\n",358 "\n",359 " [theme=dark] .colab-df-convert {\n",360 " background-color: #3B4455;\n",361 " fill: #D2E3FC;\n",362 " }\n",363 "\n",364 " [theme=dark] .colab-df-convert:hover {\n",365 " background-color: #434B5C;\n",366 " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",367 " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",368 " fill: #FFFFFF;\n",369 " }\n",370 " </style>\n",371 "\n",372 " <script>\n",373 " const buttonEl =\n",374 " document.querySelector('#df-e68083bf-2bf2-4252-bd1f-e325f170ef32 button.colab-df-convert');\n",375 " buttonEl.style.display =\n",376 " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",377 "\n",378 " async function convertToInteractive(key) {\n",379 " const element = document.querySelector('#df-e68083bf-2bf2-4252-bd1f-e325f170ef32');\n",380 " const dataTable =\n",381 " await google.colab.kernel.invokeFunction('convertToInteractive',\n",382 " [key], {});\n",383 " if (!dataTable) return;\n",384 "\n",385 " const docLinkHtml = 'Like what you see? Visit the ' +\n",386 " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",387 " + ' to learn more about interactive tables.';\n",388 " element.innerHTML = '';\n",389 " dataTable['output_type'] = 'display_data';\n",390 " await google.colab.output.renderOutput(dataTable, element);\n",391 " const docLink = document.createElement('div');\n",392 " docLink.innerHTML = docLinkHtml;\n",393 " element.appendChild(docLink);\n",394 " }\n",395 " </script>\n",396 " </div>\n",397 " </div>\n",398 " "399 ]400 },401 "metadata": {},402 "execution_count": 33403 }404 ]405 },406 {407 "cell_type": "code",408 "source": [409 "delivery.shape"410 ],411 "metadata": {412 "colab": {413 "base_uri": "https://localhost:8080/"414 },415 "id": "gx7DKlAp_pts",416 "outputId": "5de1c24e-79b0-4c86-f37c-d13dcec388ee"417 },418 "execution_count": 34,419 "outputs": [420 {421 "output_type": "execute_result",422 "data": {423 "text/plain": [424 "(179078, 21)"425 ]426 },427 "metadata": {},428 "execution_count": 34429 }430 ]431 },432 {433 "cell_type": "code",434 "source": [435 "delivery.head()"436 ],437 "metadata": {438 "colab": {439 "base_uri": "https://localhost:8080/",440 "height": 473441 },442 "id": "H9P2KVtj_mFS",443 "outputId": "5637c47e-e584-4142-e555-22826b3cac99"444 },445 "execution_count": 35,446 "outputs": [447 {448 "output_type": "execute_result",449 "data": {450 "text/plain": [451 " match_id inning batting_team bowling_team over \\\n",452 "0 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 \n",453 "1 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 \n",454 "2 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 \n",455 "3 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 \n",456 "4 1 1 Sunrisers Hyderabad Royal Challengers Bangalore 1 \n",457 "\n",458 " ball batsman non_striker bowler is_super_over ... bye_runs \\\n",459 "0 1 DA Warner S Dhawan TS Mills 0 ... 0 \n",460 "1 2 DA Warner S Dhawan TS Mills 0 ... 0 \n",461 "2 3 DA Warner S Dhawan TS Mills 0 ... 0 \n",462 "3 4 DA Warner S Dhawan TS Mills 0 ... 0 \n",463 "4 5 DA Warner S Dhawan TS Mills 0 ... 0 \n",464 "\n",465 " legbye_runs noball_runs penalty_runs batsman_runs extra_runs \\\n",466 "0 0 0 0 0 0 \n",467 "1 0 0 0 0 0 \n",468 "2 0 0 0 4 0 \n",469 "3 0 0 0 0 0 \n",470 "4 0 0 0 0 2 \n",471 "\n",472 " total_runs player_dismissed dismissal_kind fielder \n",473 "0 0 NaN NaN NaN \n",474 "1 0 NaN NaN NaN \n",475 "2 4 NaN NaN NaN \n",476 "3 0 NaN NaN NaN \n",477 "4 2 NaN NaN NaN \n",478 "\n",479 "[5 rows x 21 columns]"480 ],481 "text/html": [482 "\n",483 " <div id=\"df-d287ac09-c86c-4dd7-b871-fc044f186c90\">\n",484 " <div class=\"colab-df-container\">\n",485 " <div>\n",486 "<style scoped>\n",487 " .dataframe tbody tr th:only-of-type {\n",488 " vertical-align: middle;\n",489 " }\n",490 "\n",491 " .dataframe tbody tr th {\n",492 " vertical-align: top;\n",493 " }\n",494 "\n",495 " .dataframe thead th {\n",496 " text-align: right;\n",497 " }\n",498 "</style>\n",499 "<table border=\"1\" class=\"dataframe\">\n",500 " <thead>\n",501 " <tr style=\"text-align: right;\">\n",502 " <th></th>\n",503 " <th>match_id</th>\n",504 " <th>inning</th>\n",505 " <th>batting_team</th>\n",506 " <th>bowling_team</th>\n",507 " <th>over</th>\n",508 " <th>ball</th>\n",509 " <th>batsman</th>\n",510 " <th>non_striker</th>\n",511 " <th>bowler</th>\n",512 " <th>is_super_over</th>\n",513 " <th>...</th>\n",514 " <th>bye_runs</th>\n",515 " <th>legbye_runs</th>\n",516 " <th>noball_runs</th>\n",517 " <th>penalty_runs</th>\n",518 " <th>batsman_runs</th>\n",519 " <th>extra_runs</th>\n",520 " <th>total_runs</th>\n",521 " <th>player_dismissed</th>\n",522 " <th>dismissal_kind</th>\n",523 " <th>fielder</th>\n",524 " </tr>\n",525 " </thead>\n",526 " <tbody>\n",527 " <tr>\n",528 " <th>0</th>\n",529 " <td>1</td>\n",530 " <td>1</td>\n",531 " <td>Sunrisers Hyderabad</td>\n",532 " <td>Royal Challengers Bangalore</td>\n",533 " <td>1</td>\n",534 " <td>1</td>\n",535 " <td>DA Warner</td>\n",536 " <td>S Dhawan</td>\n",537 " <td>TS Mills</td>\n",538 " <td>0</td>\n",539 " <td>...</td>\n",540 " <td>0</td>\n",541 " <td>0</td>\n",542 " <td>0</td>\n",543 " <td>0</td>\n",544 " <td>0</td>\n",545 " <td>0</td>\n",546 " <td>0</td>\n",547 " <td>NaN</td>\n",548 " <td>NaN</td>\n",549 " <td>NaN</td>\n",550 " </tr>\n",551 " <tr>\n",552 " <th>1</th>\n",553 " <td>1</td>\n",554 " <td>1</td>\n",555 " <td>Sunrisers Hyderabad</td>\n",556 " <td>Royal Challengers Bangalore</td>\n",557 " <td>1</td>\n",558 " <td>2</td>\n",559 " <td>DA Warner</td>\n",560 " <td>S Dhawan</td>\n",561 " <td>TS Mills</td>\n",562 " <td>0</td>\n",563 " <td>...</td>\n",564 " <td>0</td>\n",565 " <td>0</td>\n",566 " <td>0</td>\n",567 " <td>0</td>\n",568 " <td>0</td>\n",569 " <td>0</td>\n",570 " <td>0</td>\n",571 " <td>NaN</td>\n",572 " <td>NaN</td>\n",573 " <td>NaN</td>\n",574 " </tr>\n",575 " <tr>\n",576 " <th>2</th>\n",577 " <td>1</td>\n",578 " <td>1</td>\n",579 " <td>Sunrisers Hyderabad</td>\n",580 " <td>Royal Challengers Bangalore</td>\n",581 " <td>1</td>\n",582 " <td>3</td>\n",583 " <td>DA Warner</td>\n",584 " <td>S Dhawan</td>\n",585 " <td>TS Mills</td>\n",586 " <td>0</td>\n",587 " <td>...</td>\n",588 " <td>0</td>\n",589 " <td>0</td>\n",590 " <td>0</td>\n",591 " <td>0</td>\n",592 " <td>4</td>\n",593 " <td>0</td>\n",594 " <td>4</td>\n",595 " <td>NaN</td>\n",596 " <td>NaN</td>\n",597 " <td>NaN</td>\n",598 " </tr>\n",599 " <tr>\n",600 " <th>3</th>\n",601 " <td>1</td>\n",602 " <td>1</td>\n",603 " <td>Sunrisers Hyderabad</td>\n",604 " <td>Royal Challengers Bangalore</td>\n",605 " <td>1</td>\n",606 " <td>4</td>\n",607 " <td>DA Warner</td>\n",608 " <td>S Dhawan</td>\n",609 " <td>TS Mills</td>\n",610 " <td>0</td>\n",611 " <td>...</td>\n",612 " <td>0</td>\n",613 " <td>0</td>\n",614 " <td>0</td>\n",615 " <td>0</td>\n",616 " <td>0</td>\n",617 " <td>0</td>\n",618 " <td>0</td>\n",619 " <td>NaN</td>\n",620 " <td>NaN</td>\n",621 " <td>NaN</td>\n",622 " </tr>\n",623 " <tr>\n",624 " <th>4</th>\n",625 " <td>1</td>\n",626 " <td>1</td>\n",627 " <td>Sunrisers Hyderabad</td>\n",628 " <td>Royal Challengers Bangalore</td>\n",629 " <td>1</td>\n",630 " <td>5</td>\n",631 " <td>DA Warner</td>\n",632 " <td>S Dhawan</td>\n",633 " <td>TS Mills</td>\n",634 " <td>0</td>\n",635 " <td>...</td>\n",636 " <td>0</td>\n",637 " <td>0</td>\n",638 " <td>0</td>\n",639 " <td>0</td>\n",640 " <td>0</td>\n",641 " <td>2</td>\n",642 " <td>2</td>\n",643 " <td>NaN</td>\n",644 " <td>NaN</td>\n",645 " <td>NaN</td>\n",646 " </tr>\n",647 " </tbody>\n",648 "</table>\n",649 "<p>5 rows × 21 columns</p>\n",650 "</div>\n",651 " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-d287ac09-c86c-4dd7-b871-fc044f186c90')\"\n",652 " title=\"Convert this dataframe to an interactive table.\"\n",653 " style=\"display:none;\">\n",654 " \n",655 " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",656 " width=\"24px\">\n",657 " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",658 " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",659 " </svg>\n",660 " </button>\n",661 " \n",662 " <style>\n",663 " .colab-df-container {\n",664 " display:flex;\n",665 " flex-wrap:wrap;\n",666 " gap: 12px;\n",667 " }\n",668 "\n",669 " .colab-df-convert {\n",670 " background-color: #E8F0FE;\n",671 " border: none;\n",672 " border-radius: 50%;\n",673 " cursor: pointer;\n",674 " display: none;\n",675 " fill: #1967D2;\n",676 " height: 32px;\n",677 " padding: 0 0 0 0;\n",678 " width: 32px;\n",679 " }\n",680 "\n",681 " .colab-df-convert:hover {\n",682 " background-color: #E2EBFA;\n",683 " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",684 " fill: #174EA6;\n",685 " }\n",686 "\n",687 " [theme=dark] .colab-df-convert {\n",688 " background-color: #3B4455;\n",689 " fill: #D2E3FC;\n",690 " }\n",691 "\n",692 " [theme=dark] .colab-df-convert:hover {\n",693 " background-color: #434B5C;\n",694 " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",695 " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",696 " fill: #FFFFFF;\n",697 " }\n",698 " </style>\n",699 "\n",700 " <script>\n",701 " const buttonEl =\n",702 " document.querySelector('#df-d287ac09-c86c-4dd7-b871-fc044f186c90 button.colab-df-convert');\n",703 " buttonEl.style.display =\n",704 " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",705 "\n",706 " async function convertToInteractive(key) {\n",707 " const element = document.querySelector('#df-d287ac09-c86c-4dd7-b871-fc044f186c90');\n",708 " const dataTable =\n",709 " await google.colab.kernel.invokeFunction('convertToInteractive',\n",710 " [key], {});\n",711 " if (!dataTable) return;\n",712 "\n",713 " const docLinkHtml = 'Like what you see? Visit the ' +\n",714 " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",715 " + ' to learn more about interactive tables.';\n",716 " element.innerHTML = '';\n",717 " dataTable['output_type'] = 'display_data';\n",718 " await google.colab.output.renderOutput(dataTable, element);\n",719 " const docLink = document.createElement('div');\n",720 " docLink.innerHTML = docLinkHtml;\n",721 " element.appendChild(docLink);\n",722 " }\n",723 " </script>\n",724 " </div>\n",725 " </div>\n",726 " "727 ]728 },729 "metadata": {},730 "execution_count": 35731 }732 ]733 },734 {735 "cell_type": "code",736 "source": [737 "total_score_df=delivery.groupby(['match_id','inning']).sum()['total_runs'].reset_index()"738 ],739 "metadata": {740 "id": "YX4u0npV_t3O"741 },742 "execution_count": 36,743 "outputs": []744 },745 {746 "cell_type": "code",747 "source": [748 "total_score_df=total_score_df[total_score_df['inning']==1]"749 ],750 "metadata": {751 "id": "rZGLNlIyAYIW"752 },753 "execution_count": 37,754 "outputs": []755 },756 {757 "cell_type": "code",758 "source": [759 "match_df=match.merge(total_score_df[['match_id','total_runs']],left_on='id',right_on='match_id')"760 ],761 "metadata": {762 "id": "da3fK7jYAupu"763 },764 "execution_count": 38,765 "outputs": []766 },767 {768 "cell_type": "code",769 "source": [770 "match_df['team1'].unique()"771 ],772 "metadata": {773 "colab": {774 "base_uri": "https://localhost:8080/"775 },776 "id": "vvVxwWR_BL7W",777 "outputId": "52152b25-ce02-4708-b597-6a58054aaa63"778 },779 "execution_count": 39,780 "outputs": [781 {782 "output_type": "execute_result",783 "data": {784 "text/plain": [785 "array(['Sunrisers Hyderabad', 'Mumbai Indians', 'Gujarat Lions',\n",786 " 'Rising Pune Supergiant', 'Royal Challengers Bangalore',\n",787 " 'Kolkata Knight Riders', 'Delhi Daredevils', 'Kings XI Punjab',\n",788 " 'Chennai Super Kings', 'Rajasthan Royals', 'Deccan Chargers',\n",789 " 'Kochi Tuskers Kerala', 'Pune Warriors', 'Rising Pune Supergiants',\n",790 " 'Delhi Capitals'], dtype=object)"791 ]792 },793 "metadata": {},794 "execution_count": 39795 }796 ]797 },798 {799 "cell_type": "code",800 "source": [801 "teams = [\n",802 " 'Sunrisers Hyderabad',\n",803 " 'Mumbai Indians',\n",804 " 'Royal Challengers Bangalore',\n",805 " 'Kolkata Knight Riders',\n",806 " 'Kings XI Punjab',\n",807 " 'Chennai Super Kings',\n",808 " 'Rajasthan Royals',\n",809 " 'Delhi Capitals'\n",810 "]"811 ],812 "metadata": {813 "id": "KeE4TTjBBRzE"814 },815 "execution_count": 40,816 "outputs": []817 },818 {819 "cell_type": "code",820 "source": [821 "match_df['team1'] = match_df['team1'].str.replace('Delhi Daredevils','Delhi Capitals')\n",822 "match_df['team2'] = match_df['team2'].str.replace('Delhi Daredevils','Delhi Capitals')\n",823 "\n",824 "match_df['team1'] = match_df['team1'].str.replace('Deccan Chargers','Sunrisers Hyderabad')\n",825 "match_df['team2'] = match_df['team2'].str.replace('Deccan Chargers','Sunrisers Hyderabad')"826 ],827 "metadata": {828 "id": "HiwfbPdxB5qe"829 },830 "execution_count": 41,831 "outputs": []832 },833 {834 "cell_type": "code",835 "source": [836 "match_df = match_df[match_df['team1'].isin(teams)]\n",837 "match_df = match_df[match_df['team2'].isin(teams)]"838 ],839 "metadata": {840 "id": "wl9bWaQEB67e"841 },842 "execution_count": 42,843 "outputs": []844 },845 {846 "cell_type": "code",847 "source": [848 "match_df.shape"849 ],850 "metadata": {851 "colab": {852 "base_uri": "https://localhost:8080/"853 },854 "id": "9ZTX_L3hB9X3",855 "outputId": "fe97ab3d-d917-48b5-9c95-c714bfff15c7"856 },857 "execution_count": 43,858 "outputs": [859 {860 "output_type": "execute_result",861 "data": {862 "text/plain": [863 "(641, 20)"864 ]865 },866 "metadata": {},867 "execution_count": 43868 }869 ]870 },871 {872 "cell_type": "code",873 "source": [874 "match_df=match_df[match_df['dl_applied']==0]"875 ],876 "metadata": {877 "id": "G840rx92B-dO"878 },879 "execution_count": 44,880 "outputs": []881 },882 {883 "cell_type": "code",884 "source": [885 "match_df = match_df[['match_id','city','winner','total_runs']]"886 ],887 "metadata": {888 "id": "osdGWtZCCZQ9"889 },890 "execution_count": 46,891 "outputs": []892 },893 {894 "cell_type": "code",895 "source": [896 "delivery_df=match_df.merge(delivery,on='match_id')"897 ],898 "metadata": {899 "id": "Dn-EcbTTCbD6"900 },901 "execution_count": 48,902 "outputs": []903 },904 {905 "cell_type": "code",906 "source": [907 "delivery_df=delivery_df[delivery_df['inning']==2]"908 ],909 "metadata": {910 "id": "FUxwOB-bCyml"911 },912 "execution_count": 50,913 "outputs": []914 },915 {916 "cell_type": "code",917 "source": [918 "delivery_df['current_score']=delivery_df.groupby('match_id').cumsum()['total_runs_y']"919 ],920 "metadata": {921 "id": "C6tuuE6JC_Ge"922 },923 "execution_count": 52,924 "outputs": []925 },926 {927 "cell_type": "code",928 "source": [929 "delivery_df['runs_left']=delivery_df['total_runs_x']-delivery_df['current_score']"930 ],931 "metadata": {932 "id": "PEbxpPssDbmx"933 },934 "execution_count": 54,935 "outputs": []936 },937 {938 "cell_type": "code",939 "source": [940 "delivery_df['balls_left'] = 126 - (delivery_df['over']*6 + delivery_df['ball'])"941 ],942 "metadata": {943 "id": "ZN7PAJfxDoND"944 },945 "execution_count": 56,946 "outputs": []947 },948 {949 "cell_type": "code",950 "source": [951 "delivery_df['player_dismissed']=delivery_df['player_dismissed'].fillna(\"0\")\n",952 "delivery_df['player_dismissed']=delivery_df['player_dismissed'].apply(lambda x:x if x==\"0\" else \"1\")\n",953 "delivery_df['player_dismissed']=delivery_df['player_dismissed'].astype('int')\n",954 "wickets=delivery_df.groupby('match_id').cumsum()['player_dismissed'].values\n",955 "delivery_df['wickets']=10-wickets\n"956 ],957 "metadata": {958 "id": "Tmn6xx2VEeSI"959 },960 "execution_count": 58,961 "outputs": []962 },963 {964 "cell_type": "code",965 "source": [966 "delivery_df['crr'] = (delivery_df['current_score']*6)/(120 - delivery_df['balls_left'])"967 ],968 "metadata": {969 "id": "xw1E6hfmG2SN"970 },971 "execution_count": 60,972 "outputs": []973 },974 {975 "cell_type": "code",976 "source": [977 "delivery_df['rrr'] = (delivery_df['runs_left']*6)/delivery_df['balls_left']"978 ],979 "metadata": {980 "id": "Eua3yfcuG34P"981 },982 "execution_count": 61,983 "outputs": []984 },985 {986 "cell_type": "code",987 "source": [988 "def result(row):\n",989 " return 1 if row['batting_team'] == row['winner'] else 0"990 ],991 "metadata": {992 "id": "NmGWwEVVHZbT"993 },994 "execution_count": 62,995 "outputs": []996 },997 {998 "cell_type": "code",999 "source": [1000 "delivery_df['result'] = delivery_df.apply(result,axis=1)"1001 ],1002 "metadata": {1003 "id": "rjul4hXWHk3a"1004 },1005 "execution_count": 63,1006 "outputs": []1007 },1008 {1009 "cell_type": "code",1010 "source": [1011 "final_df = delivery_df[['batting_team','bowling_team','city','runs_left','balls_left','wickets','total_runs_x','crr','rrr','result']]"1012 ],1013 "metadata": {1014 "id": "cwCjWuCUHnPj"1015 },1016 "execution_count": 66,1017 "outputs": []1018 },1019 {1020 "cell_type": "code",1021 "source": [1022 "final_df=final_df.sample(final_df.shape[0])"1023 ],1024 "metadata": {1025 "id": "ywcx2XLJHpKE"1026 },1027 "execution_count": 67,1028 "outputs": []1029 },1030 {1031 "cell_type": "code",1032 "source": [1033 "final_df.sample()"1034 ],1035 "metadata": {1036 "colab": {1037 "base_uri": "https://localhost:8080/",1038 "height": 811039 },1040 "id": "fYy4oxNlIvuR",1041 "outputId": "76e56250-10b0-406a-91bf-7ba31cdd8813"1042 },1043 "execution_count": 68,1044 "outputs": [1045 {1046 "output_type": "execute_result",1047 "data": {1048 "text/plain": [1049 " batting_team bowling_team city runs_left balls_left \\\n",1050 "20128 Rajasthan Royals Chennai Super Kings Mumbai 137 98 \n",1051 "\n",1052 " wickets total_runs_x crr rrr result \n",1053 "20128 9 163 7.090909 8.387755 1 "1054 ],1055 "text/html": [1056 "\n",1057 " <div id=\"df-019e3217-71d5-4c56-b8d9-c1b1da0e2182\">\n",1058 " <div class=\"colab-df-container\">\n",1059 " <div>\n",1060 "<style scoped>\n",1061 " .dataframe tbody tr th:only-of-type {\n",1062 " vertical-align: middle;\n",1063 " }\n",1064 "\n",1065 " .dataframe tbody tr th {\n",1066 " vertical-align: top;\n",1067 " }\n",1068 "\n",1069 " .dataframe thead th {\n",1070 " text-align: right;\n",1071 " }\n",1072 "</style>\n",1073 "<table border=\"1\" class=\"dataframe\">\n",1074 " <thead>\n",1075 " <tr style=\"text-align: right;\">\n",1076 " <th></th>\n",1077 " <th>batting_team</th>\n",1078 " <th>bowling_team</th>\n",1079 " <th>city</th>\n",1080 " <th>runs_left</th>\n",1081 " <th>balls_left</th>\n",1082 " <th>wickets</th>\n",1083 " <th>total_runs_x</th>\n",1084 " <th>crr</th>\n",1085 " <th>rrr</th>\n",1086 " <th>result</th>\n",1087 " </tr>\n",1088 " </thead>\n",1089 " <tbody>\n",1090 " <tr>\n",1091 " <th>20128</th>\n",1092 " <td>Rajasthan Royals</td>\n",1093 " <td>Chennai Super Kings</td>\n",1094 " <td>Mumbai</td>\n",1095 " <td>137</td>\n",1096 " <td>98</td>\n",1097 " <td>9</td>\n",1098 " <td>163</td>\n",1099 " <td>7.090909</td>\n",1100 " <td>8.387755</td>\n",1101 " <td>1</td>\n",1102 " </tr>\n",1103 " </tbody>\n",1104 "</table>\n",1105 "</div>\n",1106 " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-019e3217-71d5-4c56-b8d9-c1b1da0e2182')\"\n",1107 " title=\"Convert this dataframe to an interactive table.\"\n",1108 " style=\"display:none;\">\n",1109 " \n",1110 " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",1111 " width=\"24px\">\n",1112 " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",1113 " <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",1114 " </svg>\n",1115 " </button>\n",1116 " \n",1117 " <style>\n",1118 " .colab-df-container {\n",1119 " display:flex;\n",1120 " flex-wrap:wrap;\n",1121 " gap: 12px;\n",1122 " }\n",1123 "\n",1124 " .colab-df-convert {\n",1125 " background-color: #E8F0FE;\n",1126 " border: none;\n",1127 " border-radius: 50%;\n",1128 " cursor: pointer;\n",1129 " display: none;\n",1130 " fill: #1967D2;\n",1131 " height: 32px;\n",1132 " padding: 0 0 0 0;\n",1133 " width: 32px;\n",1134 " }\n",1135 "\n",1136 " .colab-df-convert:hover {\n",1137 " background-color: #E2EBFA;\n",1138 " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",1139 " fill: #174EA6;\n",1140 " }\n",1141 "\n",1142 " [theme=dark] .colab-df-convert {\n",1143 " background-color: #3B4455;\n",1144 " fill: #D2E3FC;\n",1145 " }\n",1146 "\n",1147 " [theme=dark] .colab-df-convert:hover {\n",1148 " background-color: #434B5C;\n",1149 " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",1150 " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",1151 " fill: #FFFFFF;\n",1152 " }\n",1153 " </style>\n",1154 "\n",1155 " <script>\n",1156 " const buttonEl =\n",1157 " document.querySelector('#df-019e3217-71d5-4c56-b8d9-c1b1da0e2182 button.colab-df-convert');\n",1158 " buttonEl.style.display =\n",1159 " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",1160 "\n",1161 " async function convertToInteractive(key) {\n",1162 " const element = document.querySelector('#df-019e3217-71d5-4c56-b8d9-c1b1da0e2182');\n",1163 " const dataTable =\n",1164 " await google.colab.kernel.invokeFunction('convertToInteractive',\n",1165 " [key], {});\n",1166 " if (!dataTable) return;\n",1167 "\n",1168 " const docLinkHtml = 'Like what you see? Visit the ' +\n",1169 " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",1170 " + ' to learn more about interactive tables.';\n",1171 " element.innerHTML = '';\n",1172 " dataTable['output_type'] = 'display_data';\n",1173 " await google.colab.output.renderOutput(dataTable, element);\n",1174 " const docLink = document.createElement('div');\n",1175 " docLink.innerHTML = docLinkHtml;\n",1176 " element.appendChild(docLink);\n",1177 " }\n",1178 " </script>\n",1179 " </div>\n",1180 " </div>\n",1181 " "1182 ]1183 },1184 "metadata": {},1185 "execution_count": 681186 }1187 ]1188 },1189 {1190 "cell_type": "code",1191 "source": [1192 "final_df.dropna(inplace=True)"1193 ],1194 "metadata": {1195 "id": "BQkY9wd3IxE9"1196 },1197 "execution_count": 69,1198 "outputs": []1199 },1200 {