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


Python trainers.BackpropTrainer方法代码示例

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


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

示例1: get_nn

# 需要导入模块: from pybrain.supervised import trainers [as 别名]
# 或者: from pybrain.supervised.trainers import BackpropTrainer [as 别名]
def get_nn(self, train=True):

        train_data, results_data = self.get_train_and_test_data()
        DS = self.create_DS(train_data)

        try:
            import arac  # noqa
            print("ARAC Available, using fast mode network builder!")
            FNN = buildNetwork(DS.indim, self.hiddenneurons, DS.outdim, bias=self.bias, recurrent=self.recurrent,
                               fast=True)
        except ImportError:
            FNN = buildNetwork(DS.indim, self.hiddenneurons, DS.outdim, bias=self.bias, recurrent=self.recurrent)
        FNN.randomize()

        TRAINER = BackpropTrainer(FNN, dataset=DS, learningrate=self.learningrate,
                                  momentum=self.momentum, verbose=False, weightdecay=self.weightdecay)

        if train:
            for i in range(self.epochs):
                TRAINER.train()

        self.nn = FNN
        return FNN 
开发者ID:owocki,项目名称:pytrader,代码行数:25,代码来源:models.py

示例2: fitANN

# 需要导入模块: from pybrain.supervised import trainers [as 别名]
# 或者: from pybrain.supervised.trainers import BackpropTrainer [as 别名]
def fitANN(data):
    '''
        Build a neural network regressor
    '''
    # determine the number of inputs and outputs
    inputs_cnt = data['input'].shape[1]
    target_cnt = data['target'].shape[1]

    # create the regressor object
    ann = pb.buildNetwork(inputs_cnt, 
        inputs_cnt * 3,
        target_cnt,
        hiddenclass=st.TanhLayer,
        outclass=st.LinearLayer,
        bias=True
    )

    # create the trainer object
    trainer = tr.BackpropTrainer(ann, data, 
        verbose=True, batchlearning=False)

    # and train the network
    trainer.trainUntilConvergence(maxEpochs=50, verbose=True, 
        continueEpochs=2, validationProportion=0.25)

    # and return the regressor
    return ann

# the file name of the dataset 
开发者ID:drabastomek,项目名称:practicalDataAnalysisCookbook,代码行数:31,代码来源:regression_ann.py

示例3: fitANN

# 需要导入模块: from pybrain.supervised import trainers [as 别名]
# 或者: from pybrain.supervised.trainers import BackpropTrainer [as 别名]
def fitANN(data):
    '''
        Build a neural network classifier
    '''
    # determine the number of inputs and outputs
    inputs_cnt = data['input'].shape[1]
    target_cnt = data['target'].shape[1]

    # create the classifier object
    ann = pb.buildNetwork(inputs_cnt, 
        inputs_cnt * 2,  
        inputs_cnt / 2,
        target_cnt,
        hiddenclass=st.SigmoidLayer,
        outclass=st.SoftmaxLayer,
        bias=True
    )

    # create the trainer object
    trainer = tr.BackpropTrainer(ann, data, 
        verbose=True, batchlearning=False)

    # and train the network
    trainer.trainUntilConvergence(maxEpochs=50, verbose=True, 
        continueEpochs=3, validationProportion=0.25)

    # and return the classifier
    return ann

# the file name of the dataset 
开发者ID:drabastomek,项目名称:practicalDataAnalysisCookbook,代码行数:32,代码来源:classification_ann_alternative.py

示例4: fitANN

# 需要导入模块: from pybrain.supervised import trainers [as 别名]
# 或者: from pybrain.supervised.trainers import BackpropTrainer [as 别名]
def fitANN(data):
    '''
        Build a neural network classifier
    '''
    # determine the number of inputs and outputs
    inputs_cnt = data['input'].shape[1]
    target_cnt = data['target'].shape[1]

    # create the classifier object
    ann = pb.buildNetwork(inputs_cnt, 
        inputs_cnt * 2, 
        target_cnt,
        hiddenclass=st.TanhLayer,
        outclass=st.SoftmaxLayer,
        bias=True
    )

    # create the trainer object
    trainer = tr.BackpropTrainer(ann, data, 
        verbose=True, batchlearning=False)

    # and train the network
    trainer.trainUntilConvergence(maxEpochs=50, verbose=True, 
        continueEpochs=3, validationProportion=0.25)

    # and return the classifier
    return ann

