Kaggle competition: Digit Recognizer
models = []
scores = []
models.append("AdaBoost")
 print("AdaBoost:")
 model = AdaBoostClassifier()
result = cross_val_score(model,train_data,train_result,scoring='roc_auc',cv=StratifiedKFold(n_splits=10))
print('mean score:', result.mean())
 scores.append(result.mean())
 models.append("LGBM")
 print("LGBM:")
 model = LGBMClassifier()
result = cross_val_score(model,train_data,train_result,scoring='roc_auc',cv=StratifiedKFold(n_splits=10))
print('mean score:', result.mean())
 scores.append(result.mean())
 models.append("XGBoost")
 print("XGBoost:")
 model = XGBClassifier(eval_metric = 'auc')
 result = cross_val_score(model,train_data,train_result,scoring='roc_auc',cv=StratifiedKFold(n_splits=10))
print('mean score:', result.mean())
 scores.append(result.mean())
 models.append("GBDT")
 print("GBDT:")
 model = GradientBoostingClassifier()
result = cross_val_score(model,train_data,train_result,scoring='roc_auc',cv=StratifiedKFold(n_splits=10))
print('mean score:', result.mean())
 scores.append(result.mean())
 models.append("RandomForest")
 print("RandomForest:")
 model = RandomForestClassifier()
result = cross_val_score(model,train_data,train_result,scoring='roc_auc',cv=StratifiedKFold(n_splits=10))
print('mean score:', result.mean())
 scores.append(result.mean())
 models.append("SVM")
 print("SVM:")
 model = svm.SVC()
result = cross_val_score(model,train_data,train_result,scoring='roc_auc',cv=StratifiedKFold(n_splits=10))
print('mean score:', result.mean())
 scores.append(result.mean())
<choose_model_class>
train = pd.read_csv(".. /input/train.csv")
 print(train.shape)
 train.head()
model = LGBMClassifier()
model.fit(train_data, train_result)
 predict_proba = model.predict_proba(test_data)[:,1]
roc_auc_score(test_result, predict_proba )<find_best_model_class>
test= pd.read_csv(".. /input/test.csv")
 print(test.shape)
 test.head()
model = LGBMClassifier(n_estimators = 290, learning_rate = 0.025,max_depth = 6, num_leaves = 22)
 model.fit(train_data, train_result)
 predict_proba = model.predict_proba(test_data)[:,1]
roc_auc_score(test_result, predict_proba )<save_to_csv>
X_train =(train.iloc[:,1:].values ).astype('float32')
 y_train = train.iloc[:,0].values.astype('int32')
 X_test = test.values.astype('float32')
 X = X_train
y = y_train
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.10, random_state=42 )
x_test = x_test.drop(['SeriousDlqin2yrs'],axis=1)
 y_test = model.predict_proba(x_test)[:,1]
ids = np.arange(1,101504)
 res = pd.DataFrame({'Id': ids, 'Probability': y_test})
 res.to_csv("submission.csv", index=False )<load_from_csv>
\
mean_px = X_train.mean().astype(np.float32)
 std_px = X_train.std().astype(np.float32)
 def standardize(x):
return(x-mean_px)/std_px
train_df = pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-training.csv')
 test_df = pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-test.csv' )<count_missing_values>
y_train = np_utils.to_categorical(y_train,10)
 X = X.reshape(-1,28,28,1)
 y = np_utils.to_categorical(y,10 )
train_df.isnull().sum()<count_missing_values>
seed = 43
np.random.seed(seed )
test_df.isnull().sum()<filter>
from keras.models import Sequential
from keras.layers.core import Lambda , Dense, Flatten, Dropout
from keras.callbacks import EarlyStopping
from keras.layers import BatchNormalization, Convolution2D , MaxPooling2D
train_df.loc[train_df['age'] < 18]<remove_duplicates>
def get_bn_model() :
model = Sequential([
Lambda(standardize, input_shape=(28,28,1)) ,
Convolution2D(32,(3,3), activation='relu'),
BatchNormalization(axis=1),
Convolution2D(32,(3,3), activation='relu'),
MaxPooling2D() ,
BatchNormalization(axis=1),
Convolution2D(64,(3,3), activation='relu'),
BatchNormalization(axis=1),
Convolution2D(64,(3,3), activation='relu'),
MaxPooling2D() ,
Flatten() ,
BatchNormalization() ,
Dense(512, activation='relu'),
BatchNormalization() ,
Dense(10, activation='softmax')
 ])
 model.compile(Adam() , loss='categorical_crossentropy', metrics=['accuracy'])
 return model
train_df.drop_duplicates(inplace=True )<rename_columns>
model= get_bn_model()
gen =ImageDataGenerator(rotation_range=8, width_shift_range=0.08, shear_range=0.3,
height_shift_range=0.08, zoom_range=0.08)
 batches = gen.flow(X, y, batch_size=64)
 history=model.fit_generator(generator=batches, steps_per_epoch=batches.n, epochs=1)
<filter><EOS> 
X_test.shape
results = model.predict(X_test)
 results = np.argmax(results,axis = 1)
 results = pd.Series(results,name="Label")
 submission = pd.concat([pd.Series(range(1,28001),name = "ImageId"),results],axis = 1)
 submission.to_csv("Aniket_Digit_pred2.csv",index=False )