{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-10-15T11:45:11.932006Z","iopub.execute_input":"2022-10-15T11:45:11.932538Z","iopub.status.idle":"2022-10-15T11:45:12.994196Z","shell.execute_reply.started":"2022-10-15T11:45:11.932423Z","shell.execute_reply":"2022-10-15T11:45:12.993090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Lets Talk about Games dataset and understand what actually it wanna to say.","metadata":{}},{"cell_type":"code","source":"games = pd.read_csv('../input/nfl-big-data-bowl-2023/games.csv')\ngames.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:12.996591Z","iopub.execute_input":"2022-10-15T11:45:12.997079Z","iopub.status.idle":"2022-10-15T11:45:13.038076Z","shell.execute_reply.started":"2022-10-15T11:45:12.997025Z","shell.execute_reply":"2022-10-15T11:45:13.037011Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Description of Game Data** : Primary Key is *gameId*\n\n* **gameId**: Game identifier, unique (numeric)\n\n* **gameDate**: Game Date (time, mm/dd/yyyy)\n\n* **gameTimeEastern**: Start time of game (time, HH:MM:SS, EST)\n\n* **homeTeamAbbr**: Home team three-letter code (text)\n\n* **visitorTeamAbbr**: Visiting team three-letter code (text)\n\n* **week**: Week of game (numeric)","metadata":{}},{"cell_type":"code","source":"games.rename(columns={'gameId': 'game_id', \n                     'homeTeamAbbr':'Home_team_sign',\n                     'visitorTeamAbbr':'Away_team_sign'\n                    }, inplace=True)\ngames.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:13.039331Z","iopub.execute_input":"2022-10-15T11:45:13.039618Z","iopub.status.idle":"2022-10-15T11:45:13.060748Z","shell.execute_reply.started":"2022-10-15T11:45:13.039580Z","shell.execute_reply":"2022-10-15T11:45:13.059877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games.tail(5)","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:13.063099Z","iopub.execute_input":"2022-10-15T11:45:13.063597Z","iopub.status.idle":"2022-10-15T11:45:13.078923Z","shell.execute_reply.started":"2022-10-15T11:45:13.063560Z","shell.execute_reply":"2022-10-15T11:45:13.077796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games.info()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:13.080436Z","iopub.execute_input":"2022-10-15T11:45:13.080714Z","iopub.status.idle":"2022-10-15T11:45:13.111031Z","shell.execute_reply.started":"2022-10-15T11:45:13.080686Z","shell.execute_reply":"2022-10-15T11:45:13.109700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games.describe","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:13.112451Z","iopub.execute_input":"2022-10-15T11:45:13.112794Z","iopub.status.idle":"2022-10-15T11:45:13.132406Z","shell.execute_reply.started":"2022-10-15T11:45:13.112748Z","shell.execute_reply":"2022-10-15T11:45:13.131480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Familiar with feature of Games dataframe.","metadata":{}},{"cell_type":"code","source":"games.shape","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:13.134031Z","iopub.execute_input":"2022-10-15T11:45:13.134338Z","iopub.status.idle":"2022-10-15T11:45:13.148572Z","shell.execute_reply.started":"2022-10-15T11:45:13.134298Z","shell.execute_reply":"2022-10-15T11:45:13.147754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games.corr()   #check_corelation","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:13.149771Z","iopub.execute_input":"2022-10-15T11:45:13.150427Z","iopub.status.idle":"2022-10-15T11:45:13.172090Z","shell.execute_reply.started":"2022-10-15T11:45:13.150391Z","shell.execute_reply":"2022-10-15T11:45:13.170937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def Familiar_with_feature(data):\n    df=pd.DataFrame(data.dtypes, columns=['Data Type'])\n    df = df.reset_index()\n    df= df.rename(columns={'index ': 'features'})\n    df['Total Null'] = data.isnull().sum().values\n    df['Unique Values'] =data.nunique().values\n    df['First Value'] = data.iloc[0].values\n    df['Lasrt Values'] = data.iloc[len(data)-1].values\n    return df\n\nFamiliar_with_feature(games)","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:13.174052Z","iopub.execute_input":"2022-10-15T11:45:13.175795Z","iopub.status.idle":"2022-10-15T11:45:13.214915Z","shell.execute_reply.started":"2022-10-15T11:45:13.175704Z","shell.execute_reply":"2022-10-15T11:45:13.213654Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"It consists of 272 games, with each of the NFL's 32 teams playing 17 games during an 18-week period with one \"bye\" week off. Since 2012, the NFL generally schedules games in five time slots during the week","metadata":{}},{"cell_type":"code","source":"# colors = ['gold','lightskyblue', 'green']\n# games['season'].value_counts().plot.pie(figsize=(10,14),colors=colors,shadow=True,explode=(0.2,0.1,0.2),autopct=\"%1.1f%%\")\n# plt.title('Number of game playing for each season',fontsize=15)\n# plt.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-10-15T11:45:13.218104Z","iopub.execute_input":"2022-10-15T11:45:13.218957Z","iopub.status.idle":"2022-10-15T11:45:13.226165Z","shell.execute_reply.started":"2022-10-15T11:45:13.218906Z","shell.execute_reply":"2022-10-15T11:45:13.225225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Basically, game start September and end on Januay, so in october less game help and particularly in december maximum game happend.","metadata":{}},{"cell_type":"code","source":"import plotly.express as px\ncheck = games['gameDate'].value_counts().reset_index()\n\ncheck.columns = [\n    'date', \n    'games'\n]\n\ncheck = check.sort_values('games')\n\nfig = px.bar(\n    check, \n    y='date', \n    x=\"games\", \n    orientation='h', \n    color='date',\n    title='Number of games for every date', \n    height=900, \n    width=800\n)\nfig.show()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-10-15T11:45:13.227473Z","iopub.execute_input":"2022-10-15T11:45:13.228122Z","iopub.status.idle":"2022-10-15T11:45:16.306020Z","shell.execute_reply.started":"2022-10-15T11:45:13.228073Z","shell.execute_reply":"2022-10-15T11:45:16.304903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\ncheck = games['week'].value_counts().reset_index()\n\ncheck.columns = [\n    'date', \n    'games'\n]\n\ncheck = check.sort_values('games')\n\nfig = px.bar(\n    check, \n    y='date', \n    x=\"games\", \n    orientation='h', \n    color='date',\n    text='games',\n    title='Number of games for per week', \n    height=900, \n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:16.307321Z","iopub.execute_input":"2022-10-15T11:45:16.307574Z","iopub.status.idle":"2022-10-15T11:45:16.407613Z","shell.execute_reply.started":"2022-10-15T11:45:16.307545Z","shell.execute_reply":"2022-10-15T11:45:16.406660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\ncheck = games['Home_team_sign'].value_counts().reset_index()\n\ncheck.columns = [\n    'date', \n    'games'\n]\n\ncheck = check.sort_values('games')\n\nfig = px.bar(\n    check, \n    y='date', \n    x=\"games\", \n    orientation='h', \n    color='date',\n    title='Number of home games', \n    text='games',\n    height=900, \n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:16.409024Z","iopub.execute_input":"2022-10-15T11:45:16.409919Z","iopub.status.idle":"2022-10-15T11:45:16.624811Z","shell.execute_reply.started":"2022-10-15T11:45:16.409876Z","shell.execute_reply":"2022-10-15T11:45:16.623837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\ncheck = games['Away_team_sign'].value_counts().reset_index()\n\ncheck.columns = [\n    'date', \n    'games'\n]\n\ncheck = check.sort_values('games')\n\nfig = px.bar(\n    check, \n    y='date', \n    x=\"games\", \n    orientation='h', \n    color='date',\n    title='Number of away games', \n    height=900, \n    width=800\n)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:16.626518Z","iopub.execute_input":"2022-10-15T11:45:16.627115Z","iopub.status.idle":"2022-10-15T11:45:16.833558Z","shell.execute_reply.started":"2022-10-15T11:45:16.627062Z","shell.execute_reply":"2022-10-15T11:45:16.832692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.line(check, x=\"games\", y=\"date\", \n              title=\"Game played increasing over the time\", \n              color_discrete_sequence=['#F61067'],\n              height=500\n             )\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:16.834950Z","iopub.execute_input":"2022-10-15T11:45:16.836014Z","iopub.status.idle":"2022-10-15T11:45:16.932776Z","shell.execute_reply.started":"2022-10-15T11:45:16.835976Z","shell.execute_reply":"2022-10-15T11:45:16.931653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Two (string or numeric) columns can be combined into one column. For example card1 and card2 can become a new column with","metadata":{}},{"cell_type":"code","source":"# df['uid'] = df[‘card1’].astype(str)+’_’+df[‘card2’].astype(str)","metadata":{"execution":{"iopub.status.busy":"2022-10-15T11:45:16.934238Z","iopub.execute_input":"2022-10-15T11:45:16.934481Z","iopub.status.idle":"2022-10-15T11:45:16.940194Z","shell.execute_reply.started":"2022-10-15T11:45:16.934453Z","shell.execute_reply":"2022-10-15T11:45:16.938160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This helps LGBM because by themselves card1 and card2 may not correlate with target and therefore LGBM won’t split them at a tree node. But the interaction uid = card1_card2 may correlate with target and now LGBM will split it. Numeric columns can combined with adding, subtracting, multiplying, et","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}