{"cells":[{"metadata":{},"cell_type":"markdown","source":"**With this version i am trying to use detailed files rather then compact files**"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","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 in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","collapsed":true,"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":false},"cell_type":"markdown","source":"### Part 1 : Understanding the data"},{"metadata":{},"cell_type":"markdown","source":"# Part 1 : Understanding the data\n\n![](https://cdn-images-1.medium.com/max/1200/1*wdGUB-2bxIMCzbUJOGw65w.jpeg)\n\nIn the first stage of the competition, Kagglers will rely on results of past tournaments to build and test models. External data can be used as well for improving the results.\n\nIn the second stage, competitors will forecast outcomes of all possible matchups in the 2020 NCAA Division I Men’s and Women’s Basketball Championships. You don't need to participate in the first stage to enter the second. The first stage exists to incentivize model building and provide a means to score predictions. The real competition is forecasting the 2020 results.\n\nAs the official public cloud provider of the **NCAA**, **Google Cloud** is proud to provide a competition to help participants strengthen their knowledge of basketball, statistics, data modeling, and cloud technology. As part of its journey to the cloud, the NCAA has migrated 80+ years of historical and play-by-play data, from **90 championships and 24 sports, to Google Cloud Platform (GCP)**. \n\n\n\n# **NCAA Division I Basketball Tournament**\n\n \n![](https://cdn-images-1.medium.com/max/800/1*2fU29HRgk4ySJ_l1N5NaJw.jpeg)\n\nThis tournament is a knockout tournament where the loser is immediately eliminated from the tournament. Since it is mostly played in march, hence it has been accorded the title of **March Madness**. The first edition took place in 1939 and has been regularly held since then. the Women’s Championship was inaugurated in the 1981–82 season.\n\n# Format\n\nThe male edition tournament comprises of **68** teams that compete in **7** rounds for the National Championship Title. However, the number of Teams in the Women’s edition is **64**.\n\n![](https://cdn-images-1.medium.com/max/800/1*TaaEJ3zTwhuU67QPqqrkaA.png)\n\n---\n\n# Selection\n\nThe selection procedure takes place by two methods:\n\n![](https://cdn-images-1.medium.com/max/800/1*s7gpAnvzL-mQ0lKlzc8xXQ.png)\n\n## 1. Automatic\n\n32 Teams get selected in this way.\n\n-   Men’s Division 1 Team comprises of **353** Teams.\n\n![](https://cdn-images-1.medium.com/max/800/1*DBT72cUKGLIvXmjO7mBgyQ.png)\n\n-   Each one of those teams belongs to **32** [conferences](https://en.wikipedia.org/wiki/List_of_NCAA_conferences).\n\n![](https://cdn-images-1.medium.com/max/800/1*rq4HBtMnQeGsiI7hOmBfIA.png)\n\n-   Each of those conferences conducts a tournament and if a time wins the tournament, they get selected for the NCAA.\n\n  \n\n## 2. At Large\n\nThe second selection process is called ‘At Large’ where The NCAA selection committee convenes at the final days of the regular season and decides which 36 teams which are not the Automatic qualifiers can be sent to the playoffs. This selection is based on multiple stats and rankings.\n\n---\n\n## Selection Sunday\n\nThese “at-large” teams are announced in a nationally televised event on the Sunday preceding the [“First Four” play-in games](https://en.wikipedia.org/wiki/NCAA_Men%27s_Division_I_Basketball_Opening_Round_game \"NCAA Men's Division I Basketball Opening Round game\"). This Sunday is called ‘Selection Sunday and is on March 15.\n\n## Seeding\n\nAfter all the 68(64 in case of Women), have been decided, the selection committee ranks them in a process called seeding where each team gets a ranking from 1 to 68. Then **First Four** play-in games are contested between teams holding the four lowest-seeded automatic bids and the four lowest-seeded at-large bids.\n\nThe Teams are then split into 4 regions of 16 Teams each. Each team is now ranked from 1 to 16 in each region. After the [First Four](https://en.wikipedia.org/wiki/First_Four \"First Four\"), the tournament occurs during the course of three weekends, at pre-selected neutral sites across the United States. Here, the first round matches are determined by pitting the top team in the region with the lowest-seeded team in that region and so on. This ranking is the team’s seed.\n\n# March Madness Begins\n![](https://www.ncaa.com/sites/default/files/public/styles/original/public-s3/images/2020/02/12/kelly-campbell-depaul-2020-ncaa.jpg?itok=suRzKxqw)\n\n## First Round\n\nThe First round consisting of 64 teams playing in 32 games over the course of a week. From here 32 teams emerge as winners and go on to the second round.\n\n## Sweet Sixteen\n\nNext, the sweet sixteen round takes place, which sees the elimination of 16 teams. Rest of the 16 teams move forward.\n\n## Elite Eight\n\nThe next fight is for the Elite Eight as only 8 teams remain in the competition.\n\n## Final Four\n![](https://media.giphy.com/media/2fMOp0fPmvwwCgLXUK/giphy.gif)\nThe penultimate round of the tournament where the 4 teams contest to reserve a place in the finals. Four teams, one from each region (East, South, Midwest, and West), compete in a preselected location for the national championship.\n \n ---\n\n# Submission Logic\n\nSubmission File\nThe file you submit will depend on whether the competition is in stage 1 (historical model building) or stage 2 (the 2020 tournament). Sample submission files will be provided for both stages. The format is a list of every possible matchup between the tournament teams. Since team1 vs. team2 is the same as team2 vs. team1, we only include the game pairs where team1 has the lower team id. For example, in a tournament of 64 teams, you will predict (64*63)/2  = 2,016 matchups. \n\nEach game has a unique id created by concatenating the season in which the game was played, the team1 id, and the team2 id. For example, \"2015_3106_3107\" indicates team 3106 played team 3107 in the year 2015. You must predict the probability that the team with the lower id beats the team with the higher id.\n\nThe resulting submission format looks like the following, where \"pred\" represents the predicted probability that the first team will win:"},{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom sklearn.linear_model import LogisticRegression\nimport matplotlib.pyplot as plt\nfrom sklearn.utils import shuffle\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.model_selection import KFold\nimport lightgbm as lgb\nimport xgboost as xgb\nfrom xgboost import XGBClassifier\nimport gc\nimport matplotlib.pyplot as plt\nfrom sklearn import preprocessing\nfrom sklearn.model_selection import RandomizedSearchCV\nfrom sklearn.ensemble import RandomForestRegressor","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Loading the Data**"},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Compact_Results = pd.read_csv('../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1/MNCAATourneyCompactResults.csv')\nTourney_Seeds = pd.read_csv('../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1/MNCAATourneySeeds.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results = pd.read_csv('../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1/MRegularSeasonCompactResults.csv')\nMSeasons = pd.read_csv('../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1/MSeasons.csv')\nMTeams=pd.read_csv('../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1/MTeams.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Let us check data in each of File**"},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Compact_Results.head(65)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Compact_Results.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Compact_Results.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results.shape","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Exlloring Number of Teams Years wise. We can see in data at start number of match were 64 which have increased to 68 later**"},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Seeds.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Seeds.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Seeds.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Compact_Results.groupby('Season').mean().head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Results_Compact=pd.merge(Tourney_Compact_Results, Tourney_Seeds, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')\nTourney_Results_Compact.rename(columns={'Seed':'WinningSeed'},inplace=True)\nTourney_Results_Compact=Tourney_Results_Compact.drop(['TeamID'],axis=1)\n\nTourney_Results_Compact = pd.merge(Tourney_Results_Compact, Tourney_Seeds, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')\nTourney_Results_Compact.rename(columns={'Seed':'LoosingSeed'}, inplace=True)\nTourney_Results_Compact=Tourney_Results_Compact.drop(['TeamID','NumOT','WLoc'],axis=1)\n\n\nTourney_Results_Compact","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Results_Compact=Tourney_Results_Compact.drop(['WScore','LScore'],axis=1)\nTourney_Results_Compact.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Results_Compact.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Results_Compact['WinningSeed'] = Tourney_Results_Compact['WinningSeed'].str.extract('(\\d+)', expand=True)\nTourney_Results_Compact['LoosingSeed'] = Tourney_Results_Compact['LoosingSeed'].str.extract('(\\d+)', expand=True)\nTourney_Results_Compact.WinningSeed = pd.to_numeric(Tourney_Results_Compact.WinningSeed, errors='coerce')\nTourney_Results_Compact.LoosingSeed = pd.to_numeric(Tourney_Results_Compact.LoosingSeed, errors='coerce')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"season_winning_team = RegularSeason_Compact_Results[['Season', 'WTeamID', 'WScore']]\nseason_losing_team = RegularSeason_Compact_Results[['Season', 'LTeamID', 'LScore']]\nseason_winning_team.rename(columns={'WTeamID':'TeamID','WScore':'Score'}, inplace=True)\nseason_losing_team.rename(columns={'LTeamID':'TeamID','LScore':'Score'}, inplace=True)\nRegularSeason_Compact_Results = pd.concat((season_winning_team, season_losing_team)).reset_index(drop=True)\nRegularSeason_Compact_Results","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results_Final = RegularSeason_Compact_Results.groupby(['Season', 'TeamID'])['Score'].sum().reset_index()\nRegularSeason_Compact_Results_Final","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Results_Compact = pd.merge(Tourney_Results_Compact, RegularSeason_Compact_Results_Final, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')\nTourney_Results_Compact.rename(columns={'Score':'WScoreTotal'}, inplace=True)\nTourney_Results_Compact","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Results_Compact = Tourney_Results_Compact.drop('TeamID', axis=1)\nTourney_Results_Compact = pd.merge(Tourney_Results_Compact, RegularSeason_Compact_Results_Final, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')\nTourney_Results_Compact.rename(columns={'Score':'LScoreTotal'}, inplace=True)\nTourney_Results_Compact = Tourney_Results_Compact.drop('TeamID', axis=1)\nTourney_Results_Compact.to_csv('Tourney_Win_Results_Train.csv', index=False)\nTourney_Results_Compact=Tourney_Results_Compact[Tourney_Results_Compact['Season'] < 2015] \nTourney_Results_Compact","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Win_Results=Tourney_Results_Compact.drop(['Season','WTeamID','LTeamID','DayNum'],axis=1)\nTourney_Win_Results","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Win_Results.rename(columns={'WinningSeed':'Seed1', 'LoosingSeed':'Seed2', 'WScoreTotal':'ScoreT1', 'LScoreTotal':'ScoreT2'}, inplace=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularSeason_Compact_Results.head(200)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Win_Results","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tourney_lose_result = Tourney_Win_Results.copy()\ntourney_lose_result['Seed1'] = Tourney_Win_Results['Seed2']\ntourney_lose_result['Seed2'] = Tourney_Win_Results['Seed1']\ntourney_lose_result['ScoreT1'] = Tourney_Win_Results['ScoreT2']\ntourney_lose_result['ScoreT2'] = Tourney_Win_Results['ScoreT1']\ntourney_lose_result","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Training Data**"},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Win_Results['Seed_diff'] = Tourney_Win_Results['Seed1'] - Tourney_Win_Results['Seed2']\nTourney_Win_Results['ScoreT_diff'] = Tourney_Win_Results['ScoreT1'] - Tourney_Win_Results['ScoreT2']\n#Tourney_Win_Results['Score_diff'] = Tourney_Win_Results['Score1'] - Tourney_Win_Results['Score2']\ntourney_lose_result['Seed_diff'] = tourney_lose_result['Seed1'] - tourney_lose_result['Seed2']\ntourney_lose_result['ScoreT_diff'] = tourney_lose_result['ScoreT1'] - tourney_lose_result['ScoreT2']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Win_Results['result'] = 1\ntourney_lose_result['result'] = 0\ntourney_result_Final = pd.concat((Tourney_Win_Results, tourney_lose_result)).reset_index(drop=True)\n\ntourney_result_Final.to_csv('Tourneyvalidate.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tourney_result_Final.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tourney_result_Final1 = tourney_result_Final[[\n    'Seed1', 'Seed2', 'ScoreT1', 'ScoreT2', 'Seed_diff', 'ScoreT_diff', 'result']]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tourney_result_Final1.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Working on the results as per upset data as per link https://en.wikipedia.org/wiki/NCAA_Division_I_Men%27s_Basketball_Tournament_upsets **"},{"metadata":{"trusted":true},"cell_type":"code","source":"tourney_result_Final1.loc[lambda x: (x['Seed1'].isin([14,15,16])) & (x['Seed2'].isin([1,2,3])),'result'\n        ] = 0\n\n\n\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Test Data**"},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df = pd.read_csv('../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MSampleSubmissionStage1_2020.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df['Season'] = test_df['ID'].map(lambda x: int(x[:4]))\ntest_df['WTeamID'] = test_df['ID'].map(lambda x: int(x[5:9]))\ntest_df['LTeamID'] = test_df['ID'].map(lambda x: int(x[10:14]))\ntest_df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Tourney_Seeds.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Tourney_Results_Compact1=Tourney_Results_Compact.drop(['DayNum','WinningSeed','LoosingSeed','WScoreTotal','LScoreTotal'],axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Tourney_Results_Compact1.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Tourney_Seeds= pd.merge(Tourney_Results_Compact1, Tourney_Seeds, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Tourney_Seeds=Tourney_Seeds.drop(['WTeamID','LTeamID'],axis=1)\n#Tourney_Seeds.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df = pd.merge(test_df, Tourney_Seeds, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')\ntest_df.rename(columns={'Seed':'Seed1'}, inplace=True)\ntest_df = test_df.drop('TeamID', axis=1)\ntest_df = pd.merge(test_df, Tourney_Seeds, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')\ntest_df.rename(columns={'Seed':'Seed2'}, inplace=True)\ntest_df = test_df.drop('TeamID', axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df = pd.merge(test_df, RegularSeason_Compact_Results_Final, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')\ntest_df.rename(columns={'Score':'ScoreT1'}, inplace=True)\ntest_df = test_df.drop('TeamID', axis=1)\ntest_df = pd.merge(test_df, RegularSeason_Compact_Results_Final, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')\ntest_df.rename(columns={'Score':'ScoreT2'}, inplace=True)\ntest_df = test_df.drop('TeamID', axis=1)\ntest_df\ntest_df.to_csv('test_df_Test.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df['Seed1'] = test_df['Seed1'].str.extract('(\\d+)', expand=True)\ntest_df['Seed2'] = test_df['Seed2'].str.extract('(\\d+)', expand=True)\ntest_df.Seed1 = pd.to_numeric(test_df.Seed1, errors='coerce')\ntest_df.Seed2 = pd.to_numeric(test_df.Seed2, errors='coerce')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_df['Seed_diff'] = test_df['Seed1'] - test_df['Seed2']\ntest_df['ScoreT_diff'] = test_df['ScoreT1'] - test_df['ScoreT2']\ntest_df = test_df.drop(['ID', 'Pred', 'Season', 'WTeamID', 'LTeamID'], axis=1)\ntest_df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tourney_result_Final1.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Applying Logistic regression**"},{"metadata":{"trusted":true},"cell_type":"code","source":"X = tourney_result_Final1.drop('result', axis=1)\ny = tourney_result_Final1.result","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Standardization for regression models\ndf = pd.concat([X, test_df], axis=0, sort=False).reset_index(drop=True)\ndf_log = pd.DataFrame(\n    preprocessing.MinMaxScaler().fit_transform(df),\n    columns=df.columns,\n    index=df.index\n)\ntrain_log, test_log = df_log.iloc[:len(X),:], df_log.iloc[len(X):,:].reset_index(drop=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"logreg = LogisticRegression()\nlogreg.fit(train_log, y)\ncoeff_logreg = pd.DataFrame(train_log.columns.delete(0))\ncoeff_logreg.columns = ['feature']\ncoeff_logreg[\"score_logreg\"] = pd.Series(logreg.coef_[0])\ncoeff_logreg.sort_values(by='score_logreg', ascending=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"y_logreg_train = logreg.predict(train_log)\ny_logreg_pred = logreg.predict_proba(test_log)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n#clf = RandomForestClassifier(n_estimators=250,max_depth=50)\nclf = RandomForestClassifier(n_estimators=200,max_depth=90,min_samples_leaf=300,min_samples_split=200,max_features=5)\n#We can get accuracy of 0.7145738779626828 using {'max_depth': 30, 'max_features': 5, 'min_samples_leaf': 300, 'min_samples_split': 300, 'n_estimators': 200}\n#clf.fit(X, y)\nclf.fit(train_log, y)\nclf_probs = clf.predict_proba(test_log)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"y_pred_df_random = pd.DataFrame(clf_probs)\ny_pred_1 = y_pred_df_random.iloc[:,[1]]\n#y_pred_1.head()\ny_pred_df_random","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.model_selection import KFold\nfrom sklearn.model_selection import GridSearchCV","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#n_folds=5\n# Create the parameter grid based on the results of random search \n#param_grid = {\n#    'max_depth': [30,60,90,120,150],\n#    'min_samples_leaf': (50,100, 200, 300,400),\n#    'min_samples_split': (25,50,100, 200, 300),\n#    'n_estimators': [100,200, 300,400], \n#    'max_features': [5, 10,15]\n#}\n# Create a based model\n#rf = RandomForestClassifier()\n# Instantiate the grid search model\n#grid_search = GridSearchCV(estimator = rf, param_grid = param_grid, \n                          #cv = 3, n_jobs = -1,verbose = 1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#grid_search.fit(train_log, y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#print('We can get accuracy of',grid_search.best_score_,'using',grid_search.best_params_)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df = pd.read_csv('../input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MSampleSubmissionStage1_2020.csv')\nsubmission_df['Pred'] = y_pred_1\nsubmission_df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df.to_csv('submission_New6.csv', index=False)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}