Esempio n. 1
0
def predict_new_data(argv):
	'''
	Implements output prediction for new data

	Arguments:
	argv -- system inputs

	Returns:
	Y -- predicted Y value

	'''

	# file1 = saved model, file2 = excel file with new data
	print(argv)
	_, file1, file2 = argv
	print(file1)
	print(file2)

	# Process the excel data 
	X = process_data(file2)

	# Load model
	model = ELM(20, 1, tprint=5)
	model.load('{}'.format(file1))

	# Predict Y
	Y_predicted = model.predict(X)

	return Y_predicted	
 def test_ELM_SaveLoad(self):
     X = np.array([1, 2, 3, 1, 2, 3])
     T = np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]])
     elm = ELM(1, 2, precision='32', norm=0.02)
     elm.add_neurons(1, "lin")
     elm.add_neurons(2, "tanh")
     elm.train(X, T, "wc", w=(0.7, 0.3))
     B1 = elm.nnet.get_B()
     try:
         f, fname = tempfile.mkstemp()
         elm.save(fname)
         elm2 = ELM(3, 3)
         elm2.load(fname)
     finally:
         os.close(f)
     self.assertEqual(elm2.nnet.inputs, 1)
     self.assertEqual(elm2.nnet.outputs, 2)
     self.assertEqual(elm2.classification, "wc")
     self.assertIs(elm.precision, np.float32)
     self.assertIs(elm2.precision, np.float64)  # precision has changed
     np.testing.assert_allclose(np.array([0.7, 0.3]), elm2.wc)
     np.testing.assert_allclose(0.02, elm2.nnet.norm)
     np.testing.assert_allclose(B1, elm2.nnet.get_B())
     self.assertEqual(elm2.nnet.get_neurons()[0][1], "lin")
     self.assertEqual(elm2.nnet.get_neurons()[1][1], "tanh")
Esempio n. 3
0
 def test_ELM_SaveLoad(self):
     X = np.array([1, 2, 3, 1, 2, 3])
     T = np.array([[1, 0], [1, 0], [1, 0], [0, 1], [0, 1], [0, 1]])
     elm = ELM(1, 2, precision='32', norm=0.02)
     elm.add_neurons(1, "lin")
     elm.add_neurons(2, "tanh")
     elm.train(X, T, "wc", w=(0.7, 0.3))
     B1 = elm.nnet.get_B()
     try:
         f, fname = tempfile.mkstemp()
         elm.save(fname)
         elm2 = ELM(3, 3)
         elm2.load(fname)
     finally:
         os.close(f)
     self.assertEqual(elm2.nnet.inputs, 1)
     self.assertEqual(elm2.nnet.outputs, 2)
     self.assertEqual(elm2.classification, "wc")
     self.assertIs(elm.precision, np.float32)
     self.assertIs(elm2.precision, np.float64)  # precision has changed
     np.testing.assert_allclose(np.array([0.7, 0.3]), elm2.wc)
     np.testing.assert_allclose(0.02, elm2.nnet.norm)
     np.testing.assert_allclose(B1, elm2.nnet.get_B())
     self.assertEqual(elm2.nnet.get_neurons()[0][1], "lin")
     self.assertEqual(elm2.nnet.get_neurons()[1][1], "tanh")
Esempio n. 4
0
def t10k_test(model_path='../models/elm.model'):
    images, labels = read_mnist.load_mnist('../data/', kind='t10k')
    images = map(read_mnist.up_to_2D, images)
    images = map(get_hog, images)
    images = np.mat(np.array(images))

    labels = np.mat(map(read_mnist.handle_label, labels))

    elm = ELM(images.shape[1], labels.shape[1])
    # print images.shape[1], images.shape[1]
    elm.load(model_path)
    results = elm.predict(images)

    labels = map(get_labels, np.array(labels))
    results = map(get_labels, np.array(results))
    yes, tot = 0, len(labels)

    for i in range(0, len(labels)):
        if labels[i] == results[i]:
            yes += 1

    print 'YES :', yes
    print 'TOT :', tot
    print 'ACC : ', str(float(yes) / tot * 100.0) + '%'
    return float(yes) / tot * 100.0
Esempio n. 5
0
def predictor_init(model_path):
    elm = ELM(324, 324)
    elm.load(model_path)
    if elm == None:
        print 'Error: elm is None.'
        exit()
    print elm
    return elm