本文整理汇总了Python中hpelm.ELM类的典型用法代码示例。如果您正苦于以下问题:Python ELM类的具体用法?Python ELM怎么用?Python ELM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ELM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HPELMNN
class HPELMNN(Classifier):
def __init__(self):
self.__hpelm = None
@staticmethod
def name():
return "hpelmnn"
def train(self, X, Y, class_number=-1):
class_count = max(np.unique(Y).size, class_number)
feature_count = X.shape[1]
self.__hpelm = ELM(feature_count, class_count, 'wc')
self.__hpelm.add_neurons(feature_count, "sigm")
Y_arr = Y.reshape(-1, 1)
enc = OneHotEncoder()
enc.fit(Y_arr)
Y_OHE = enc.transform(Y_arr).toarray()
out_fd = sys.stdout
sys.stdout = open(os.devnull, 'w')
self.__hpelm.train(X, Y_OHE)
sys.stdout = out_fd
def predict(self, X):
Y_predicted = self.__hpelm.predict(X)
return Y_predicted
示例2: test_24_AddNeurons_InitDefault_BiasWNotZero
def test_24_AddNeurons_InitDefault_BiasWNotZero(self):
elm = ELM(2, 1)
elm.add_neurons(3, "sigm")
W = elm.neurons[0][2]
bias = elm.neurons[0][3]
self.assertGreater(np.sum(np.abs(W)), 0.001)
self.assertGreater(np.sum(np.abs(bias)), 0.001)
示例3: test_ConfusionELM_Multilabel
def test_ConfusionELM_Multilabel(self):
T = np.array([[1, 0], [1, 0], [0, 1], [0, 1]])
Y = np.array([[1, 1], [1, 0], [0, 1], [0, 1]])
elm = ELM(1, 2)
elm.classification = "ml"
C = elm.confusion(T, Y)
np.testing.assert_allclose(C, np.array([[2, 1], [0, 2]]))
示例4: test_CrossValidation_ReturnsError
def test_CrossValidation_ReturnsError(self):
model = ELM(5, 2)
model.add_neurons(10, 'tanh')
X = np.random.rand(100, 5)
T = np.random.rand(100, 2)
err = model.train(X, T, 'CV', k=3)
self.assertIsNotNone(err)
示例5: test_RegressionError_Works
def test_RegressionError_Works(self):
T = np.array([1, 2, 3])
Y = np.array([1.1, 2.2, 3.3])
err1 = np.mean((T - Y) ** 2)
elm = ELM(1, 1)
e = elm.error(T, Y)
np.testing.assert_allclose(e, err1)
示例6: test_MultiLabelClassification_Works
def test_MultiLabelClassification_Works(self):
elm = ELM(1, 2)
X = np.array([1, 2, 3, 4, 5, 6])
T = np.array([[1, 1], [1, 0], [1, 0], [0, 1], [0, 1], [1, 1]])
elm.add_neurons(1, "lin")
elm.train(X, T, 'ml')
elm.train(X, T, 'mc')
示例7: test_TrainWithBatch_OverwritesBatch
def test_TrainWithBatch_OverwritesBatch(self):
elm = ELM(1, 1, batch=123)
X = np.array([1, 2, 3])
T = np.array([1, 2, 3])
elm.add_neurons(1, "lin")
elm.train(X, T, batch=234)
self.assertEqual(234, elm.batch)
示例8: test_MultilabelError_CorrectWithMultipleClasses
def test_MultilabelError_CorrectWithMultipleClasses(self):
T = np.zeros((100, 5))
T[:, 0] = 1
Y = np.zeros((100, 5))
Y[:, 1] = 1
model = ELM(1, 5, classification='ml')
self.assertEqual(0.4, model.error(T, Y))
示例9: test_AddNeurons_WorksWithLongType
def test_AddNeurons_WorksWithLongType(self):
if sys.version_info[0] == 2:
ltype = long
else:
ltype = int
model = ELM(3, 2)
L = ltype(10)
model.add_neurons(L, 'tanh')
示例10: test_20_SLFN_AddTwoNeuronTypes_GotThem
def test_20_SLFN_AddTwoNeuronTypes_GotThem(self):
elm = ELM(1, 1)
elm.add_neurons(1, "lin")
elm.add_neurons(1, "sigm")
self.assertEquals(2, len(elm.neurons))
ntypes = [nr[0] for nr in elm.neurons]
self.assertIn("lin", ntypes)
self.assertIn("sigm", ntypes)
示例11: test_MultiLabelClassError_Works
def test_MultiLabelClassError_Works(self):
X = np.array([1, 2, 3])
T = np.array([[0, 1], [1, 1], [1, 0]])
Y = np.array([[0.4, 0.6], [0.8, 0.6], [1, 1]])
elm = ELM(1, 2, classification="ml")
elm.add_neurons(1, "lin")
e = elm.error(T, Y)
np.testing.assert_allclose(e, 1.0 / 6)
示例12: test_WeightedClassError_Works
def test_WeightedClassError_Works(self):
T = np.array([[0, 1], [0, 1], [1, 0]])
Y = np.array([[0, 1], [0.4, 0.6], [0, 1]])
# here class 0 is totally incorrect, and class 1 is totally correct
w = (9, 1)
elm = ELM(1, 2, classification="wc", w=w)
elm.add_neurons(1, "lin")
e = elm.error(T, Y)
np.testing.assert_allclose(e, 0.9)
示例13: test_25_AddNeurons_InitTwiceBiasW_CorrectlyMerged
def test_25_AddNeurons_InitTwiceBiasW_CorrectlyMerged(self):
elm = ELM(2, 1)
W1 = np.random.rand(2, 3)
W2 = np.random.rand(2, 4)
bias1 = np.random.rand(3,)
bias2 = np.random.rand(4,)
elm.add_neurons(3, "sigm", W1, bias1)
elm.add_neurons(4, "sigm", W2, bias2)
np.testing.assert_array_almost_equal(np.hstack((W1, W2)), elm.neurons[0][2])
np.testing.assert_array_almost_equal(np.hstack((bias1, bias2)), elm.neurons[0][3])
示例14: test_LOOandOP_CanSelectMoreThanOneNeuron
def test_LOOandOP_CanSelectMoreThanOneNeuron(self):
X = np.random.rand(100, 5)
T = np.random.rand(100, 2)
for _ in range(10):
model = ELM(5, 2)
model.add_neurons(5, 'lin')
model.train(X, T, 'LOO', 'OP')
max2 = model.nnet.L
if max2 > 1:
break
self.assertGreater(max2, 1)
示例15: build_ELM_encoder
def build_ELM_encoder(xinput, target, num_neurons):
elm = ELM(xinput.shape[1], target.shape[1])
elm.add_neurons(num_neurons, "sigm")
elm.add_neurons(num_neurons, "lin")
#elm.add_neurons(num_neurons, "rbf_l1")
elm.train(xinput, target, "r")
ypred = elm.predict(xinput)
print "mse error", elm.error(ypred, target)
return elm, ypred