Kaggle competition: Google Cloud & NCAA® ML Competition 2020-NCAAM
<SOS> metric: logloss Kaggle data source: google-cloud-ncaa-march-madness-2020-division-1-mens-tournament<compute_test_metric>
py.init_notebook_mode(connected=True)
 pd.set_option('max_columns', 50 )
print("Accuracy Score of KNN Model:")
 print(metrics.accuracy_score(y_test,KNN_predict))
print("
","Classification Report:")
 print(metrics.classification_report(y_test,KNN_predict),'
' )<train_model>
datadir = Path('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament')
 stage1dir = datadir/'MDataFiles_Stage1'
gbk = GradientBoostingClassifier(random_state=101, n_estimators=150,min_samples_split=100, max_depth=6)
 gbk.fit(X_train, y_train )<predict_on_test>
teams_df = pd.read_csv(stage1dir/'MTeams.csv')
 print('teams_df', teams_df.shape)
 teams_df.head()
gbk_predict = gbk.predict(X_test)
 gbk_score = gbk.score(X_test,y_test)
 print("Gradient Boosting Score :",gbk_score )<compute_test_metric>
seasons_df = pd.read_csv(stage1dir/'MSeasons.csv' )
print("Accuracy Score of Gradient Boosting Model:")
 print(metrics.accuracy_score(y_test,gbk_predict))<import_modules>
tourney_seeds_df = pd.read_csv(stage1dir/'MNCAATourneySeeds.csv')
 tourney_seeds_df
from sklearn import ensemble
from sklearn.model_selection import GridSearchCV<choose_model_class>
regular_season_results_df = pd.read_csv(stage1dir/'MRegularSeasonCompactResults.csv')
 tournament_results_df = pd.read_csv(stage1dir/'MNCAATourneyCompactResults.csv' )
GridList =[ {'n_estimators' : [10, 15, 20, 25, 30, 35, 40], 'max_depth' : [5,10,15, 20]},]
randomForest_ensemble = ensemble.RandomForestClassifier(random_state=31, max_features= 3)
 gridSearchCV = GridSearchCV(randomForest_ensemble,GridList, cv = 5 )<train_on_grid>
sample_submission = pd.read_csv(datadir/'MSampleSubmissionStage1_2020.csv')
 sample_submission
gridSearchCV.fit(X_train,y_train )<compute_train_metric>
regular_season_detailed_results_df = pd.read_csv(stage1dir/'MRegularSeasonDetailedResults.csv')
 tournament_detailed_results_df = pd.read_csv(stage1dir/'MNCAATourneyDetailedResults.csv' )
gridSearchCV_predict = gridSearchCV.predict(X_test)
 gridSearchCV_score = gridSearchCV.score(X_test,y_test)
 print("Grid SearchCV Score :",gridSearchCV_score )<import_modules>
cities_df = pd.read_csv(stage1dir/'Cities.csv')
 mgame_cities_df = pd.read_csv(stage1dir/'MGameCities.csv' )
from tabulate import tabulate<predict_on_test>
massey_df = pd.read_csv(stage1dir/'MMasseyOrdinals.csv')
 massey_df
ids = test_data['PassengerId']
print(len(ids))
predictions = gridSearchCV.predict(test_data )<save_to_csv>
event2015_df = pd.read_csv(datadir/'MEvents2015.csv')
output = pd.DataFrame({ 'PassengerId' : ids, 'Survived': predictions } )<save_to_csv>
players_df = pd.read_csv(datadir/'MPlayers.csv')
 players_df
output.to_csv('submission.csv', index=False )<import_modules>
team_coaches_df = pd.read_csv(stage1dir/'MTeamCoaches.csv')
 print('team_coaches_df', team_coaches_df.shape)
 team_coaches_df.iloc[80:85]
import numpy as np
import pandas as pd<load_from_csv>
conferences_df = pd.read_csv(stage1dir/'Conferences.csv')
 team_conferences_df = pd.read_csv(stage1dir/'MTeamConferences.csv' )
test = pd.read_csv("/kaggle/input/mldl-competition-1/test.csv")
 train = pd.read_csv("/kaggle/input/mldl-competition-1/train.csv")
 sampleSabmission = pd.read_csv("/kaggle/input/mldl-competition-1/sampleSubmission.csv" )<import_modules>
team_conferences_df[team_conferences_df['TeamID'] == 1102]
print(tf.__version__)
<prepare_x_and_y>
conference_tourney_games_df = pd.read_csv(stage1dir/'MConferenceTourneyGames.csv')
 conference_tourney_games_df
column_names = ['Id' 'X','Y','Z','Time']
X_train_orig = train[["X", "Y", "Z"]]
X_test_orig = test[["X", "Y", "Z"]]
Y_train_orig = train["Time"]
print(X_train_orig.shape)
 print(X_test_orig.shape)
 print(Y_train_orig.shape)
<train_model>
secondary_tourney_teams_df = pd.read_csv(stage1dir/'MSecondaryTourneyTeams.csv')
 secondary_tourney_teams_df
scaler = MinMaxScaler(feature_range=(-1, 1), copy=True)
 scaler.fit(X_train_orig)
 print("Maximum values of X_train(X, Y, Z): " + str(scaler.data_max_))
print("Minimum values of X_train(X, Y, Z): " + str(scaler.data_min_))
X_train_norm = scaler.transform(X_train_orig)
 X_test_norm = scaler.transform(X_test_orig)
<split>
secondary_tourney_results_df = pd.read_csv(stage1dir/'MSecondaryTourneyCompactResults.csv')
 secondary_tourney_results_df
X_train, X_val, y_train, y_val = train_test_split(X_train_norm, Y_train_orig, test_size=0.2)
 print(X_train.shape)
 print(y_train.shape)
 print(X_val.shape)
 print(y_val.shape )<choose_model_class>
model = keras.Sequential([
keras.layers.Dense(128, input_dim=3, activation='relu'),
keras.layers.Dense(6, activation='relu'),
keras.layers.Dense(1, activation="linear")
 ])
 print(model.summary())
<choose_model_class>
tourney_slots_df = pd.read_csv(stage1dir/'MNCAATourneySlots.csv')
 tourney_seed_round_slots_df = pd.read_csv(stage1dir/'MNCAATourneySeedRoundSlots.csv' )
model.compile(optimizer='adam',
loss='MSE',
metrics=['accuracy'] )<train_model>
tourney_slots_df[(tourney_slots_df['Season'] == 1985)&(tourney_slots_df['Slot'].str.startswith('R1W')) ]
history = model.fit(X_train, y_train, validation_data=(X_val, y_val), epochs=5 )<compute_test_metric>
tournament_results2015_df = tournament_results_df.query("Season >= 2015")
 tournament_results2015_df
test_loss, test_acc = model.evaluate(X_val, y_val, verbose=0)
 print('
Test loss:', test_loss)
 print('
Test accuracy:', test_acc )<predict_on_test>
for key, row in tournament_results2015_df.iterrows() :
if row['WTeamID'] < row['LTeamID']:
id_name = str(row['Season'])+ '_' + str(row['WTeamID'])+ '_' + str(row['LTeamID'])
 sample_submission.loc[sample_submission['ID'] == id_name, 'Pred'] = 1.0
else:
id_name = str(row['Season'])+ '_' + str(row['LTeamID'])+ '_' + str(row['WTeamID'])
 sample_submission.loc[sample_submission['ID'] == id_name, 'Pred'] = 0.0
<save_to_csv><EOS> 
sample_submission.to_csv('submission.csv', index=False )