# the file name of the dataset 
开发者ID:drabastomek,项目名称:practicalDataAnalysisCookbook,代码行数:31,代码来源:classification_ann.py

示例5: learn

# 需要导入模块: from pybrain.supervised import trainers [as 别名]
# 或者: from pybrain.supervised.trainers import BackpropTrainer [as 别名]
def learn(self, train_data = None, seed = None):
        """
    Performs single run training, and it is designed to be called after network instantiation.

    ----------

    train_data: pandas Dataframe
            It needs to contain datetime objects on index, and both features and target variables.
            The target variables need to end with the suffix "_tau". If None the self.train_set
            variable passed at the moment of instantiation will be used.

    Returns: tuple(MP_Pybrain object,float)
            It returns the model with the lowest training error, and the value of the training error.

        """
        if train_data is not None:
            self.train_set = train_data
            self.randomize()
        ds_train, ds_valid = self._build_dataset(self.train_set)
        trainer = BackpropTrainer(self.N, ds_train, learningrate=self.learning_rate,
                                  momentum=self.momentum,batchlearning=self.batch)
        trainer.train()
        e_train = [self._error(ds_train)]
        e_valid = [self._error(ds_valid)]
        final_model = copy(self)
        fin_error_train = e_train[0]
        fin_error_valid = e_valid[0]
        for i in range(1,self.epochs):
            if i%10 == 0:
                print "epoch: ", i
            trainer.train()
            e_train.append(self._error(ds_train))
            e_valid.append(self._error(ds_valid))
            if e_train[-1] < fin_error_train:
                final_model = deepcopy(self)
                fin_error_train = e_train[-1]
                fin_error_valid = e_valid[-1]
        return final_model, fin_error_train, fin_error_valid 
开发者ID:Ambrosys,项目名称:climatelearn,代码行数:40,代码来源:pybrain_MP.py

示例6: fit_predict

# 需要导入模块: from pybrain.supervised import trainers [as 别名]
# 或者: from pybrain.supervised.trainers import BackpropTrainer [as 别名]
def fit_predict(xTrain,yTrain,xTest,epochs,neurons):

  # Check edge cases
  if (not len(xTrain) == len(yTrain) or len(xTrain) == 0 or 
    len(xTest) == 0 or epochs <= 0):
    return

  # Randomize the training data (probably not necessary but pybrain might
  # not shuffle the data itself, so perform as safety check)
  indices = np.arange(len(xTrain))
  np.random.shuffle(indices)

  trainSwapX = [xTrain[x] for x in indices]
  trainSwapY = [yTrain[x] for x in indices]

  supTrain = SupervisedDataSet(len(xTrain[0]),1)
  for x in range(len(trainSwapX)):
    supTrain.addSample(trainSwapX[x],trainSwapY[x])

  # Construct the feed-forward neural network

  n = FeedForwardNetwork()

  inLayer = LinearLayer(len(xTrain[0]))
  hiddenLayer1 = SigmoidLayer(neurons)
  outLayer = LinearLayer(1)

  n.addInputModule(inLayer)
  n.addModule(hiddenLayer1)
  n.addOutputModule(outLayer)

  in_to_hidden = FullConnection(inLayer, hiddenLayer1)
  hidden_to_out = FullConnection(hiddenLayer1, outLayer)
  
  n.addConnection(in_to_hidden)
  n.addConnection(hidden_to_out)

  n.sortModules() 

  # Train the neural network on the training partition, validating
  # the training progress on the validation partition

  trainer = BackpropTrainer(n,dataset=supTrain,momentum=0.1,learningrate=0.01
    ,verbose=False,weightdecay=0.01)
  
  trainer.trainUntilConvergence(dataset=supTrain,
    maxEpochs=epochs,validationProportion=0.30)

  outputs = []
  for x in xTest:
    outputs.append(n.activate(x))

  return outputs 
