Kaggle competition: CareerCon 2019 - Help Navigate Robots
model = build_model(bert_layer, max_len=128)
 model.summary()<init_hyperparams>
X_train = pd.read_csv('.. /input/X_train.csv')
 Y_train=pd.read_csv('.. /input/y_train.csv')
 X_train.head()
callbacks2 = [
ModelCheckpoint('model_bert.h5', monitor='val_loss', save_best_only=True)
 ]<train_model>
columns=['orientation_X','orientation_Y','orientation_Z','orientation_W','angular_velocity_X','angular_velocity_Y','angular_velocity_Z','linear_acceleration_X','linear_acceleration_Y','linear_acceleration_Z']
def feature_data(X):
data_train=pd.DataFrame()
for col in columns:
data_train[col+'_mean'] = X.groupby(['series_id'])[col].mean()
data_train[col+'_median'] = X.groupby(['series_id'])[col].median()
data_train[col+'_max'] = X.groupby(['series_id'])[col].max()
data_train[col+'_min'] = X.groupby(['series_id'])[col].min()
data_train[col+'_std'] = X.groupby(['series_id'])[col].std()
data_train[col+'_var'] = X.groupby(['series_id'])[col].var()
data_train[col + '_range'] = data_train[col + '_max'] - data_train[col + '_min']
data_train[col + '_maxtoMin'] = data_train[col + '_max'] / data_train[col + '_min']
data_train[col + '_mean_abs_chg'] = X.groupby(['series_id'])[col].apply(lambda x: np.mean(np.abs(np.diff(x))))
data_train[col + '_abs_median_chg'] = X.groupby(['series_id'])[col].apply(lambda x: np.median(np.abs(np.diff(x))))
data_train[col + '_abs_std_chg'] = X.groupby(['series_id'])[col].apply(lambda x: np.std(np.abs(x)))
 data_train[col + '_abs_max'] = X.groupby(['series_id'])[col].apply(lambda x: np.max(np.abs(x)))
 data_train[col + '_abs_min'] = X.groupby(['series_id'])[col].apply(lambda x: np.min(np.abs(x)))
 data_train[col + '_abs_avg'] =(data_train[col + '_abs_min'] + data_train[col + '_abs_max'])/2
return data_train
data_train=feature_data(X_train)
 data_train.head()
data_train, data_valid, Y_train, y_valid = train_test_split(data_train, Y_train, test_size=0.3)
model.fit(train_input, train_labels, validation_split=0.075, epochs=3,
callbacks=callbacks2, batch_size=32 )<save_to_csv>
model = LogisticRegression(solver = 'lbfgs',max_iter=500,multi_class='multinomial')
 model.fit(data_train,Y_train['surface'] )
sample_submission=pd.read_csv('/kaggle/input/nlp-getting-started/sample_submission.csv')
 y_pre2=model.predict(test_input)
 y_pre2=np.round(y_pre2 ).astype(int ).reshape(3263)
 sub2=pd.DataFrame({'id':sample_submission['id'].values.tolist() ,'target':y_pre2})
 sub2.to_csv('tweet5b.csv',index=False )<feature_engineering>
Y_pred_train=model.predict(data_train)
 accuracy = metrics.accuracy_score(Y_train['surface'], Y_pred_train)
 print('Accuracy training: {:.2f}'.format(accuracy))
Y_pred_valid=model.predict(data_valid)
 accuracy = metrics.accuracy_score(y_valid['surface'], Y_pred_valid)
 print('Accuracy validation: {:.2f}'.format(accuracy))
TRAIN_ABLE_FALSE=True
if TRAIN_ABLE_FALSE:
os.environ['CUDA_VISIBLE_DEVICES'] = "1"
TRAIN_OFFLINE = False
pd.set_option('display.max_columns', 50)
 pd.set_option('display.max_rows', 150 )<import_modules>
nn_model = MLPClassifier(hidden_layer_sizes=(200, 100,50,), activation='tanh', solver='adam', alpha=0.01,learning_rate_init=0.001, max_iter=800)
 nn_model.fit(data_train,Y_train['surface'])
 Y_pred_train=nn_model.predict(data_train)
 accuracy = metrics.accuracy_score(Y_train['surface'], Y_pred_train)
 print('Accuracy: {:.2f}'.format(accuracy))
Y_pred_valid=nn_model.predict(data_valid)
 accuracy = metrics.accuracy_score(y_valid['surface'], Y_pred_valid)
 print('Accuracy validation: {:.2f}'.format(accuracy))
warnings.filterwarnings('ignore')
 sns.set()
%matplotlib inline
TRAIN_OFFLINE = False
pd.set_option('display.max_columns', 50)
 pd.set_option('display.max_rows', 150 )<load_from_csv>
forest = RandomForestClassifier(n_estimators=600)
 forest.fit(data_train,Y_train['surface'])
 Y_pred_train=forest.predict(data_train)
 accuracy = metrics.accuracy_score(Y_train['surface'], Y_pred_train)
 print('Accuracy training: {:.2f}'.format(accuracy))
Y_pred_valid=forest.predict(data_valid)
 accuracy = metrics.accuracy_score(y_valid['surface'], Y_pred_valid)
 print('Accuracy validation: {:.2f}'.format(accuracy))
if TRAIN_OFFLINE:
train = pd.read_csv('.. /input/train.csv', dtype={'WindSpeed': 'object'})
 else:
train = pd.read_csv('/kaggle/input/nfl-big-data-bowl-2020/train.csv', dtype={'WindSpeed': 'object'})
<remove_duplicates>
X_test=pd.read_csv('.. /input/X_test.csv')
 data_test=feature_data(X_test)
 Y_pred_test=forest.predict(data_test)
 result = pd.DataFrame()
result['series_id'] = data_test.index.values
result['surface'] = Y_pred_test
result.head()
result.to_csv('submission.csv',sep=',',index=False )