本文整理汇总了Python中mlp.MLP.get_train_func方法的典型用法代码示例。如果您正苦于以下问题:Python MLP.get_train_func方法的具体用法?Python MLP.get_train_func怎么用?Python MLP.get_train_func使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mlp.MLP
的用法示例。
在下文中一共展示了MLP.get_train_func方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fit_model
# 需要导入模块: from mlp import MLP [as 别名]
# 或者: from mlp.MLP import get_train_func [as 别名]
def fit_model(self, X, Y, num_classes):
if self.modeltype == "mlp":
classifier = MLP(self.input_size, self.hidden_sizes, num_classes)
else:
classifier = RNN(self.input_size, self.hidden_size, num_classes)
train_func = classifier.get_train_func(self.learning_rate)
for num_iter in range(self.max_iter):
for x, y in zip(X, Y):
train_func(x, y)
return classifier
示例2: fit_model
# 需要导入模块: from mlp import MLP [as 别名]
# 或者: from mlp.MLP import get_train_func [as 别名]
def fit_model(self, X, Y, num_classes):
if self.modeltype == "mlp" or self.modeltype == "rnn":
if self.modeltype == "mlp":
classifier = MLP(self.input_size, self.hidden_sizes, num_classes)
else:
classifier = RNN(self.input_size, self.hidden_size, num_classes)
train_func = classifier.get_train_func(self.learning_rate)
for num_iter in range(self.max_iter):
for x, y in zip(X, Y):
train_func(x, y)
elif self.modeltype == "lstm":
classifier = Sequential()
classifier.add(LSTM(input_dim=self.input_size, output_dim=self.input_size/2))
#classifier.add(Dropout(0.3))
classifier.add(Dense(num_classes, activation='softmax'))
classifier.compile(loss='categorical_crossentropy', optimizer='adam')
Y_indexed = numpy.zeros((len(Y), num_classes))
for i in range(len(Y)):
Y_indexed[i][Y[i]] = 1
classifier.fit(X, Y_indexed, nb_epoch=20)
return classifier