Skip to content

Instantly share code, notes, and snippets.

View Praveenk8051's full-sized avatar
🐢

Praveen Praveenk8051

🐢
View GitHub Profile
# prediction
results = model.predict(test)
# Index with the maximum probability
results = np.argmax(results,axis = 1)
results = pd.Series(results,name="Label")
@Praveenk8051
Praveenk8051 / augment_mnist.py
Last active May 6, 2020 12:23
Dataaugment mnist
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
@Praveenk8051
Praveenk8051 / lr_metric_mnist.py
Last active May 6, 2020 12:21
lr metric monitor mnist
# 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
# 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"])
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',
@Praveenk8051
Praveenk8051 / split_mnist.py
Last active May 6, 2020 11:14
Split the data MNIST
# 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)
Y_train = to_categorical(Y_train, num_classes = 10)
@Praveenk8051
Praveenk8051 / normalize_reshape_mnist.py
Created May 6, 2020 11:09
Normalize and Reshape MNIST
#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)
@Praveenk8051
Praveenk8051 / handle_missing_mnist.py
Created May 6, 2020 10:48
Handle Missing Data Mnist
X_train.isnull().any().describe()
test.isnull().any().describe()
@Praveenk8051
Praveenk8051 / load_data_mnist.py
Created May 6, 2020 10:20
load data for mnist
# 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()