Kaggle competition: Conway's Reverse Game of Life 2020
<SOS> metric: PostProcessorKernel Kaggle data source: conways-reverse-game-of-life-2020<split>
import numpy as np
import pandas as pd
import os
import tensorflow as tf
import matplotlib.pyplot as plt
X_train, X_test, y_train, y_test = train_test_split(train.drop(['Survived','PassengerId'], axis=1),
train['Survived'], test_size = 0.2,
random_state = 0 )<train_model>
train_df = pd.read_csv('/kaggle/input/conways-reverse-game-of-life-2020/train.csv')
 test_df = pd.read_csv("/kaggle/input/conways-reverse-game-of-life-2020/test.csv")
 sample_submission = pd.read_csv("/kaggle/input/conways-reverse-game-of-life-2020/sample_submission.csv" )
logisticRegression = LogisticRegression(max_iter = 30000)
 logisticRegression.fit(X_train, y_train)
<predict_on_test>
start_features = [f for f in train_df.columns if "start" in f]
stop_features = [f for f in train_df.columns if "stop" in f]
features_in = stop_features + ["delta"]
predictions = logisticRegression.predict(X_test)
 acc_LOG = round(accuracy_score(predictions, y_test)* 100, 2)
 print(acc_LOG)
 print(predictions)
<compute_test_metric>
delta_train, delta_validation, stop_train, stop_validation, Y_train, Y_valid = train_test_split(train_df["delta"].values,
train_df[stop_features].values.reshape(-1, 25, 25, 1 ).astype(float),
train_df[start_features].values.reshape(-1, 25, 25, 1 ).astype(float),
test_size=0.33,
)
print(confusion_matrix(y_test, predictions))<compute_test_metric>
X_train = [delta_train, stop_train]
X_valid = [delta_validation, stop_validation]
X_test = [test_df["delta"].values, test_df[stop_features].values.reshape(-1, 25, 25, 1 ).astype(float)]
X_all_train = [train_df["delta"].values, train_df[stop_features].values.reshape(-1, 25, 25, 1 ).astype(float)]
Y_all_train = train_df[start_features].values.reshape(-1, 25, 25, 1 ).astype(float )
accuracy=(( 88+50)/(88+50+22+19))
print('accuracy is: ',(round(accuracy, 2)*100))<train_model>
def conv_block(inputs, filters, index, activation='relu'):

 x = layers.Conv2D(filters, kernel_size=(3,3), padding="SAME", name=f'conv{index}' )(inputs)
 x = layers.BatchNormalization()(x)
 return layers.Activation(activation, name=activation + str(index))(x )
randomforest = RandomForestClassifier(random_state = 5, criterion = 'gini', max_depth = 10, max_features = 'auto', n_estimators = 500)
 randomforest.fit(X_train, y_train)
 pred = randomforest.predict(X_test)
 acc_randomforest = round(accuracy_score(pred, y_test)* 100, 2)
 print(acc_randomforest)
<train_model>
def create_model(dropout_prob=0.3):

 input_delta = layers.Input(shape=(1,), name="input_delta")
 dense_delta = layers.Dense(25*25, name='dense_delta' )(input_delta)
 dense_reshape = layers.Reshape(( 25,25,1), name='reshape_delta' )(dense_delta)
 input_image = layers.Input(shape=(25,25,1), name="input_images")
 all_inputs = layers.Concatenate(axis=3, name='concatenate' )([input_image, dense_reshape])
 x = conv_block(all_inputs, 32, index=1)
 x = layers.Dropout(dropout_prob )(x)
 x = conv_block(x, 128, index=2)
 x = layers.Dropout(dropout_prob )(x)
 x = conv_block(x, 256, index=3)
 x = layers.Dropout(dropout_prob )(x)
 x = conv_block(x, 64, index=4)
 x = layers.Dropout(dropout_prob )(x)
 out = conv_block(x, 1, index=5, activation='sigmoid')
 return Model(inputs=[input_delta, input_image], outputs=out )
gbk = GradientBoostingClassifier()
gbk.fit(X_train, y_train)
 pred = gbk.predict(X_test)
 acc_gbk = round(accuracy_score(pred, y_test)* 100, 2)
 print(acc_gbk )<create_dataframe>
model = create_model()
model.compile(loss="bce", optimizer=tf.keras.optimizers.Adam() , metrics=["accuracy"] )
see={'TECHNIQUE':['RANDOM FOREST','LOGISTIC REGRESSION','GRADIENT BOOSTING'],'ACCURACY':[acc_randomforest,acc_LOG,acc_gbk]}
mod=pd.DataFrame(see)
 mod<save_to_csv>
history = model.fit(x=X_train,
y=Y_train,
batch_size=128,
epochs=25,
validation_data=(X_valid, Y_valid))
ids = test['PassengerId']
predictions = randomforest.predict(test.drop('PassengerId', axis=1))
output = pd.DataFrame({ 'PassengerId' : ids, 'Survived': predictions })
 output.to_csv('submission.csv', index=False )<import_modules>
model = create_model()
model.compile(loss="bce", optimizer=tf.keras.optimizers.Adam() , metrics=["accuracy"] )
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.metrics import accuracy_score<load_from_csv>
history = model.fit(x=X_all_train,
y=Y_all_train,
batch_size=128,
epochs=20,
)
train=pd.read_csv(".. /input/titanic/train.csv")
 tit1=train.select_dtypes(include=['float64','int64','object'])
 train.info()
test=pd.read_csv(".. /input/titanic/test.csv")
 tit2=test.select_dtypes(include=['float64','int64','object'])
 test.info()<feature_engineering>
test_prediction = model.predict(X_test)
 test_prediction =(test_prediction > 0.5 ).astype(int ).reshape(test_df.shape[0], -1)
 sub = test_df[["id"]].copy()
tmp = pd.DataFrame(test_prediction, columns=start_features)
 submission = sub.join(tmp )
tit2['survived']=np.nan
tit2.head()<feature_engineering>
submission.to_csv("submission.csv", index=False )
<count_values><EOS> 
submission.to_csv("submission.csv", index=False )