{"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":"markdown","source":"<center>\n<h1>Football Match Probability Prediction (Logistic Regression)</h1>\n<img src=\"https://storage.googleapis.com/kaggle-competitions/kaggle/34189/logos/header.png\" />\n</center>\n<h4>This competition is about predicting the probabilities of more than 150000 match outcomes using the recent sequence of 10 matches of the teams.</h4>\n","metadata":{}},{"cell_type":"markdown","source":"#### 1. Import modules and loading the data\nFirst let's import modules, the training and the test set. The test set contains the same columns than the training set without the target.","metadata":{}},{"cell_type":"code","source":"# data processing\nimport pandas as pd\n# linear algebra\nimport numpy as np\n\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:10.513739Z","iopub.execute_input":"2022-05-23T20:31:10.513978Z","iopub.status.idle":"2022-05-23T20:31:10.518877Z","shell.execute_reply.started":"2022-05-23T20:31:10.513953Z","shell.execute_reply":"2022-05-23T20:31:10.518262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load the data\ntrain = pd.read_csv(\"../input/football-match-probability-prediction/train.csv\")\ntest = pd.read_csv(\"../input/football-match-probability-prediction/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:10.552076Z","iopub.execute_input":"2022-05-23T20:31:10.552366Z","iopub.status.idle":"2022-05-23T20:31:15.443202Z","shell.execute_reply.started":"2022-05-23T20:31:10.552336Z","shell.execute_reply":"2022-05-23T20:31:15.44206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show the first 5 rows\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:15.445237Z","iopub.execute_input":"2022-05-23T20:31:15.445563Z","iopub.status.idle":"2022-05-23T20:31:15.478782Z","shell.execute_reply.started":"2022-05-23T20:31:15.445524Z","shell.execute_reply":"2022-05-23T20:31:15.477718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#function that return columns contient the string where we written\ndef features_filtred(data,column_name):\n    features_filtred = [_ for _ in data.columns if str(column_name) in _]\n    return features_filtred","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:15.480619Z","iopub.execute_input":"2022-05-23T20:31:15.480931Z","iopub.status.idle":"2022-05-23T20:31:15.486477Z","shell.execute_reply.started":"2022-05-23T20:31:15.480891Z","shell.execute_reply":"2022-05-23T20:31:15.4852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 2. Preprocessing data\nwe drop all columns contient _id ,_name,_date","metadata":{}},{"cell_type":"code","source":"# we drop all columns contient _id ,_name,_date\n#from train-datasets\nall_id_features = features_filtred(train,\"_id\")\ntrain = train.drop(all_id_features, 1)\n\nall_name_features1 = features_filtred(train,\"_name\")\ntrain = train.drop(all_name_features1, 1)\n\nall_date_features2 = features_filtred(train,\"date\")\ntrain = train.drop(all_date_features2, 1)\n\n#from test-datasets\nall_id_features3 = features_filtred(test,\"_id\")\ntest = test.drop(all_id_features3, 1)\n\nall_name_features4 = features_filtred(test,\"_name\")\ntest = test.drop(all_name_features4, 1)\n\nall_date_features5 = features_filtred(test,\"date\")\ntest = test.drop(all_date_features5, 1)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:15.489122Z","iopub.execute_input":"2022-05-23T20:31:15.489578Z","iopub.status.idle":"2022-05-23T20:31:15.738183Z","shell.execute_reply.started":"2022-05-23T20:31:15.489437Z","shell.execute_reply":"2022-05-23T20:31:15.737136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### remove the missing values of columns and replce them with its mean","metadata":{}},{"cell_type":"code","source":"#sum of missing values in every column in our datasets\ntrain.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:15.739363Z","iopub.execute_input":"2022-05-23T20:31:15.73956Z","iopub.status.idle":"2022-05-23T20:31:15.777137Z","shell.execute_reply.started":"2022-05-23T20:31:15.739531Z","shell.execute_reply":"2022-05-23T20:31:15.775811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:15.778514Z","iopub.execute_input":"2022-05-23T20:31:15.778704Z","iopub.status.idle":"2022-05-23T20:31:15.802136Z","shell.execute_reply.started":"2022-05-23T20:31:15.778681Z","shell.execute_reply":"2022-05-23T20:31:15.801619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Replace the missing values in each column with its mean\ntrain[\"is_cup\"].fillna(True, inplace=True)\ntrain.fillna(train.mean(), inplace=True)\ntest.fillna(test.mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:15.803139Z","iopub.execute_input":"2022-05-23T20:31:15.80388Z","iopub.status.idle":"2022-05-23T20:31:16.763639Z","shell.execute_reply.started":"2022-05-23T20:31:15.80385Z","shell.execute_reply":"2022-05-23T20:31:16.762606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:16.765003Z","iopub.execute_input":"2022-05-23T20:31:16.76528Z","iopub.status.idle":"2022-05-23T20:31:16.797301Z","shell.execute_reply.started":"2022-05-23T20:31:16.765244Z","shell.execute_reply":"2022-05-23T20:31:16.796181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['target'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:16.798867Z","iopub.execute_input":"2022-05-23T20:31:16.799363Z","iopub.status.idle":"2022-05-23T20:31:16.818913Z","shell.execute_reply.started":"2022-05-23T20:31:16.79933Z","shell.execute_reply":"2022-05-23T20:31:16.81748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Encoding the two features ['target'] and ['is_cup']\nwhere ['away', 'home', 'draw'] => [0, 2, 1] And ['True', 'False'] => [0, 1] ","metadata":{}},{"cell_type":"code","source":"#Encoding the two features ['target'] and ['is_cup']\nfrom sklearn.preprocessing import LabelEncoder\nlabelencoder = LabelEncoder()\n\ntest['is_cup']  = labelencoder.fit_transform(test['is_cup'])\ntrain['is_cup'] = labelencoder.fit_transform(train['is_cup'])\ntrain['target'] = labelencoder.fit_transform(train['target'])","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:16.823102Z","iopub.execute_input":"2022-05-23T20:31:16.823439Z","iopub.status.idle":"2022-05-23T20:31:16.886722Z","shell.execute_reply.started":"2022-05-23T20:31:16.823412Z","shell.execute_reply":"2022-05-23T20:31:16.885971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['is_cup'].unique()\ntest['is_cup'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:16.887849Z","iopub.execute_input":"2022-05-23T20:31:16.888107Z","iopub.status.idle":"2022-05-23T20:31:16.895852Z","shell.execute_reply.started":"2022-05-23T20:31:16.888071Z","shell.execute_reply":"2022-05-23T20:31:16.894846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['target'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:16.897148Z","iopub.execute_input":"2022-05-23T20:31:16.897791Z","iopub.status.idle":"2022-05-23T20:31:16.909136Z","shell.execute_reply.started":"2022-05-23T20:31:16.897759Z","shell.execute_reply":"2022-05-23T20:31:16.908053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Split train data","metadata":{}},{"cell_type":"code","source":"#split train data to Input \"X\" and Output \"Y\"\nID = train['id']\nY = train['target']\nX = train.iloc[:, 2:]","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:16.910161Z","iopub.execute_input":"2022-05-23T20:31:16.910333Z","iopub.status.idle":"2022-05-23T20:31:16.93824Z","shell.execute_reply.started":"2022-05-23T20:31:16.910311Z","shell.execute_reply":"2022-05-23T20:31:16.937465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:16.939535Z","iopub.execute_input":"2022-05-23T20:31:16.939755Z","iopub.status.idle":"2022-05-23T20:31:16.980069Z","shell.execute_reply.started":"2022-05-23T20:31:16.939725Z","shell.execute_reply":"2022-05-23T20:31:16.979448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 3. Features Selection\nThe scikit-learn library provides the SelectKBest class which can be used with a suite of\ndifferent statistical tests to select a specific number of features.","metadata":{}},{"cell_type":"code","source":"from sklearn.feature_selection import SelectKBest\nfrom sklearn.feature_selection import chi2\nSKB = SelectKBest(score_func=chi2, k=4)\nfit = SKB.fit(X, Y)\nnp.set_printoptions(precision=3)\nprint(fit.scores_)\nfeatures = fit.transform(X)\nprint(features[0:5,:])\nX.columns","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:16.980994Z","iopub.execute_input":"2022-05-23T20:31:16.981204Z","iopub.status.idle":"2022-05-23T20:31:17.120477Z","shell.execute_reply.started":"2022-05-23T20:31:16.981173Z","shell.execute_reply":"2022-05-23T20:31:17.119896Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"==> You can see the scores for each attribute and the chosen attributes (those with the highest scores).\nhigher)","metadata":{}},{"cell_type":"markdown","source":"#### Drop the features","metadata":{}},{"cell_type":"code","source":"# we drop the features with the low scores\nall_history_coach_features = features_filtred(X,\"history_coach_\")\nX = X.drop(all_history_coach_features, 1)\n\nall_history_rating_features = features_filtred(X,\"rating_\")\nX = X.drop(all_history_rating_features, 1)\n\nall_history_coach_features_test = features_filtred(test,\"history_coach_\")\ntest = test.drop(all_history_coach_features_test, 1)\n\nall_history_rating_features_test = features_filtred(test,\"rating_\")\ntest = test.drop(all_history_rating_features_test, 1)","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:17.123983Z","iopub.execute_input":"2022-05-23T20:31:17.124627Z","iopub.status.idle":"2022-05-23T20:31:17.193552Z","shell.execute_reply.started":"2022-05-23T20:31:17.124592Z","shell.execute_reply":"2022-05-23T20:31:17.193042Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Create sub-tables for features of Home team / Away team","metadata":{}},{"cell_type":"code","source":"#create sub-tables for features of Home team\nhome_team_history_is_play_home = features_filtred(train,\"home_team_history_is_play_home\")\nX_HTPH = X[home_team_history_is_play_home]\n\nhome_team_history_is_cup = features_filtred(train,\"home_team_history_is_cup_\")\nX_HTC = X[home_team_history_is_cup]\n\nhome_team_history_goal = features_filtred(train,\"home_team_history_goal_\")\nX_HTG = X[home_team_history_goal]\n\nhome_team_history_opponent_goal = features_filtred(train,\"home_team_history_opponent_goal\")\nX_HTOG = X[home_team_history_opponent_goal]\n\n\n#create sub-tables for features of Away team\n\naway_team_history_is_play_home = features_filtred(train,\"away_team_history_is_play_home\")\nX_ATPH = X[away_team_history_is_play_home]\n\naway_team_history_is_cup = features_filtred(train,\"away_team_history_is_cup_\")\nX_ATC = X[away_team_history_is_cup]\n\naway_team_history_goal = features_filtred(train,\"away_team_history_goal_\")\nX_ATG = X[away_team_history_goal]\n\naway_team_history_opponent_goal = features_filtred(train,\"away_team_history_opponent_goal\")\nX_ATOG = X[away_team_history_opponent_goal]\n\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:17.19477Z","iopub.execute_input":"2022-05-23T20:31:17.195051Z","iopub.status.idle":"2022-05-23T20:31:17.223389Z","shell.execute_reply.started":"2022-05-23T20:31:17.195013Z","shell.execute_reply":"2022-05-23T20:31:17.222409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#create sub-tables for features of Home team\nhome_team_history_is_play_home = features_filtred(test,\"home_team_history_is_play_home\")\nX_HTPH_test = test[home_team_history_is_play_home]\n\nhome_team_history_is_cup = features_filtred(test,\"home_team_history_is_cup_\")\nX_HTC_test = test[home_team_history_is_cup]\n\nhome_team_history_goal = features_filtred(test,\"home_team_history_goal_\")\nX_HTG_test = test[home_team_history_goal]\n\nhome_team_history_opponent_goal = features_filtred(test,\"home_team_history_opponent_goal\")\nX_HTOG_test = test[home_team_history_opponent_goal]\n\n\n#create sub-tables for features of Away team\n\naway_team_history_is_play_home = features_filtred(test,\"away_team_history_is_play_home\")\nX_ATPH_test = test[away_team_history_is_play_home]\n\naway_team_history_is_cup = features_filtred(test,\"away_team_history_is_cup_\")\nX_ATC_test = test[away_team_history_is_cup]\n\naway_team_history_goal = features_filtred(test,\"away_team_history_goal_\")\nX_ATG_test = test[away_team_history_goal]\n\naway_team_history_opponent_goal = features_filtred(test,\"away_team_history_opponent_goal\")\nX_ATOG_test = test[away_team_history_opponent_goal]\n\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:17.225304Z","iopub.execute_input":"2022-05-23T20:31:17.225609Z","iopub.status.idle":"2022-05-23T20:31:17.258626Z","shell.execute_reply.started":"2022-05-23T20:31:17.225569Z","shell.execute_reply":"2022-05-23T20:31:17.257573Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_HTPH_test","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:17.260152Z","iopub.execute_input":"2022-05-23T20:31:17.260887Z","iopub.status.idle":"2022-05-23T20:31:17.279575Z","shell.execute_reply.started":"2022-05-23T20:31:17.260855Z","shell.execute_reply":"2022-05-23T20:31:17.278901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 4. Principal Component Analysis\nPrincipal component analysis uses linear algebra to transform the data set into a compressed form. Generally, this is called a data reduction technique. A property of PCA is that you can choose the number of dimensions\nor principal component in the transformed result.\nwhere we reduce the 10 features to one feature","metadata":{}},{"cell_type":"code","source":"from sklearn.decomposition import PCA","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:17.280641Z","iopub.execute_input":"2022-05-23T20:31:17.280833Z","iopub.status.idle":"2022-05-23T20:31:17.295233Z","shell.execute_reply.started":"2022-05-23T20:31:17.28081Z","shell.execute_reply":"2022-05-23T20:31:17.294317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=1)\n\n#PCA for Home_Team_Features\nX_HTPH_C = pca.fit_transform(X_HTPH)\nX_HTC_C = pca.fit_transform(X_HTC)\nX_HTG_C = pca.fit_transform(X_HTG)\nX_HTOG_C = pca.fit_transform(X_HTOG)\n\n#PCA for Home_Team_Features\nX_ATPH_C = pca.fit_transform(X_ATPH)\nX_ATC_C = pca.fit_transform(X_ATC)\nX_ATG_C = pca.fit_transform(X_ATG)\nX_ATOG_C = pca.fit_transform(X_ATOG)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:17.296287Z","iopub.execute_input":"2022-05-23T20:31:17.296581Z","iopub.status.idle":"2022-05-23T20:31:18.966936Z","shell.execute_reply.started":"2022-05-23T20:31:17.296556Z","shell.execute_reply":"2022-05-23T20:31:18.966356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca_test = PCA(n_components=1)\n\n#PCA for Home_Team_Features\nX_HTPH_C_test = pca_test.fit_transform(X_HTPH_test)\nX_HTC_C_test = pca_test.fit_transform(X_HTC_test)\nX_HTG_C_test = pca_test.fit_transform(X_HTG_test)\nX_HTOG_C_test = pca_test.fit_transform(X_HTOG_test)\n\n#PCA for Home_Team_Features\nX_ATPH_C_test = pca_test.fit_transform(X_ATPH_test)\nX_ATC_C_test = pca_test.fit_transform(X_ATC_test)\nX_ATG_C_test = pca_test.fit_transform(X_ATG_test)\nX_ATOG_C_test = pca_test.fit_transform(X_ATOG_test)","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:18.967915Z","iopub.execute_input":"2022-05-23T20:31:18.968251Z","iopub.status.idle":"2022-05-23T20:31:20.058796Z","shell.execute_reply.started":"2022-05-23T20:31:18.968219Z","shell.execute_reply":"2022-05-23T20:31:20.058122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# create a new feature that replaces the 10 old features through PCA\nX[\"home_team_is_play_home\"] = X_HTPH_C\nhome_team_history_is_play_home = features_filtred(train,\"home_team_history_is_play_home_\")\nX = X.drop(home_team_history_is_play_home,1)\n\nX[\"home_team_is_cup\"] = X_HTC_C\nhome_team_history_is_cup = features_filtred(train,\"home_team_history_is_cup_\")\nX = X.drop(home_team_history_is_cup,1) \n\nX[\"home_team_goal\"] = X_HTG_C\nhome_team_history_goal = features_filtred(train,\"home_team_history_goal_\")\nX = X.drop(home_team_history_goal,1)\n\nX[\"home_team_opponent_goal\"] = X_HTOG_C\nhome_team_history_opponent_goal = features_filtred(train,\"home_team_history_opponent_goal\")\nX = X.drop(home_team_history_opponent_goal,1)\n\n\n\nX[\"away_team_is_play_home\"] = X_ATPH_C\naway_team_history_is_play_home = features_filtred(train,\"away_team_history_is_play_home_\")\nX = X.drop(away_team_history_is_play_home,1)\n\nX[\"away_team_is_cup\"] = X_ATC_C\naway_team_history_is_cup = features_filtred(train,\"away_team_history_is_cup_\")\nX = X.drop(away_team_history_is_cup,1)\n\nX[\"away_team_goal\"] = X_ATG_C\naway_team_history_goal = features_filtred(train,\"away_team_history_goal_\")\nX = X.drop(away_team_history_goal,1)\n\nX[\"away_team_opponent_goal\"] = X_ATOG_C\naway_team_history_opponent_goal = features_filtred(train,\"away_team_history_opponent_goal\")\nX = X.drop(away_team_history_opponent_goal,1)\n","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:20.059904Z","iopub.execute_input":"2022-05-23T20:31:20.060236Z","iopub.status.idle":"2022-05-23T20:31:20.30408Z","shell.execute_reply.started":"2022-05-23T20:31:20.060204Z","shell.execute_reply":"2022-05-23T20:31:20.3032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# create a new feature that replaces the 10 old features through PCA\ntest[\"home_team_is_play_home\"] = X_HTPH_C_test\nhome_team_history_is_play_home = features_filtred(test,\"home_team_history_is_play_home_\")\ntest = test.drop(home_team_history_is_play_home,1)\n\ntest[\"home_team_is_cup\"] = X_HTC_C_test\nhome_team_history_is_cup = features_filtred(test,\"home_team_history_is_cup_\")\ntest = test.drop(home_team_history_is_cup,1)\n\ntest[\"home_team_goal\"] = X_HTG_C_test\nhome_team_history_goal = features_filtred(test,\"home_team_history_goal_\")\ntest = test.drop(home_team_history_goal,1)\n\ntest[\"home_team_opponent_goal\"] = X_HTOG_C_test\nhome_team_history_opponent_goal = features_filtred(test,\"home_team_history_opponent_goal\")\ntest = test.drop(home_team_history_opponent_goal,1)\n\n\n\ntest[\"away_team_is_play_home\"] = X_ATPH_C_test\naway_team_history_is_play_home = features_filtred(test,\"away_team_history_is_play_home_\")\ntest = test.drop(away_team_history_is_play_home,1)\n\ntest[\"away_team_is_cup\"] = X_ATC_C_test\naway_team_history_is_cup = features_filtred(test,\"away_team_history_is_cup_\")\ntest = test.drop(away_team_history_is_cup,1)\n\ntest[\"away_team_goal\"] = X_ATG_C_test\naway_team_history_goal = features_filtred(test,\"away_team_history_goal_\")\ntest = test.drop(away_team_history_goal,1)\n\ntest[\"away_team_opponent_goal\"] = X_ATOG_C_test\naway_team_history_opponent_goal = features_filtred(test,\"away_team_history_opponent_goal\")\ntest = test.drop(away_team_history_opponent_goal,1)\n","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:20.30524Z","iopub.execute_input":"2022-05-23T20:31:20.305876Z","iopub.status.idle":"2022-05-23T20:31:20.430986Z","shell.execute_reply.started":"2022-05-23T20:31:20.305847Z","shell.execute_reply":"2022-05-23T20:31:20.429842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.head(3)","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:20.432267Z","iopub.execute_input":"2022-05-23T20:31:20.432497Z","iopub.status.idle":"2022-05-23T20:31:20.447525Z","shell.execute_reply.started":"2022-05-23T20:31:20.432468Z","shell.execute_reply":"2022-05-23T20:31:20.446677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"==> It can be seen that the transform dataset (9 principal components) bears little resemblance to the source data.","metadata":{}},{"cell_type":"markdown","source":"#### 5. Feature Importance , FI\nDecision trees like Random Forest and Extra Trees can be used to estimate the importance of entities.\nhere we build a classifier ExtraTreesClassifier for the dataset. ","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import ExtraTreesClassifier\n\nmodel = ExtraTreesClassifier()\nmodel.fit(X, Y)\nprint(model.feature_importances_)","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:20.449049Z","iopub.execute_input":"2022-05-23T20:31:20.449346Z","iopub.status.idle":"2022-05-23T20:31:40.493393Z","shell.execute_reply.started":"2022-05-23T20:31:20.449309Z","shell.execute_reply":"2022-05-23T20:31:40.492567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ID_test = test['id']\nID_train = ID\nx_train = X\ny_train = Y\nx_test = test.iloc[:,1:]\n","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:40.494602Z","iopub.execute_input":"2022-05-23T20:31:40.495447Z","iopub.status.idle":"2022-05-23T20:31:40.501071Z","shell.execute_reply.started":"2022-05-23T20:31:40.495401Z","shell.execute_reply":"2022-05-23T20:31:40.500234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### 5. Training using Logistic Regression\nLogistic regression is a classification algorithm used to assign observations\nto a discrete set of classes","metadata":{}},{"cell_type":"markdown","source":"#### Fit the model and a make submission","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import LogisticRegression\n\n#using LogisticRegression for prediction\nlg = LogisticRegression()\nlg.fit(x_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:40.503444Z","iopub.execute_input":"2022-05-23T20:31:40.503632Z","iopub.status.idle":"2022-05-23T20:31:42.886241Z","shell.execute_reply.started":"2022-05-23T20:31:40.503605Z","shell.execute_reply":"2022-05-23T20:31:42.885567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_prop_pred = lg.predict_proba(x_test)\ny_prop_pred\n","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:42.887559Z","iopub.execute_input":"2022-05-23T20:31:42.887989Z","iopub.status.idle":"2022-05-23T20:31:42.922238Z","shell.execute_reply.started":"2022-05-23T20:31:42.887951Z","shell.execute_reply":"2022-05-23T20:31:42.921548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_test = pd.DataFrame(y_prop_pred,columns=['away', 'draw', 'home'])\nsubmission = pd.DataFrame()\nsubmission['id'] = test[['id']]\nsubmission['away'] = submission_test['away']\nsubmission['draw'] = submission_test['draw']\nsubmission['home'] = submission_test['home']\n\n\n# submission[['id', 'home', 'away', 'draw']].to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:31:42.923495Z","iopub.execute_input":"2022-05-23T20:31:42.923915Z","iopub.status.idle":"2022-05-23T20:31:42.947462Z","shell.execute_reply.started":"2022-05-23T20:31:42.923878Z","shell.execute_reply":"2022-05-23T20:31:42.946775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission","metadata":{"execution":{"iopub.status.busy":"2022-05-23T20:32:14.196633Z","iopub.execute_input":"2022-05-23T20:32:14.196886Z","iopub.status.idle":"2022-05-23T20:32:14.209477Z","shell.execute_reply.started":"2022-05-23T20:32:14.196861Z","shell.execute_reply":"2022-05-23T20:32:14.208678Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h5> Kaggle_score :</h5>\n<center>\n<img src=\"./score.png\" />\n</center>","metadata":{}}]}