This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prediction | |
results = model.predict(test) | |
# Index with the maximum probability | |
results = np.argmax(results,axis = 1) | |
results = pd.Series(results,name="Label") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datagen = ImageDataGenerator( | |
featurewise_center=False, | |
samplewise_center=False, | |
featurewise_std_normalization=False, | |
samplewise_std_normalization=False, | |
zca_whitening=False, | |
rotation_range=10, # randomly rotate images | |
zoom_range = 0.2, # Randomly zoom image | |
width_shift_range=0.2, # randomly shift images horizontally | |
height_shift_range=0.2, # randomly shift images vertically |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set LR metric monitor | |
learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc', | |
patience=3, | |
verbose=1, | |
factor=0.4, | |
min_lr=0.00001) | |
epochs = 500 | |
batch_size = 32 #to start with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Optimizer | |
optimizer = RMSprop(lr=0.001, rho=0.9, epsilon=1e-08, decay=0.0) | |
# Compile the model | |
model.compile(optimizer = optimizer , loss = "categorical_crossentropy", metrics=["accuracy"]) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = Sequential() | |
model.add(Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same', | |
activation ='relu', input_shape = (28,28,1))) | |
model.add(Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same', | |
activation ='relu')) | |
model.add(MaxPool2D(pool_size=(2,2))) | |
model.add(Dropout(0.25)) | |
model.add(Conv2D(filters = 64, kernel_size = (3,3),padding = 'Same', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# random seed | |
random_seed = 3 | |
# Split | |
X_train, X_val, Y_train, Y_val = train_test_split(X_train, Y_train, test_size = 0.2, random_state=random_seed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Y_train = to_categorical(Y_train, num_classes = 10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Normalize | |
X_train = X_train / 255.0 | |
test = test / 255.0 | |
#Reshape | |
X_train = X_train.values.reshape(-1,28,28,1) | |
test = test.values.reshape(-1,28,28,1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_train.isnull().any().describe() | |
test.isnull().any().describe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load data and visualize the histogram | |
train = pd.read_csv("../input/train.csv") | |
test = pd.read_csv("../input/test.csv") | |
Y_train = train["label"] | |
X_train = train.drop(labels = ["label"],axis = 1) | |
g = sns.countplot(Y_train) | |
Y_train.value_counts() |
NewerOlder