Kaggle competition: Digit Recognizer
hyperparameters = {
'var_smoothing': np.logspace(0, -9, num=100)
 }
estimator = GaussianNB()
best_model_gaussian_nb = get_best_model(estimator, hyperparameters )<find_best_params>
train = pd.read_csv('.. /input/digit-recognizer/train.csv')
 test_data = pd.read_csv('.. /input/digit-recognizer/test.csv')
 print(train.info() )
evaluate_model(best_model_gaussian_nb.best_estimator_, 'gaussian_nb' )<choose_model_class>
X_train = train.iloc[:,1:]
y_train = train.iloc[:,0]
hyperparameters = {
'alpha' : [0.5, 1.0, 1.5, 2.0, 5],
'fit_prior' : [True, False],
}
estimator = MultinomialNB()
best_model_multinominal_nb = get_best_model(estimator, hyperparameters )<find_best_params>
X_train = X_train/255.0
test_data = test_data/255.0
X_train = X_train.values.reshape(-1,28,28,1)
 test_data = test_data.values.reshape(-1,28,28,1 )
evaluate_model(best_model_multinominal_nb.best_estimator_, 'multinominal_nb' )<choose_model_class>
import tensorflow as tf
from tensorflow import keras
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dropout, Lambda, Flatten, Dense
from keras.utils.np_utils import to_categorical
hyperparameters = {
'alpha' : [0.5, 1.0, 1.5, 2.0, 5],
'fit_prior' : [True, False],
'norm' : [True, False]
}
estimator = ComplementNB()
best_model_complement_nb = get_best_model(estimator, hyperparameters )<find_best_params>
y_train = to_categorical(y_train,num_classes=10 )
evaluate_model(best_model_complement_nb.best_estimator_, 'complement_nb' )<choose_model_class>
X_train, X_test, y_train, y_test = train_test_split(X_train, y_train, test_size=0.1, random_state=42 )
hyperparameters = {
'alpha' : [0.5, 1.0, 1.5, 2.0, 5],
'fit_prior' : [True, False],
}
estimator = BernoulliNB()
best_model_bernoulli_nb = get_best_model(estimator, hyperparameters )<find_best_params>
model = Sequential()
model.add(Conv2D(32,(5,5),padding='Same', activation='relu', kernel_initializer='glorot_uniform', input_shape=(28, 28, 1)))
 model.add(Conv2D(32,(5,5),padding='Same', activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Dropout(0.25))
model.add(Conv2D(64,(3,3), padding='Same', activation='relu'))
model.add(Conv2D(64,(3,3), padding='Same', activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))
 model.add(Dropout(0.25))
model.add(Flatten())
 model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
evaluate_model(best_model_bernoulli_nb.best_estimator_, 'bernoulli_nb' )<choose_model_class>
opt = RMSprop(lr=0.001)
 model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'] )
hyperparameters = {
'n_neighbors' : list(range(1,5)) ,
'weights' : ['uniform', 'distance'],
'algorithm' : ['auto', 'ball_tree', 'kd_tree', 'brute'],
'leaf_size' : list(range(1,10)) ,
'p' : [1,2]
}
estimator = KNeighborsClassifier()
best_model_kneighbors = get_best_model(estimator, hyperparameters )<find_best_params>
from keras.preprocessing.image import ImageDataGenerator,img_to_array,load_img
import itertools
evaluate_model(best_model_kneighbors.best_estimator_, 'kneighbors' )<choose_model_class>
datagen = ImageDataGenerator(rotation_range=10, zoom_range = 0.1, width_shift_range=0.1, height_shift_range=0.1)
 datagen.fit(X_train)
 history = model.fit_generator(datagen.flow(X_train,y_train, batch_size=86),
epochs = 30, validation_data =(X_test,y_test),verbose = 2,
steps_per_epoch=X_train.shape[0]/86 )
hyperparameters = {
'penalty' : ['l1', 'l2', 'elasticnet'],
'eta0' : [0.0001, 0.001, 0.01, 0.1, 1.0],
'max_iter' : list(range(50, 200, 50))
}
estimator = Perceptron(random_state=1)
 best_model_perceptron = get_best_model(estimator, hyperparameters )<find_best_params>
pred = model.predict(test_data)
 pred
evaluate_model(best_model_perceptron.best_estimator_, 'perceptron' )<find_best_params>
prediction = np.argmax(pred, axis = 1)
 prediction
hyperparameters = {
'C' : [0.1, 1, 10, 100],
'gamma' : [0.0001, 0.001, 0.01, 0.1, 1],
'kernel' : ['rbf']
}
estimator = SVC(random_state=1)
 best_model_svc = get_best_model(estimator, hyperparameters )<find_best_params>
submission = pd.read_csv('.. /input/digit-recognizer/sample_submission.csv')
 submission['Label'] = prediction
submission.head(10 )
evaluate_model(best_model_svc.best_estimator_, 'svc' )<choose_model_class>
submission.to_csv("submission.csv", index=False, header=True )