Kaggle competition: Statoil/C-CORE Iceberg Classifier Challenge
df = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2020/train.csv', low_memory=False)
 feats_player = ['Team', 'X', 'Y', 'S', 'A', 'Dis', 'Orientation', 'Dir',
'NflId', 'DisplayName', 'JerseyNumber', 'PlayerHeight', 'PlayerWeight',
'PlayerBirthDate', 'PlayerCollegeName', 'Position']
for id_ in ['PlayId', 'GameId']:
df_ = df.drop(columns=feats_player)
 groups = df_.groupby(id_)
 s = groups.agg(lambda s: len(s.unique())).apply(max)
 print('---------- ' + id_ + ' 内共通 ----------')
 for index, value in s.iteritems() :
if value == 1:
print(index )<prepare_output>
train = pd.read_json(".. /input/train.json")
 test = pd.read_json(".. /input/test.json" )
prediction_df = pd.DataFrame()
for y in range(-99, 100):
prediction_df['Yards' + str(y)] = [0.0]
loss = []
for i in range(len(df_play_2018)) :
target_df_ = df_play_2018.iloc[[i],:]
prediction_df_ = prediction_df.copy()
make_my_predictions_0(target_df_, prediction_df_)
 actual_ = np.array([0.0] * 199)
 actual_[yard_to_index[target_df_['Yards'].iloc[0]]:] = 1.0
loss_ =(prediction_df_.iloc[0,:] - actual_)*(prediction_df_.iloc[0,:] - actual_)
 loss.append(loss_.mean())
 print(np.array(loss ).mean())
 loss = []
for i in range(len(df_play_2018)) :
target_df_ = df_play_2018.iloc[[i],:]
prediction_df_ = prediction_df.copy()
make_my_predictions_1(target_df_, prediction_df_)
 actual_ = np.array([0.0] * 199)
 actual_[yard_to_index[target_df_['Yards'].iloc[0]]:] = 1.0
loss_ =(prediction_df_.iloc[0,:] - actual_)*(prediction_df_.iloc[0,:] - actual_)
 loss.append(loss_.mean())
 print(np.array(loss ).mean() )<set_options>
X_band_1=np.array([np.array(band ).astype(np.float32 ).reshape(75, 75)for band in train["band_1"]])
 X_band_2=np.array([np.array(band ).astype(np.float32 ).reshape(75, 75)for band in train["band_2"]])
 X_train = np.concatenate([X_band_1[:, :, :, np.newaxis], X_band_2[:, :, :, np.newaxis],(( X_band_1+X_band_2)/2)[:, :, :, np.newaxis]], axis=-1)
 Y_train=train['is_iceberg']
sns.set_style('darkgrid')
 mpl.rcParams['figure.figsize'] = [15,10]<load_from_csv>
from matplotlib import pyplot
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dense, Dropout, Input, Flatten
from keras.layers import GlobalMaxPooling2D
from keras.layers.normalization import BatchNormalization
from keras.layers.merge import Concatenate
from keras.models import Model
from keras.optimizers import Adam
from keras.callbacks import ModelCheckpoint, Callback, EarlyStopping, ReduceLROnPlateau
train = pd.read_csv('.. /input/nfl-big-data-bowl-2020/train.csv', dtype={'WindSpeed': 'object'} )<count_values>
def getModel() :
model=Sequential()
model.add(Conv2D(8, kernel_size=(3, 3),activation='relu', input_shape=(75, 75, 3)))
 model.add(MaxPooling2D(pool_size=(3, 3), strides=(2, 2)))
 model.add(Dropout(0.2))
model.add(Conv2D(16, kernel_size=(3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
 model.add(Dropout(0.2))
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
 model.add(Dropout(0.3))
model.add(Conv2D(64, kernel_size=(3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
 model.add(Dropout(0.3))
model.add(Flatten())
 model.add(Dense(512, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(1, activation="sigmoid"))
optimizer = Adam(lr=0.001)
 model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
 return model
model = getModel()
model.summary()
train['PlayId'].value_counts()<count_values>
batch_size = 32
earlyStopping = EarlyStopping(monitor='val_loss', patience=10, verbose=0, mode='min')
 mcp_save = ModelCheckpoint('.mdl_wts.hdf5', save_best_only=True, monitor='val_loss', mode='min')
 reduce_lr_loss = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=7, verbose=1, epsilon=1e-4, mode='min' )
off_form = train['OffenseFormation'].unique()
train['OffenseFormation'].value_counts()<categorify>
X_train_cv, X_valid, y_train_cv, y_valid = train_test_split(X_train, Y_train, random_state=1, train_size=0.75)
 model=getModel()
model.fit(X_train_cv, y_train_cv, batch_size=batch_size, epochs=100, verbose=1, validation_data=(X_valid, y_valid), callbacks=[earlyStopping, mcp_save, reduce_lr_loss], validation_split=0.25 )
train = pd.concat([train.drop(['OffenseFormation'], axis=1), pd.get_dummies(train['OffenseFormation'], prefix='Formation')], axis=1)
 dummy_col = train.columns<count_values>
model.load_weights(filepath = '.mdl_wts.hdf5')
 score = model.evaluate(X_train, Y_train, verbose=1)
 print('Train score:', score[0])
 print('Train accuracy:', score[1] )
train['GameClock'].value_counts()<feature_engineering>
X_band_test_1=np.array([np.array(band ).astype(np.float32 ).reshape(75, 75)for band in test["band_1"]])
 X_band_test_2=np.array([np.array(band ).astype(np.float32 ).reshape(75, 75)for band in test["band_2"]])
 X_test = np.concatenate([X_band_test_1[:, :, :, np.newaxis]
, X_band_test_2[:, :, :, np.newaxis]
,(( X_band_test_1+X_band_test_2)/2)[:, :, :, np.newaxis]], axis=-1)
 pred_test = model.predict(X_test )
train['GameClock'] = train['GameClock'].apply(strtoseconds )<feature_engineering>
submission = pd.DataFrame({'id': test["id"], 'is_iceberg': pred_test.reshape(( pred_test.shape[0])) })
 submission.head(10 )
<data_type_conversions><EOS> 
submission.to_csv("./submission.csv", index=False )