Kaggle competition: Digit Recognizer
sub['target'] = 1.2*test_preds-0.2*test_preds_2
sub.to_csv('submission_average_1.csv', index=False )<save_to_csv>
train = pd.read_csv("/kaggle/input/digit-recognizer/train.csv")
 test = pd.read_csv("/kaggle/input/digit-recognizer/test.csv")
 submission = pd.read_csv("/kaggle/input/digit-recognizer/sample_submission.csv" )
sub['target'] = 1.3*test_preds-0.3*test_preds_2
sub.to_csv('submission_average_2.csv', index=False )<load_from_csv>
X = train.drop(['label'], axis = 1 ).values/255
Y = train['label'].values
X_valid = test.values/255
X = X.reshape(X.shape[0],28,28,1)
 X_valid = X_valid.reshape(X_valid.shape[0],28,28,1)
input_dir = os.path.join('.. ', 'input', 'tabular-playground-series-feb-2021')
 sample_submission_csv_path = os.path.join(input_dir, 'sample_submission.csv')
 test_csv_path = os.path.join(input_dir, 'test.csv')
 train_csv_path = os.path.join(input_dir, 'train.csv')
 train_df = pd.read_csv(train_csv_path)
 y = train_df[['target']]
x = train_df.drop(columns=['id', 'target'])
 cat_features = list(range(0, 10))
train_pool = Pool(x, y, cat_features=cat_features)
 model = CatBoostRegressor(random_seed=1)
 model.fit(train_pool)
 test_df = pd.read_csv(test_csv_path)
 x_id = test_df[['id']]
x_test = test_df.drop(columns=['id'])
 test_pool = Pool(x_test, cat_features=cat_features)
 target = model.predict(test_pool)
 submission = pd.read_csv(sample_submission_csv_path)
 submission[['target']] = target
submission.to_csv('submission.csv', index=False)
<import_modules>
X_train, X_dev, Y_train,Y_dev = train_test_split(X,Y,test_size = 0.2 )
import lightgbm as lgb
import optuna.integration.lightgbm as oplgb
from sklearn.model_selection import KFold
from sklearn.metrics import mean_squared_error
from tqdm.notebook import tqdm
import matplotlib.pyplot as plt
import category_encoders as ce
import seaborn as sns<load_from_csv>
f = 2
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(f*16,kernel_size =(3,3), padding = 'same',activation='relu',
kernel_initializer='he_uniform',
input_shape =(28,28,1)) ,
tf.keras.layers.Conv2D(f*16,(3,3), activation = "relu", padding = 'same'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.MaxPooling2D() ,
tf.keras.layers.Conv2D(f*32, kernel_size =(3,3), padding = 'same',activation='relu'),
tf.keras.layers.Conv2D(f*32,(3,3), activation = "relu", padding = 'same'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.MaxPooling2D() ,
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Conv2D(f*64, kernel_size =(3,3), padding = 'same',activation='relu'),
tf.keras.layers.Conv2D(f*64,(3,3), activation = "relu", padding = 'same'),
tf.keras.layers.BatchNormalization() ,
tf.keras.layers.MaxPooling2D() ,
tf.keras.layers.Dropout(0.125),
keras.layers.Flatten() ,
keras.layers.Dense(512, activation = 'relu'),
keras.layers.Dense(128, activation = 'relu'),
keras.layers.Dense(10, activation='softmax')
 ])
 model.summary()
df_train = pd.read_csv("/kaggle/input/tabular-playground-series-feb-2021/train.csv")
 df_test = pd.read_csv("/kaggle/input/tabular-playground-series-feb-2021/test.csv")
 df_sample = pd.read_csv("/kaggle/input/tabular-playground-series-feb-2021/sample_submission.csv" )<drop_column>
from keras.utils import plot_model
train_id = df_train["id"]
test_id = df_test["id"]
df_train.drop("id", axis=1, inplace=True)
 df_test.drop("id", axis=1, inplace=True )<define_variables>
model.compile(optimizer=Adam(learning_rate=0.0003),
loss = 'sparse_categorical_crossentropy',
metrics = ['accuracy'] )
cat_features = [f"cat{i}" for i in range(9 + 1)]<categorify>
train_datagen = ImageDataGenerator(rotation_range=10,
width_shift_range=0.15,
height_shift_range=0.15,
shear_range=0.05,
zoom_range=0.15,
horizontal_flip=False)
 valid_datagen = ImageDataGenerator(horizontal_flip=False, 
)
 callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=5)
 def lr_decay(epoch, initial_learningrate = 0.0003):
return initial_learningrate * 0.99 ** epoch
learning_rate_reduction = tf.keras.callbacks.ReduceLROnPlateau(monitor='val_acc',
patience=300,
verbose=1,
factor=0.5,
min_lr=0.00001)
 batchsize = 512*2
epoch = 45
history = model.fit_generator(train_datagen.flow(X, Y, batch_size = batchsize),
steps_per_epoch = 100,
epochs = epoch,
callbacks=[
LearningRateScheduler(lr_decay),
callback],
validation_data=valid_datagen.flow(X_dev, Y_dev),
validation_steps=50,
)
<categorify><EOS> 
yhat = model.predict_classes(X_valid)
 submission['Label']=pd.Series(yhat)
 submission.to_csv('submission.csv',index=False )