{"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 pandas as pd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:54:47.959240Z","iopub.execute_input":"2022-03-09T14:54:47.960117Z","iopub.status.idle":"2022-03-09T14:54:47.987047Z","shell.execute_reply.started":"2022-03-09T14:54:47.960006Z","shell.execute_reply":"2022-03-09T14:54:47.986222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/football-match-probability-prediction/train.csv\")\ntest_df = pd.read_csv(\"/kaggle/input/football-match-probability-prediction/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:54:50.026299Z","iopub.execute_input":"2022-03-09T14:54:50.026786Z","iopub.status.idle":"2022-03-09T14:55:00.404591Z","shell.execute_reply.started":"2022-03-09T14:54:50.026744Z","shell.execute_reply":"2022-03-09T14:55:00.403930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape, test_df.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.406404Z","iopub.execute_input":"2022-03-09T14:55:00.407082Z","iopub.status.idle":"2022-03-09T14:55:00.415283Z","shell.execute_reply.started":"2022-03-09T14:55:00.407042Z","shell.execute_reply":"2022-03-09T14:55:00.414234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.416443Z","iopub.execute_input":"2022-03-09T14:55:00.416698Z","iopub.status.idle":"2022-03-09T14:55:00.520197Z","shell.execute_reply.started":"2022-03-09T14:55:00.416670Z","shell.execute_reply":"2022-03-09T14:55:00.519297Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_count = train_df['target'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.522918Z","iopub.execute_input":"2022-03-09T14:55:00.523667Z","iopub.status.idle":"2022-03-09T14:55:00.551451Z","shell.execute_reply.started":"2022-03-09T14:55:00.523606Z","shell.execute_reply":"2022-03-09T14:55:00.550586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_count.plot.bar()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.552730Z","iopub.execute_input":"2022-03-09T14:55:00.553157Z","iopub.status.idle":"2022-03-09T14:55:00.777343Z","shell.execute_reply.started":"2022-03-09T14:55:00.553066Z","shell.execute_reply":"2022-03-09T14:55:00.776555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['home_team_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.778713Z","iopub.execute_input":"2022-03-09T14:55:00.778939Z","iopub.status.idle":"2022-03-09T14:55:00.816813Z","shell.execute_reply.started":"2022-03-09T14:55:00.778910Z","shell.execute_reply":"2022-03-09T14:55:00.815922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['away_team_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.817909Z","iopub.execute_input":"2022-03-09T14:55:00.818122Z","iopub.status.idle":"2022-03-09T14:55:00.857285Z","shell.execute_reply.started":"2022-03-09T14:55:00.818096Z","shell.execute_reply":"2022-03-09T14:55:00.856483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['league_name'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.858377Z","iopub.execute_input":"2022-03-09T14:55:00.858900Z","iopub.status.idle":"2022-03-09T14:55:00.886351Z","shell.execute_reply.started":"2022-03-09T14:55:00.858865Z","shell.execute_reply":"2022-03-09T14:55:00.885642Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['home_team_coach_id'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.887602Z","iopub.execute_input":"2022-03-09T14:55:00.887815Z","iopub.status.idle":"2022-03-09T14:55:00.901438Z","shell.execute_reply.started":"2022-03-09T14:55:00.887790Z","shell.execute_reply":"2022-03-09T14:55:00.900564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['away_team_coach_id'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.903696Z","iopub.execute_input":"2022-03-09T14:55:00.904111Z","iopub.status.idle":"2022-03-09T14:55:00.918557Z","shell.execute_reply.started":"2022-03-09T14:55:00.904076Z","shell.execute_reply":"2022-03-09T14:55:00.917910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cup_count = train_df['is_cup'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.920631Z","iopub.execute_input":"2022-03-09T14:55:00.920856Z","iopub.status.idle":"2022-03-09T14:55:00.940187Z","shell.execute_reply.started":"2022-03-09T14:55:00.920830Z","shell.execute_reply":"2022-03-09T14:55:00.939556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cup_count.plot.bar()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:00.941124Z","iopub.execute_input":"2022-03-09T14:55:00.941737Z","iopub.status.idle":"2022-03-09T14:55:01.215964Z","shell.execute_reply.started":"2022-03-09T14:55:00.941697Z","shell.execute_reply":"2022-03-09T14:55:01.215154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df[['home_team_history_rating_1','away_team_history_rating_1']]","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:01.217306Z","iopub.execute_input":"2022-03-09T14:55:01.217719Z","iopub.status.idle":"2022-03-09T14:55:01.234593Z","shell.execute_reply.started":"2022-03-09T14:55:01.217672Z","shell.execute_reply":"2022-03-09T14:55:01.232808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['home_rating'] = train_df['home_team_history_rating_1'] + train_df['home_team_history_rating_2'] + train_df['home_team_history_rating_3'] + train_df['home_team_history_rating_4'] + train_df['home_team_history_rating_5'] + train_df['home_team_history_rating_6'] +train_df['home_team_history_rating_7'] + train_df['home_team_history_rating_8'] + train_df['home_team_history_rating_9'] +train_df['home_team_history_rating_10']","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:55:01.235948Z","iopub.execute_input":"2022-03-09T14:55:01.236786Z","iopub.status.idle":"2022-03-09T14:55:01.248123Z","shell.execute_reply.started":"2022-03-09T14:55:01.236744Z","shell.execute_reply":"2022-03-09T14:55:01.247226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['away_rating'] = train_df['away_team_history_rating_1'] + train_df['away_team_history_rating_2'] + train_df['away_team_history_rating_3'] + train_df['away_team_history_rating_4'] + train_df['away_team_history_rating_5'] + train_df['away_team_history_rating_6'] +train_df['away_team_history_rating_7'] + train_df['away_team_history_rating_8'] + train_df['away_team_history_rating_9'] +train_df['away_team_history_rating_10']","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:57:43.369080Z","iopub.execute_input":"2022-03-09T14:57:43.369368Z","iopub.status.idle":"2022-03-09T14:57:43.380082Z","shell.execute_reply.started":"2022-03-09T14:57:43.369340Z","shell.execute_reply":"2022-03-09T14:57:43.379149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-03-09T14:57:48.355643Z","iopub.execute_input":"2022-03-09T14:57:48.355970Z","iopub.status.idle":"2022-03-09T14:57:48.441130Z","shell.execute_reply.started":"2022-03-09T14:57:48.355933Z","shell.execute_reply":"2022-03-09T14:57:48.440559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import Sequential\nfrom tensorflow.keras import layers","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:01:01.103457Z","iopub.execute_input":"2022-03-09T15:01:01.104097Z","iopub.status.idle":"2022-03-09T15:01:07.313631Z","shell.execute_reply.started":"2022-03-09T15:01:01.104064Z","shell.execute_reply":"2022-03-09T15:01:07.312694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train_df[['target',\n'home_team_history_rating_1',\n 'home_team_history_rating_2',\n 'home_team_history_rating_3',\n 'home_team_history_rating_4',\n 'home_team_history_rating_5',\n 'home_team_history_rating_6',\n 'home_team_history_rating_7',\n 'home_team_history_rating_8',\n 'home_team_history_rating_9',\n 'home_team_history_rating_10',\n'away_team_history_rating_1',\n 'away_team_history_rating_2',\n 'away_team_history_rating_3',\n 'away_team_history_rating_4',\n 'away_team_history_rating_5',\n 'away_team_history_rating_6',\n 'away_team_history_rating_7',\n 'away_team_history_rating_8',\n 'away_team_history_rating_9',\n 'away_team_history_rating_10']]","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:02:35.245434Z","iopub.execute_input":"2022-03-09T15:02:35.245755Z","iopub.status.idle":"2022-03-09T15:02:35.385649Z","shell.execute_reply.started":"2022-03-09T15:02:35.245720Z","shell.execute_reply":"2022-03-09T15:02:35.384781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['target'] = train['target'].replace(['away','draw','home'],[0, 1, 2])","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:02:56.181389Z","iopub.execute_input":"2022-03-09T15:02:56.181696Z","iopub.status.idle":"2022-03-09T15:02:56.265991Z","shell.execute_reply.started":"2022-03-09T15:02:56.181663Z","shell.execute_reply":"2022-03-09T15:02:56.264998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test_df[['home_team_history_rating_1',\n 'home_team_history_rating_2',\n 'home_team_history_rating_3',\n 'home_team_history_rating_4',\n 'home_team_history_rating_5',\n 'home_team_history_rating_6',\n 'home_team_history_rating_7',\n 'home_team_history_rating_8',\n 'home_team_history_rating_9',\n 'home_team_history_rating_10',\n'away_team_history_rating_1',\n 'away_team_history_rating_2',\n 'away_team_history_rating_3',\n 'away_team_history_rating_4',\n 'away_team_history_rating_5',\n 'away_team_history_rating_6',\n 'away_team_history_rating_7',\n 'away_team_history_rating_8',\n 'away_team_history_rating_9',\n 'away_team_history_rating_10']]","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:34:49.588650Z","iopub.execute_input":"2022-03-09T15:34:49.588938Z","iopub.status.idle":"2022-03-09T15:34:49.597743Z","shell.execute_reply.started":"2022-03-09T15:34:49.588906Z","shell.execute_reply":"2022-03-09T15:34:49.596981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = train.drop(['target'],axis = 1)\ny_train = train['target']\ny_train = pd.DataFrame(y_train)\nX_test = test","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:16:24.191543Z","iopub.execute_input":"2022-03-09T15:16:24.192481Z","iopub.status.idle":"2022-03-09T15:16:24.202947Z","shell.execute_reply.started":"2022-03-09T15:16:24.192421Z","shell.execute_reply":"2022-03-09T15:16:24.202143Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.fillna(0)","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:16:33.003997Z","iopub.execute_input":"2022-03-09T15:16:33.004261Z","iopub.status.idle":"2022-03-09T15:16:33.019632Z","shell.execute_reply.started":"2022-03-09T15:16:33.004234Z","shell.execute_reply":"2022-03-09T15:16:33.018695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.fillna(0)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([\n    layers.Input(20),\n    layers.Dense(10, activation = 'relu'),\n    layers.Dense(3)\n])","metadata":{"execution":{"iopub.status.busy":"2022-03-09T16:11:04.815210Z","iopub.execute_input":"2022-03-09T16:11:04.815530Z","iopub.status.idle":"2022-03-09T16:11:04.842288Z","shell.execute_reply.started":"2022-03-09T16:11:04.815480Z","shell.execute_reply":"2022-03-09T16:11:04.841450Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer = 'adam',\n             loss = tf.keras.losses.SparseCategoricalCrossentropy(),\n             metrics = ['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2022-03-09T16:11:05.602134Z","iopub.execute_input":"2022-03-09T16:11:05.602427Z","iopub.status.idle":"2022-03-09T16:11:05.612188Z","shell.execute_reply.started":"2022-03-09T16:11:05.602393Z","shell.execute_reply":"2022-03-09T16:11:05.611595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T16:11:06.019653Z","iopub.execute_input":"2022-03-09T16:11:06.020222Z","iopub.status.idle":"2022-03-09T16:11:06.027261Z","shell.execute_reply.started":"2022-03-09T16:11:06.020170Z","shell.execute_reply":"2022-03-09T16:11:06.026613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X_train,y_train,epochs = 50)","metadata":{"execution":{"iopub.status.busy":"2022-03-09T16:01:26.962056Z","iopub.execute_input":"2022-03-09T16:01:26.962915Z","iopub.status.idle":"2022-03-09T16:01:32.562981Z","shell.execute_reply.started":"2022-03-09T16:01:26.962868Z","shell.execute_reply":"2022-03-09T16:01:32.559760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prob_model = tf.keras.Sequential([model,tf.keras.layers.Softmax()])","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:43:37.753147Z","iopub.execute_input":"2022-03-09T15:43:37.753732Z","iopub.status.idle":"2022-03-09T15:43:37.760592Z","shell.execute_reply.started":"2022-03-09T15:43:37.753699Z","shell.execute_reply":"2022-03-09T15:43:37.759893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction = prob_model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:43:37.761907Z","iopub.execute_input":"2022-03-09T15:43:37.762358Z","iopub.status.idle":"2022-03-09T15:43:39.983713Z","shell.execute_reply.started":"2022-03-09T15:43:37.762327Z","shell.execute_reply":"2022-03-09T15:43:39.982844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:43:39.985667Z","iopub.execute_input":"2022-03-09T15:43:39.986288Z","iopub.status.idle":"2022-03-09T15:43:39.993160Z","shell.execute_reply.started":"2022-03-09T15:43:39.986236Z","shell.execute_reply":"2022-03-09T15:43:39.992301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ans = pd.DataFrame()\nans['id'] = test_df['id']\nans['home'] = prediction[:,2]\nans['draw'] = prediction[:,1]\nans['away'] = prediction[:,0]","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:43:42.666662Z","iopub.execute_input":"2022-03-09T15:43:42.667288Z","iopub.status.idle":"2022-03-09T15:43:42.684263Z","shell.execute_reply.started":"2022-03-09T15:43:42.667246Z","shell.execute_reply":"2022-03-09T15:43:42.683701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ans.head()","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:43:43.206996Z","iopub.execute_input":"2022-03-09T15:43:43.207656Z","iopub.status.idle":"2022-03-09T15:43:43.217373Z","shell.execute_reply.started":"2022-03-09T15:43:43.207622Z","shell.execute_reply":"2022-03-09T15:43:43.216590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ans.to_csv(\"submission1.csv\", index = False)","metadata":{"execution":{"iopub.status.busy":"2022-03-09T15:44:22.882048Z","iopub.execute_input":"2022-03-09T15:44:22.882585Z","iopub.status.idle":"2022-03-09T15:44:23.271750Z","shell.execute_reply.started":"2022-03-09T15:44:22.882546Z","shell.execute_reply":"2022-03-09T15:44:23.270902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}