How to set initial weights in MLPClassifier?

后端 未结 3 1949
無奈伤痛
無奈伤痛 2021-01-02 08:07

I cannot find a way to set the initial weights of the neural network, could someone tell me how please? I am using python package sklearn.neural_network.MLPClassifier.

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-02 08:44

    The docs show you the attributes in use.

    Attributes:
    ...

    coefs_ : list, length n_layers - 1 The ith element in the list represents the weight matrix corresponding to > layer i.

    intercepts_ : list, length n_layers - 1 The ith element in the list represents the bias vector corresponding to layer > i + 1.

    Just build your classifier clf=MLPClassifier(solver="sgd") and set coefs_ and intercepts_ before calling clf.fit().

    The only remaining question is: does sklearn overwrite your inits?

    The code looks like:

        if not hasattr(self, 'coefs_') or (not self.warm_start and not
                                           incremental):
            # First time training the model
            self._initialize(y, layer_units)
    

    This looks to me like it won't replace your given coefs_ (you might check biases too).

    The packing and unpacking functions further indicates that this should be possible. These are probably used for serialization through pickle internally.

提交回复
热议问题