开发者ID:lbenning,项目名称:Load-Forecasting,代码行数:55,代码来源:neural.py

示例7: build_network

# 需要导入模块: from pybrain.supervised import trainers [as 别名]
# 或者: from pybrain.supervised.trainers import BackpropTrainer [as 别名]
def build_network():

    # get iris data
    iris = datasets.load_iris()
    d,t = iris.data, iris.target

    # build dataset
    ds = _get_classification_dataset()
    for i in range(len(d)):
        ds.addSample(d[i],t[i])

    print "Dataset input: {}".format(ds['input'])
    print "Dataset output: {}".format(ds['target'])
    print "Dataset input length: {}".format(len(ds['input']))
    print "Dataset output length: {}".format(len(ds['target']))
    print "Dataset length: {}".format(len(ds))
    print "Dataset input|output dimensions are {}|{}".format(ds.indim, ds.outdim)

    # split dataset
    train_data,test_data = _split_with_proportion(ds, 0.70)
    
    print "Train Data length: {}".format(len(train_data))
    print "Test Data length: {}".format(len(test_data))

    # encode with one output neuron per class
    train_data._convertToOneOfMany()
    test_data._convertToOneOfMany()

    print "Train Data input|output dimensions are {}|{}".format(train_data.indim, train_data.outdim)
    print "Test Data input|output dimensions are {}|{}".format(test_data.indim, test_data.outdim)

    # build network
    network = buildNetwork(INPUT,HIDDEN,CLASSES,outclass=SoftmaxLayer)

    # train network
    trainer = BackpropTrainer(network,dataset=train_data,momentum=0.1,verbose=True,weightdecay=0.01)
    trainer.trainOnDataset(train_data, 500)

    print "Total epochs: {}".format(trainer.totalepochs)

    # test network
    output = network.activateOnDataset(test_data).argmax(axis=1)
    
    print "Percent error: {}".format(percentError(output, test_data['class']))

    # return network
    return network

# classify data against neural network 
开发者ID:rdmilligan,项目名称:SaltwashAR,代码行数:51,代码来源:neuralnetwork.py

示例8: build_network

# 需要导入模块: from pybrain.supervised import trainers [as 别名]
# 或者: from pybrain.supervised.trainers import BackpropTrainer [as 别名]
def build_network(inputs,targets):

    # build dataset
    ds = _get_classification_dataset()
    for i in range(len(inputs)):
        ds.addSample(inputs[i],targets[i])

    print "Dataset input: {}".format(ds['input'])
    print "Dataset output: {}".format(ds['target'])
    print "Dataset input length: {}".format(len(ds['input']))
    print "Dataset output length: {}".format(len(ds['target']))
    print "Dataset length: {}".format(len(ds))
    print "Dataset input|output dimensions are {}|{}".format(ds.indim, ds.outdim)

    # split dataset
    train_data,test_data = _split_with_proportion(ds, 0.70)
    
    print "Train Data length: {}".format(len(train_data))
    print "Test Data length: {}".format(len(test_data))

    # encode with one output neuron per class
    train_data._convertToOneOfMany()
    test_data._convertToOneOfMany()

    print "Train Data input|output dimensions are {}|{}".format(train_data.indim, train_data.outdim)
    print "Test Data input|output dimensions are {}|{}".format(test_data.indim, test_data.outdim)

    # build network
    network = buildNetwork(INPUT,HIDDEN,CLASSES,outclass=SoftmaxLayer)

    # train network
    trainer = BackpropTrainer(network,dataset=train_data,momentum=0.1,verbose=True,weightdecay=0.01)
    trainer.trainUntilConvergence(dataset=train_data,maxEpochs=500)

    print "Total epochs: {}".format(trainer.totalepochs)

    # test network
    output = network.activateOnDataset(test_data).argmax(axis=1)
    
    print "Percent error: {}".format(percentError(output, test_data['class']))

    # return network
    return network

# classify input against neural network 
开发者ID:rdmilligan,项目名称:SaltwashAR,代码行数:47,代码来源:neuralnetwork.py


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