当前位置: 首页>>代码示例>>Python>>正文


Python NeuralNet.train_split方法代码示例

本文整理汇总了Python中nolearn.lasagne.NeuralNet.train_split方法的典型用法代码示例。如果您正苦于以下问题:Python NeuralNet.train_split方法的具体用法?Python NeuralNet.train_split怎么用?Python NeuralNet.train_split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nolearn.lasagne.NeuralNet的用法示例。


在下文中一共展示了NeuralNet.train_split方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: neural_network_regression

# 需要导入模块: from nolearn.lasagne import NeuralNet [as 别名]
# 或者: from nolearn.lasagne.NeuralNet import train_split [as 别名]
def neural_network_regression(data):
    layers0 = [('input', InputLayer),
               ('dense0', DenseLayer),
               ('dense1', DenseLayer),
               ('dense2', DenseLayer),
               ('dense3', DenseLayer),
               ('dense4', DenseLayer),
               ('output', DenseLayer)]

    net0 = NeuralNet(layers=layers0,
                     input_shape=(None, len(data.X_train[0])),
                     dense0_num_units=400,
                     dense0_nonlinearity=rectify,
                     dense1_num_units=200,
                     dense1_nonlinearity=rectify,
                     dense2_num_units=100,
                     dense2_nonlinearity=rectify,
                     dense3_num_units=50,
                     dense3_nonlinearity=rectify,
                     dense4_num_units=25,
                     dense4_nonlinearity=rectify,
                     output_num_units=1,
                     output_nonlinearity=None,

                     update=nesterov_momentum,
                     update_learning_rate=0.00001,
                     update_momentum=0.9,
                     regression=True,

                     on_epoch_finished=[
                         EarlyStopping(patience=20),
                         AcceptLoss(min=0.01)
                     ],

                     verbose=VERBOSE,
                     max_epochs=100000)

    # Provide our own validation set
    def my_split(self, X, y, eval_size):
        return data.X_train, data.X_validate, data.y_train_nn, data.y_validate_nn

    net0.train_split = types.MethodType(my_split, net0)

    return net0
开发者ID:jeffheaton,项目名称:papers,代码行数:46,代码来源:run_experiment.py

示例2: zscore

# 需要导入模块: from nolearn.lasagne import NeuralNet [as 别名]
# 或者: from nolearn.lasagne.NeuralNet import train_split [as 别名]
# Compute the z-scores for both train and validation.  However, use mean and standard deviation for training
# on both.  This is customary because we trained on this standard deviation and mean.  Additionally, our
# prediction set might too small to calculate a meaningful mean and standard deviation.
X_train_z = zscore(X_train, train_mean, train_sdev) #scipy.stats.mstats.zscore(X_train)
X_validate_z = zscore(X_validate, train_mean, train_sdev)  #scipy.stats.mstats.zscore(X_validate)

#These can be used to check my zscore calc to numpy
#print(X_train_z)
#print(scipy.stats.mstats.zscore(X_train))

# Provide our own validation set
def my_split(self, X, y, eval_size):
    return X_train_z,X_validate_z,y_train,y_validate

net0.train_split = types.MethodType(my_split, net0)

# Train the network
net0.fit(X_train_z,y_train)

# Predict the validation set
pred_y = net0.predict(X_validate_z)

# Display predictions and count the number of incorrect predictions.
species_names = ['setosa','versicolour','virginica']

count = 0
wrong = 0
for element in zip(X_validate,y_validate,pred_y):
    print("Input: sepal length: {}, sepal width: {}, petal length: {}, petal width: {}; Expected: {}; Actual: {}".format(
        element[0][0],element[0][1],element[0][2],element[0][3],
开发者ID:Adri96,项目名称:aifh,代码行数:32,代码来源:example_iris.py


注:本文中的nolearn.lasagne.NeuralNet.train_split方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。