在 Python 中实现 PatterNet,就像在 MATLAB 中一样

数据挖掘 机器学习 Python 神经网络 scikit-学习 matlab
2022-02-12 16:25:47

注意:这个问题最初是在 Cross Validated Stack Exchange 上发布的,但我被指示将其移出该网站,因为它不适合。

我是python中机器学习、神经网络实现的新手。我正在尝试 patternet 在 python 中实现,就像在 MATLAB 中一样;更具体地说是保留网络配置设置。以下是我使用 paternet(10) 时得到的结果:

    Neural Network
 
              name: 'Pattern Recognition Neural Network'
          userdata: (your custom info)
 
    dimensions:
 
         numInputs: 1
         numLayers: 2
        numOutputs: 1
    numInputDelays: 0
    numLayerDelays: 0
 numFeedbackDelays: 0
 numWeightElements: 230
        sampleTime: 1
 
    connections:
 
       biasConnect: [1; 1]
      inputConnect: [1; 0]
      layerConnect: [0 0; 1 0]
     outputConnect: [0 1]
 
    subobjects:
 
             input: Equivalent to inputs{1}
            output: Equivalent to outputs{2}
 
            inputs: {1x1 cell array of 1 input}
            layers: {2x1 cell array of 2 layers}
           outputs: {1x2 cell array of 1 output}
            biases: {2x1 cell array of 2 biases}
      inputWeights: {2x1 cell array of 1 weight}
      layerWeights: {2x2 cell array of 1 weight}
 
    functions:
 
          adaptFcn: 'adaptwb'
        adaptParam: (none)
          derivFcn: 'defaultderiv'
         divideFcn: 'divideind'
       divideParam: .trainInd, .valInd, .testInd
        divideMode: 'sample'
           initFcn: 'initlay'
        performFcn: 'crossentropy'
      performParam: .regularization, .normalization
          plotFcns: {'plotperform', plottrainstate, ploterrhist,
                    plotconfusion, plotroc}
        plotParams: {1x5 cell array of 5 params}
          trainFcn: 'trainscg'
        trainParam: .showWindow, .showCommandLine, .show, .epochs,
                    .time, .goal, .min_grad, .max_fail, .sigma,
                    .lambda
 
    weight and bias values:
 
                IW: {2x1 cell} containing 1 input weight matrix
                LW: {2x2 cell} containing 1 layer weight matrix
                 b: {2x1 cell} containing 2 bias vectors
 

我的目的不是创建确切的网络数据结构,我想主要对我的网络的不同层实现 激活功能 ,如上所述。假设我可以初始化权重(网络参数)。

我从这篇文章 开始使用深度学习和 Python 以及 多层感知器 开始。在后一个链接中,我了解到我可以通过使用库来实现 MLPclassifier MLP  sklearn.neural_network

MLPClassifier(activation='relu', alpha=1e-05, batch_size='auto',
       beta_1=0.9, beta_2=0.999, early_stopping=False,
       epsilon=1e-08, hidden_layer_sizes=(5, 2), learning_rate='constant',
       learning_rate_init=0.001, max_iter=200, momentum=0.9,
       nesterovs_momentum=True, power_t=0.5, random_state=1, shuffle=True,
       solver='lbfgs', tol=0.0001, validation_fraction=0.1, verbose=False,
       warm_start=False)

但是,它的设置并不完全是我想要的设置。阅读 MLPclassifier 文档页面并没有进一步帮助我。

如果我知道如何实现它,我将不胜感激?我很乐意被引导到已经讨论过这个问题的任何帖子或链接。

1个回答

考虑重用现有框架并添加缺少的激活函数。例如,在这里您可以看到如何在sklearn.

但是,请注意,算法的实现方式可能存在其他差异(考虑这个例子),随着深度学习和卷积网络的兴起,神经网络的多样性和复杂性都大大增加。