Kaggle competition: Digit Recognizer
output1 = pd.DataFrame({'Id': test.Id.values, 'SalePrice': y_test_rf})
 output1.to_csv('output1.csv', index=False )<find_best_params>
train_data = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')
 test_data = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')
 submission = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')
 train_labels = train_data["label"]
train_data = train_data.drop(['label'], axis = 1)
 train_data = train_data /255.
 test_data = test_data / 255.
 train_data = train_data.values.reshape(train_data.shape[0],28,28,1)
 test_data = test_data.values.reshape(test_data.shape[0],28,28,1)
 labels = to_categorical(train_labels)
 X_train, X_test, y_train, y_test = train_test_split(train_data, labels, test_size = 0.2, random_state = 42 )
search_cv = RidgeCV(alphas =(0.001, 0.01, 0.05, 0.1, 0.3, 0.5, 1, 3, 5, 10))
search_cv.fit(X_train, y_train)
 y_test_cv = search_cv.predict(X_test)
 print('RidgeCV accuracy:', search_cv.score(X_train, y_train))<save_to_csv>
learning_rate_cb = ReduceLROnPlateau(monitor = 'val_acc',
patience = 2,
verbose = 1,
factor = 0.5,
min_lr = 1e-5 )
output2 = pd.DataFrame({'Id': test.Id.values, 'SalePrice': y_test_cv})
 output2.to_csv('output2.csv', index=False )<save_to_csv>
datagen = ImageDataGenerator(
 zoom_range = 0.1,
width_shift_range = 0.1,
height_shift_range = 0.1,
rotation_range = 10 
)
 datagen.fit(X_train )
prediction =(y_test_rf + y_test_cv)/2
output = pd.DataFrame({'Id': test.Id.values, 'SalePrice': prediction})
 output.to_csv('submission.csv', index=False )<import_modules>
batchsize = 512
num_epochs = 30
n_model_runs = 10
modellist = list()
for i in range(n_model_runs):
print("+++++++++ running model number", i+1)
 model = models.Sequential([
Conv2D(16, [5,5], activation = 'relu', padding = 'same', input_shape = [28,28,1]),
MaxPooling2D([2,2]),
Conv2D(32, [5,5], activation = 'relu', padding = 'same'),
MaxPooling2D([2,2]),
Conv2D(64, [3,3], activation = 'relu', padding = 'same'),
MaxPooling2D([2,2]),
Conv2D(64, [3,3], activation = 'relu', padding = 'same'),
MaxPooling2D([2,2]),
Flatten() ,
Dense(512, activation = 'relu'),
Dropout(0.3),
Dense(1024, activation = 'relu'),
Dropout(0.5),
Dense(10, activation = 'softmax')
 ])
 model.compile(optimizer = Adam(lr=1e-3),
loss='categorical_crossentropy',
metrics = ['accuracy'])
 model.fit_generator(datagen.flow(X_train, y_train, batchsize),
epochs = num_epochs,
steps_per_epoch = X_train.shape[0]/batchsize,
validation_data =(X_test, y_test),
callbacks=[learning_rate_cb],
verbose = 1)
 modellist.append(model )
import os
import warnings
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.feature_selection import mutual_info_regression
from sklearn.decomposition import PCA
from sklearn.preprocessing import LabelEncoder, OneHotEncoder, OrdinalEncoder, StandardScaler
from sklearn.model_selection import train_test_split, KFold, StratifiedKFold
from sklearn.linear_model import LinearRegression, Lasso, Ridge, ElasticNet
from sklearn.ensemble import RandomForestRegressor
from lightgbm import LGBMRegressor
from catboost import CatBoostRegressor
from xgboost import XGBRegressor
from sklearn.metrics import mean_squared_error
import optuna<set_options>
prediction = [model.predict(test_data)for model in modellist]
prediction = np.sum(prediction, axis=0)
 prediction = np.argmax(prediction,axis=1 )
<drop_column><EOS> 
submission = pd.DataFrame({"ImageId": list(range(1, len(prediction)+1)) , "Label": prediction})
 submission.to_csv('submission.csv', index = False, header = True )