Posts

Simple Neural Network get 95.83% accuracy with RMSprop optimizer

Image
Simple Neural Network by using RMSprop optimzer with only 5 layers. Here's the coding. from __future__ import print_function import keras from keras.models import Sequential from keras.layers import Dense, Dropout from keras.optimizers import RMSprop from keras.utils import np_utils import os from six.moves import cPickle as pickle batch_size = 128 num_classes = 10 epochs = 20 def load_data():     test_filename = "notMNIST.pickle"     if os.path.exists(test_filename):         with open(test_filename, 'rb') as f:             letter_dataset = pickle.load(f)     return (letter_dataset)       lt_dt = load_data()   train_dataset = lt_dt['train_dataset'] train_labels = lt_dt['train_labels'] valid_dataset = lt_dt['valid_dataset'] valid_labels = lt_dt['valid_labels'] test_dataset = lt_dt['test_dataset'] test_labels = lt_dt['test_labels'] x_train = train_dataset.reshape(train_dataset.shape

Accuracy for Logistic Regression model is always lower than using Convolutional neural network

Image
Here's the coding for a logistic regression model with 100k samples. The accuracy is only 86.7% compared than 96% for ConvNet. ROC Curve for logistic is 0.97 compared to 0.99 for ConvNet. from __future__ import print_function import numpy as np import matplotlib.pyplot as plt import os from sklearn.metrics import roc_curve, auc from sklearn.linear_model import LogisticRegression from six.moves import cPickle as pickle from sklearn.metrics import confusion_matrix def load_data(): test_filename = "notMNIST.pickle" if os.path.exists(test_filename): with open(test_filename, 'rb') as f: letter_dataset = pickle.load(f) return (letter_dataset) sample_size = 10000 print('Sample size: ', sample_size) lt_dt = load_data() x_train = lt_dt['train_dataset'][:sample_size] y_train = lt_dt['train_labels'][:sample_size] x_test = lt_dt['test_dataset'] y_test = lt_dt['test_labels'] regr = LogisticRegressi

96.24% accuracy with higher epoch numbers for Convolutional Neural Network

Image
For Convolutional Neural Network , there are a lots of factors affect the model accuracy. Factors included the structure of Convolutional Neural Network , hyper parameters values, over-fitting and etc. Only correct or suitable network structure can produce high model accuracy. If wrong network structure is used, whatever you tune the hyper parameters, the accuracy will still worse. So, after we found the right network structure, only we can start to tune the hyper parameters. However, over-fitting may happened on your model accuracy. There are several methods to prevent that. One of the over-fitting prevention is by using the dropout function. Dropout give the model a way to find alternative way to train the model by removed some characteristic according to the ratio. Another way to prevent over-fitting is by increasing the number of samples. Besides, we can also simplify the network structure. Some complicated network structure sometimes can cause over-fitting too.  Finall

Accuracy 96% with Simple Deep NN using Keras Theano backend for nonMNist alphabet recognition

Image
Here's first try to build a simple simple deep neurons network by using Keras with Theano backend. By using the previous data pickles sample   nonMNist dataset we have saved, here's the completed coding. The summarized deep filter layers can be described as combination of common dense layer with 512 units, relu activation, dropout ratio of 0.2, softmax activation, and RMSprop optimizer. from __future__ import print_function import keras from keras.models import Sequential from keras.layers import Dense, Dropout from keras.optimizers import RMSprop from keras.utils import np_utils import os from six.moves import cPickle as pickle batch_size = 128 num_classes = 10 epochs = 20 def load_data(): test_filename = "notMNIST.pickle" if os.path.exists(test_filename): with open(test_filename, 'rb') as f: letter_dataset = pickle.load(f) return (letter_dataset) lt_dt = load_data() train_dataset = lt_dt['train_

Using mini batch SGD Neural Network in Alphabet recognition!

Here we are using mini-batch stochastic gradient descent neural network method in Alphabet recognition with previous data set mentioned in  nonMNIST data set . First, we are going to build the neural network part. Here we have adjustable number of hidden neurons, layers, epochs, mini batch sizes that allow us to tune the accuracy later. #network part import random import numpy as np class Network(object): def __init__(self, sizes): #sizes: number of neurons (eg: (2,3,1)) #biases and weights are initialized randomly self.num_layers = len(sizes) self.sizes = sizes self.biases = [np.random.randn(y, 1) for y in sizes[1:]] self.weights = [np.random.randn(y, x) for x, y in zip(sizes[:-1], sizes[1:])] def feedforward(self, a): #return output of network f a is input for b, w in zip(self.biases, self.weights): a = sigmoid(np.dot(w, a) + b) return a def SGD