Exemplo n.º 1
0
    def solver(self, load_from_file=True):
        for acti_fn in ['relu', 'sigmoid', 'linear', 'tanh']:
            if (load_from_file == False):
                model = Q1.MyNeuralNetwork(5, [784, 256, 128, 64, 10], acti_fn,
                                           0.1, 'normal', 500, 100)
                model.fill_testing_data(self.X_test, self.y_test, verbose=1)
                print('-------' * 8)
                print('Begening fit for activation function', acti_fn)
                model.fit(self.X_train, self.y_train)
                joblib.dump(model, 'models/saved_model_' + acti_fn)

            else:
                model = joblib.load('models/saved_model_' + acti_fn)

            err = model.get_errors_featres()
            self.__plot_errorVSepochs(err[0], err[1],
                                      'Actvation function = ' + acti_fn)

            NNfeatures = TSNE(n_components=2).fit_transform(err[2])
            self.__plot_cluster(NNfeatures, self.y_test,
                                'Features using ' + acti_fn)

            print('Accuracy for', acti_fn, '= ',
                  model.score(self.X_test, self.y_test) * 100, '%')
Exemplo n.º 2
0
import matplotlib.pylab as plt

train_x, train_y = loadlocal_mnist("data/train-images.idx3-ubyte",
                                   "data/train-labels.idx1-ubyte")
test_x, test_y = loadlocal_mnist("data/t10k-images.idx3-ubyte",
                                 "data/t10k-labels.idx1-ubyte")
train_x = preprocessing.normalize(train_x)
test_x = preprocessing.normalize(test_x)
enc = OneHotEncoder(sparse=False, categories='auto')
train_y = enc.fit_transform(train_y.reshape(len(train_y), -1))
test_y = enc.transform(test_y.reshape(len(test_y), -1))

network = Q1.MyNeuralNetwork(n_layers=5,
                             layer_sizes=[784, 256, 128, 64, 10],
                             activation="relu",
                             learning_rate=0.1,
                             weight_init="normal",
                             batch_size=200,
                             num_epochs=101)
network.fit(network.train_x, network.train_y)
network.tsne()

network = Q1.MyNeuralNetwork(n_layers=5,
                             layer_sizes=[784, 256, 128, 64, 10],
                             activation="relu",
                             learning_rate=0.1,
                             weight_init="normal",
                             batch_size=200,
                             num_epochs=101)
network.fit(network.train_x, network.train_y)
network.saveModel(network, "ReLU_normal")