Kaggle competition: Google Cloud & NCAA® ML Competition 2020-NCAAM
embarked1 = pd.get_dummies(test['Embarked'], drop_first = True)
 pcl1 = pd.get_dummies(test['Pclass'], drop_first = True )<concatenate>
import pandas as pd
import numpy as np
from sklearn.linear_model import LogisticRegression
import matplotlib.pyplot as plt
from sklearn.utils import shuffle
from sklearn.model_selection import GridSearchCV
test = pd.concat([test,embarked1,pcl1,sex1], axis = 1 )<drop_column>
tourney_result = pd.read_csv('.. /input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1/MNCAATourneyCompactResults.csv')
 tourney_seed = pd.read_csv('.. /input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1/MNCAATourneySeeds.csv' )
test.drop(['Sex', 'Embarked', 'Name', 'Ticket','Pclass','Cabin'], axis=1,inplace=True )<correct_missing_values>
tourney_result = tourney_result.drop(['DayNum', 'WScore', 'LScore', 'WLoc', 'NumOT'], axis=1)
 tourney_result
test.fillna(test.mean() , inplace=True )<predict_on_test>
tourney_result = pd.merge(tourney_result, tourney_seed, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')
 tourney_result.rename(columns={'Seed':'WSeed'}, inplace=True)
 tourney_result = tourney_result.drop('TeamID', axis=1)
 tourney_result = pd.merge(tourney_result, tourney_seed, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')
 tourney_result.rename(columns={'Seed':'LSeed'}, inplace=True)
 tourney_result = tourney_result.drop('TeamID', axis=1)
 tourney_result
ids = test['PassengerId']
predictions = clf.predict(test.drop('PassengerId', axis=1)) 
<save_to_csv>
def get_seed(x):
return int(x[1:3])
 tourney_result['WSeed'] = tourney_result['WSeed'].map(lambda x: get_seed(x))
tourney_result['LSeed'] = tourney_result['LSeed'].map(lambda x: get_seed(x))
tourney_result
output = pd.DataFrame({ 'PassengerId' : ids, 'Survived': predictions })
 output.to_csv('submission.csv', index=False )<import_modules>
season_result = pd.read_csv('.. /input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MDataFiles_Stage1/MRegularSeasonCompactResults.csv' )
tf.__version__<import_modules>
season_win_result = season_result[['Season', 'WTeamID', 'WScore']]
season_lose_result = season_result[['Season', 'LTeamID', 'LScore']]
season_win_result.rename(columns={'WTeamID':'TeamID', 'WScore':'Score'}, inplace=True)
 season_lose_result.rename(columns={'LTeamID':'TeamID', 'LScore':'Score'}, inplace=True)
 season_result = pd.concat(( season_win_result, season_lose_result)).reset_index(drop=True)
 season_result
from tensorflow.keras import layers
import tensorflow.keras.backend as K
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from tensorflow.keras.layers import Conv2D, Dense, Flatten, MaxPool2D, Dropout, Reshape, Input
from tensorflow.keras.losses import CategoricalCrossentropy
from tensorflow.keras.optimizers import Adam, Adadelta, Adagrad, Adamax, Nadam, RMSprop, Ftrl<set_options>
season_score = season_result.groupby(['Season', 'TeamID'])['Score'].sum().reset_index()
season_score
device = torch.device("cuda" )<load_from_csv>
tourney_result = pd.merge(tourney_result, season_score, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')
 tourney_result.rename(columns={'Score':'WScoreT'}, inplace=True)
 tourney_result = tourney_result.drop('TeamID', axis=1)
 tourney_result = pd.merge(tourney_result, season_score, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')
 tourney_result.rename(columns={'Score':'LScoreT'}, inplace=True)
 tourney_result = tourney_result.drop('TeamID', axis=1)
 tourney_result
df_train = pd.read_csv(".. /input/digit-recognizer/train.csv")
 df_test = pd.read_csv(".. /input/digit-recognizer/test.csv")
 df_sub = pd.read_csv(".. /input/digit-recognizer/sample_submission.csv")
 df_Id = df_sub["ImageId"]<prepare_x_and_y>
tourney_win_result = tourney_result.drop(['Season', 'WTeamID', 'LTeamID'], axis=1)
 tourney_win_result.rename(columns={'WSeed':'Seed1', 'LSeed':'Seed2', 'WScoreT':'ScoreT1', 'LScoreT':'ScoreT2'}, inplace=True)
 tourney_win_result
X = df_train.drop("label", axis=1 ).values
y = df_train["label"].values
X_test = df_test.values
X = X / 255
X_test = X_test / 255
X = X.reshape(( -1, 1, 28, 28))
X_test = X_test.reshape(( -1, 1, 28, 28))<split>
tourney_lose_result = tourney_win_result.copy()
tourney_lose_result['Seed1'] = tourney_win_result['Seed2']
tourney_lose_result['Seed2'] = tourney_win_result['Seed1']
tourney_lose_result['ScoreT1'] = tourney_win_result['ScoreT2']
tourney_lose_result['ScoreT2'] = tourney_win_result['ScoreT1']
tourney_lose_result
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.1, random_state=123 )<prepare_x_and_y>
tourney_win_result['Seed_diff'] = tourney_win_result['Seed1'] - tourney_win_result['Seed2']
tourney_win_result['ScoreT_diff'] = tourney_win_result['ScoreT1'] - tourney_win_result['ScoreT2']
tourney_lose_result['Seed_diff'] = tourney_lose_result['Seed1'] - tourney_lose_result['Seed2']
tourney_lose_result['ScoreT_diff'] = tourney_lose_result['ScoreT1'] - tourney_lose_result['ScoreT2']
t_X_train = torch.from_numpy(X_train ).float()
t_y_train = torch.from_numpy(y_train ).long()
t_X_val = torch.from_numpy(X_val ).float()
t_y_val = torch.from_numpy(y_val ).long()
dataset_train = TensorDataset(t_X_train, t_y_train)
 dataset_val = TensorDataset(t_X_val, t_y_val)
 loader_train = DataLoader(dataset_train, batch_size=20, shuffle=True)
 loader_val = DataLoader(dataset_val, batch_size=20 )<choose_model_class>
tourney_win_result['result'] = 1
tourney_lose_result['result'] = 0
tourney_result = pd.concat(( tourney_win_result, tourney_lose_result)).reset_index(drop=True)
 tourney_result
activation_relu = torch.nn.ReLU()
class cnn(nn.Module):
def __init__(self):
super(cnn, self ).__init__()
self.conv1 = nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, padding=1)
 self.conv2 = nn.Conv2d(32, 32, 3, padding=1)
 self.conv3 = nn.Conv2d(32, 32, 3, padding=1)
 self.conv4 = nn.Conv2d(32, 32, 3, padding=1)
 self.maxpool1 = nn.MaxPool2d(kernel_size=2, stride=2)
 self.conv5 = nn.Conv2d(32, 64, 3, padding=1)
 self.conv6 = nn.Conv2d(64, 64, 3, padding=1)
 self.conv7 = nn.Conv2d(64, 64, 3, padding=1)
 self.conv8 = nn.Conv2d(64, 64, 3, padding=1)
 self.maxpool2 = nn.MaxPool2d(kernel_size=2, stride=2)
 self.flatten = nn.Flatten()
self.drop1 = nn.Dropout(p=0.5)
 self.fc1 = nn.Linear(7*7*64, 1024)
 self.drop2 = nn.Dropout(p=0.5)
 self.fc2 = nn.Linear(1024, 10)
 def forward(self, x):
x = activation_relu(self.conv1(x))
x = activation_relu(self.conv2(x))
x = activation_relu(self.conv3(x))
x = activation_relu(self.conv4(x))
x = activation_relu(self.maxpool1(x))
x = activation_relu(self.conv5(x))
x = activation_relu(self.conv6(x))
x = activation_relu(self.conv7(x))
x = activation_relu(self.conv8(x))
x = activation_relu(self.maxpool2(x))
x = self.flatten(x)
 x = self.drop1(x)
 x = activation_relu(self.fc1(x))
x = self.drop2(x)
 x = self.fc2(x)
 return x
cnn = cnn()<set_options>
X_train=tourney_result.drop('result',axis=1)
 y_train=tourney_result.result
device = torch.device("cuda")
 cnn.to(device )<choose_model_class>
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.utils import to_categorical, normalize
from sklearn.utils import shuffle
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(cnn.parameters() , lr=0.0002 )<train_on_grid>
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(128, input_shape=(6,), activation='relu'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(125, activation='relu'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(1, activation='sigmoid')
 ] )
train_history = []
val_history = []
for epoch in range(10):
total_train_loss = 0
total_val_loss = 0
total_train_acc = 0
total_val_acc = 0
total_train = 0
total_val = 0
for inputs, labels in loader_train:
inputs, labels = inputs.to(device), labels.to(device)
 cnn.train()
optimizer.zero_grad()
outputs = cnn(inputs)
 loss = criterion(outputs, labels)
 loss.backward()
optimizer.step()
total_train_loss += loss
with torch.no_grad() :
y_pred = torch.argmax(cnn(inputs), dim=1)
 acc_train = int(( y_pred==labels ).sum())
 total_train_acc += acc_train
total_train += len(labels)
 for inputs, labels in loader_val:
inputs, labels = inputs.to(device), labels.to(device)
 cnn.eval()
outputs = cnn(inputs)
 loss = criterion(outputs, labels)
 total_val_loss += loss
with torch.no_grad() :
y_pred = torch.argmax(cnn(inputs), dim=1)
 total_acc_val = int(( y_pred==labels ).sum())
 total_val += len(labels)
 avg_train_acc = total_train_acc / total_train
avg_val_acc = total_acc_val / total_val
train_history.append([total_train_loss, total_train_acc])
 val_history.append([total_val_loss, total_val_acc])
 print(f"Epoch {epoch+1} ---> train_loss: {total_train_loss:.5f} | val_loss: {total_val_loss:.5f} || "\
f"train_acc {avg_train_acc:.5f} | val_acc {avg_val_acc:.5f}" )<prepare_x_and_y>
model.compile(loss='binary_crossentropy',
optimizer=Adam(0.0001),
metrics=['acc'] )
x = torch.tensor([[1, 2, 3, 4, 5],
[2, 2, 2, 2, 2]])
 y = torch.tensor([1, 3, 4, 4, 5])
 type(len(x))<choose_model_class>
history = model.fit(X_train, y_train,epochs=150,verbose=1 )
cnn1 = tf.keras.models.Sequential([Conv2D(input_shape=(28, 28, 1), filters=16, kernel_size=(3, 3), activation="relu", padding="same"),
Conv2D(filters=16, kernel_size=(3, 3), activation="relu", padding="same"),
Conv2D(filters=16, kernel_size=(3, 3), activation="relu", padding="same"),
Conv2D(filters=16, kernel_size=(3, 3), activation="relu", padding="same"),
MaxPool2D(pool_size=(2, 2), strides=(2, 2)) ,
Conv2D(filters=32, kernel_size=(3, 3), activation="relu", padding="same"),
Conv2D(filters=32, kernel_size=(3, 3), activation="relu", padding="same"),
Conv2D(filters=32, kernel_size=(3, 3), activation="relu", padding="same"),
Conv2D(filters=32, kernel_size=(3, 3), activation="relu", padding="same"),
MaxPool2D(pool_size=(2, 2), strides=(2, 2)) ,
Flatten() ,
Dense(units=1024, activation="relu"),
Dropout(rate=0.5),
Dense(units=10, activation="softmax")] )<train_model>
test_df = pd.read_csv('.. /input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MSampleSubmissionStage1_2020.csv' )
def seq_train_val(X, y, model, optimizer=Adam, validation_data=None, learning_rate=0.0001, loss="categorical_crossentropy", batch_size=10, epochs=40):
model.summary()
learning_rate_reduction = tf.keras.callbacks.ReduceLROnPlateau(monitor="val_loss", mode="min", patiencs=5, verbose=1, factor=0.5, min_lr=0.000001)
 model.compile(optimizer=optimizer(learning_rate=learning_rate), loss=loss, metrics=["acc"])
 model.fit(X_train, y_train, validation_data=validation_data, batch_size=batch_size, verbose=2, epochs=epochs, callbacks=[learning_rate_reduction])
 return None
def predict(X, model):
y_pred = model.predict(X)
 y_pred = np.argmax(y_pred, axis=1)
 return y_pred<train_model>
test_df['Season'] = test_df['ID'].map(lambda x: int(x[:4]))
test_df['WTeamID'] = test_df['ID'].map(lambda x: int(x[5:9]))
test_df['LTeamID'] = test_df['ID'].map(lambda x: int(x[10:14]))
test_df
seq_train_val(X=X_train_std, y=y_train, validation_data=(X_val_std, y_val), model=cnn1 )<compute_test_metric>
test_df = pd.merge(test_df, tourney_seed, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')
 test_df.rename(columns={'Seed':'Seed1'}, inplace=True)
 test_df = test_df.drop('TeamID', axis=1)
 test_df = pd.merge(test_df, tourney_seed, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')
 test_df.rename(columns={'Seed':'Seed2'}, inplace=True)
 test_df = test_df.drop('TeamID', axis=1)
 test_df = pd.merge(test_df, season_score, left_on=['Season', 'WTeamID'], right_on=['Season', 'TeamID'], how='left')
 test_df.rename(columns={'Score':'ScoreT1'}, inplace=True)
 test_df = test_df.drop('TeamID', axis=1)
 test_df = pd.merge(test_df, season_score, left_on=['Season', 'LTeamID'], right_on=['Season', 'TeamID'], how='left')
 test_df.rename(columns={'Score':'ScoreT2'}, inplace=True)
 test_df = test_df.drop('TeamID', axis=1)
 test_df
validation(X_val_std, y_val, model=cnn )<save_to_csv>
test_df['Seed1'] = test_df['Seed1'].map(lambda x: get_seed(x))
test_df['Seed2'] = test_df['Seed2'].map(lambda x: get_seed(x))
test_df['Seed_diff'] = test_df['Seed1'] - test_df['Seed2']
test_df['ScoreT_diff'] = test_df['ScoreT1'] - test_df['ScoreT2']
test_df = test_df.drop(['ID', 'Pred', 'Season', 'WTeamID', 'LTeamID'], axis=1)
 test_df
y_pred = predict(X_test_std, model=cnn)
 y_pred = pd.DataFrame(y_pred, columns=["Label"])
 sub = pd.concat([df_Id, y_pred], axis=1)
 sub.to_csv("submission.csv", index=False )<choose_model_class>
from sklearn.linear_model import LogisticRegression
import matplotlib.pyplot as plt
from sklearn.utils import shuffle
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import KFold
import lightgbm as lgb
import xgboost as xgb
from xgboost import XGBClassifier
import gc
ac_relu = layers.Activation("relu")
 ac_softmax = layers.Activation("softmax")
 class cnn2(tf.keras.Model):
def __init__(self, *args, **kwargs):
super(cnn2, self ).__init__(*args, **kwargs)
 self.conv1 = Conv2D(filters=8, kernel_size=(3, 3), padding="same")
 self.conv2 = Conv2D(filters=8, kernel_size=(3, 3), padding="same")
 self.conv3 = Conv2D(filters=8, kernel_size=(3, 3), padding="same")
 self.maxpool1 = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding="same")
 self.conv4 = Conv2D(filters=16, kernel_size=(3, 3), padding="same")
 self.conv5 = Conv2D(filters=16, kernel_size=(3, 3), padding="same")
 self.conv6 = Conv2D(filters=16, kernel_size=(3, 3), padding="same")
 self.maxpool2 = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding="same")
 self.conv7 = Conv2D(filters=32, kernel_size=(3, 3), padding="same")
 self.conv8 = Conv2D(filters=32, kernel_size=(3, 3), padding="same")
 self.conv9 = Conv2D(filters=32, kernel_size=(3, 3), padding="same")
 self.conv10 = Conv2D(filters=32, kernel_size=(3, 3), padding="same")
 self.maxpool3 = MaxPool2D(pool_size=(2, 2), strides=(2, 2))
self.conv11 = Conv2D(filters=64, kernel_size=(3, 3), padding="same")
 self.conv12 = Conv2D(filters=64, kernel_size=(3, 3), padding="same")
 self.conv13 = Conv2D(filters=64, kernel_size=(3, 3), padding="same")
 self.conv14 = Conv2D(filters=64, kernel_size=(3, 3), padding="same")
 self.maxpool4 = MaxPool2D(pool_size=(2, 2), strides=(2, 2))
self.flatten = Flatten()
self.dense1 = Dense(units=1024)
 self.drop = Dropout(rate=0.5)
 self.dense2 = Dense(units=10)
 def call(self, inputs, training=None):
x2 = ac_relu(self.conv1(inputs))
x3 = ac_relu(self.conv2(x2))
x4 = ac_relu(self.conv3(x3))
x5 = ac_relu(self.maxpool1(x4))
x6 = ac_relu(self.conv4(x5))
x7 = ac_relu(self.conv5(x6))
x8 = ac_relu(self.conv6(x7))
x9 = ac_relu(self.maxpool2(x8))
x10 = ac_relu(self.conv7(x9))
x11 = ac_relu(self.conv8(x10))
x12 = ac_relu(self.conv9(x11))
x13 = ac_relu(self.conv10(x12))
x14 = ac_relu(self.maxpool3(x13))
x15 = ac_relu(self.conv11(x14))
x16 = ac_relu(self.conv12(x15))
x17 = ac_relu(self.conv13(x16))
x18 = ac_relu(self.conv14(x17))
x19 = ac_relu(self.maxpool4(x18))
x20 = self.flatten(x19)
 x21 = ac_relu(self.dense1(x20))
x22 = self.drop(x21)
 outputs = ac_softmax(self.dense2(x22))
return outputs
cnn2 = cnn2()<categorify>
params_lgb = {'num_leaves': 400,
'min_child_weight': 0.034,
'feature_fraction': 0.379,
'bagging_fraction': 0.418,
'min_data_in_leaf': 106,
'objective': 'binary',
'max_depth': 50,
'learning_rate': 0.0068,
"boosting_type": "gbdt",
"bagging_seed": 11,
"metric": 'logloss',
"verbosity": -1,
'reg_alpha': 0.3899,
'reg_lambda': 0.648,
'random_state': 47,
}
params_xgb = {'colsample_bytree': 0.8,
'learning_rate': 0.0004,
'max_depth': 31,
'subsample': 1,
'objective':'binary:logistic',
'eval_metric':'logloss',
'min_child_weight':3,
'gamma':0.25,
'n_estimators':5000
}
def sub_train_val(X_train, y_train, X_val, y_val, model, optimizer=Adam, learning_rate=0.0001, loss_object=CategoricalCrossentropy() ,
batch_size=20, y_label=10, epochs=5):
X_trainn = X_train.astype("float32")
 if y_label:
y_trainn = tf.one_hot(y_train, 10, dtype="float32")
 else:
y_trainn = y_train.astype("float32")
 train_sliced = tf.data.Dataset.from_tensor_slices(( X_trainn, y_trainn))
train_dataset = train_sliced.shuffle(100000 ).batch(batch_size)
 X_vall = X_val.astype("float32")
 if y_label:
y_vall = tf.one_hot(y_val, 10, dtype="float32")
 else:
y_vall = y_vall.astype("float32")
 val_sliced = tf.data.Dataset.from_tensor_slices(( X_vall, y_vall))
val_dataset = val_sliced.batch(batch_size)
 optimizer = optimizer(learning_rate=learning_rate)
 loss_object = loss_object
train_loss = tf.keras.metrics.Mean(name="train_loss")
 val_loss = tf.keras.metrics.Mean(name="val_loss")
 train_loss_list = []
val_loss_list = []
@tf.function
def train_step(X_train, y_train, model, optimizer, loss_object, train_loss):
training = True
K.set_learning_phase(training)
 with tf.GradientTape() as tape:
y_pred_tra = model(X_train, training=training)
 loss = loss_object(y_train, y_pred_tra)
 gradient = tape.gradient(loss, model.trainable_weights)
 optimizer.apply_gradients(zip(gradient, model.trainable_weights))
train_loss(loss)
 @tf.function
def val_step(X_val, y_val, model, optimizer, loss_object, val_loss):
training = False
y_pred_val = model(X_val, training=training)
 loss = loss_object(y_val, y_pred_val)
 val_loss(loss)
 for epoch in range(epochs):
print(f"Epoch is {str(epoch+1 ).zfill(3)} ----->", end=" ")
 for X, y in train_dataset:
train_step(X, y, model=model, optimizer=optimizer, loss_object=loss_object, train_loss=train_loss)
 print("train_loss: {:.6f}".format(float(train_loss.result())) , end=" | ")
 train_loss_list.append(float(train_loss.result()))
train_loss.reset_states()
for X, y in val_dataset:
val_step(X, y, model=model, optimizer=optimizer, loss_object=loss_object, val_loss=val_loss)
 print("val_loss: {:.6f}".format(float(val_loss.result())))
 val_loss_list.append(float(val_loss.result()))
val_loss.reset_states()
print()
print("-"*100)
 print()
print("Best val_loss is {:.6f}, and when the epoch is {}".format(min(val_loss_list), epoch+1))
fig = plt.figure(figsize=(10, 8))
plt.plot(range(1, epochs+1), train_loss_list, marker="o", c="b", label="train_loss")
 plt.plot(range(1, epochs+1), val_loss_list, marker="v", c="r", label="validation_loss")
 plt.legend()
plt.xlabel("epochs")
 plt.ylabel("loss")
 plt.title("train_and_validation_loss" )<train_model>
NFOLDS = 200
folds = KFold(n_splits=NFOLDS)
 columns = X_train.columns
splits = folds.split(X_train, y_train )
train_val(X_train=X_train_std, y_train=y_train, X_val=X_val_std, y_val=y_val, model=cnn2, learning_rate=0.0001, epochs=40, optimizer=Adam )<predict_on_test>
y_preds_lgb = np.zeros(test_df.shape[0])
 y_oof_lgb = np.zeros(X_train.shape[0] )
def validate(X, y, model):
X_tensor = tf.convert_to_tensor(X)
 y_pred = model(X_tensor)
 y_pred = y_pred.numpy()
y_pred = np.argmax(y_pred, axis=1)
 acc = accuracy_score(y, y_pred)
 return acc
def predict(X, model):
X_tensor = tf.convert_to_tensor(X)
 y_pred = model(X_tensor)
 y_pred = y_pred.numpy()
y_pred = np.argmax(y_pred, axis=1)
 return y_pred<compute_test_metric>
for fold_n,(train_index, valid_index)in enumerate(splits):
print('Fold:',fold_n+1)
 X_train1, X_valid1 = X_train[columns].iloc[train_index], X_train[columns].iloc[valid_index]
y_train1, y_valid1 = y_train.iloc[train_index], y_train.iloc[valid_index]
dtrain = lgb.Dataset(X_train1, label=y_train1)
 dvalid = lgb.Dataset(X_valid1, label=y_valid1)
 clf = lgb.train(params_lgb, dtrain, 10000, valid_sets = [dtrain, dvalid], verbose_eval=200)
 y_pred_valid = clf.predict(X_valid1)
 y_oof_lgb[valid_index] = y_pred_valid
y_preds_lgb += clf.predict(test_df)/ NFOLDS
del X_train1, X_valid1, y_train1, y_valid1
gc.collect()
validate(X_train_std, y_train, cnn2 )<categorify>
x = torch.empty(2, 3)
 print(x)
 x = torch.rand(2, 3)
 print(x)
 x = torch.zeros(2, 3, dtype=torch.float)
 print(x)
 x = torch.ones(2, 3, dtype=torch.int)
 print(x)
 x = torch.tensor([[0.0, 0.1, 0.2],
[1.0, 1.1, 1.2]])
 print(x)
 y = x.new_ones(1, 2)
 print(y)
 y = torch.ones_like(x, dtype=torch.int)
 print(y )<categorify>
submission_df = pd.read_csv('.. /input/google-cloud-ncaa-march-madness-2020-division-1-mens-tournament/MSampleSubmissionStage1_2020.csv')
 submission_df['Pred'] = y_preds_lgb
submission_df
b = x.numpy()
print('PyTorch計算→NumPy反映：')
 print(b); x.add_(y); print(b)
 print('NumPy計算→PyTorch反映：')
 print(x); np.add(b, b, out=b); print(x)
 c = np.ones(( 2, 3), dtype=np.float64)
 d = torch.from_numpy(c)
 print('NumPy計算→PyTorch反映：')
 print(d); np.add(c, c, out=c); print(d)
 print('PyTorch計算→NumPy反映：')
 print(c); d.add_(y); print(c )<set_options>
<define_variables><EOS> 
submission_df.to_csv('submission.csv', index=False )