如何在MLPClassifier中设置初始权重? [英] How to set initial weights in MLPClassifier?

查看:728
本文介绍了如何在MLPClassifier中设置初始权重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到设置神经网络初始权重的方法,有人可以告诉我如何吗? 我正在使用python包sklearn.neural_network.MLPClassifier.

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.

以下是参考代码:

from sklearn.neural_network import MLPClassifier
classifier = MLPClassifier(solver="sgd")
classifier.fit(X_train, y_train)

推荐答案

The docs show you the attributes in use.

属性:
...

Attributes:
...

coefs_:列表,长度n_layers-1 列表中的第i个元素表示与>第i层相对应的权重矩阵.

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

intercepts_:列表,长度n_layers-1 列表中的第ith个元素表示对应于> i + 1层的偏置向量.

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

只需构建您的分类器clf=MLPClassifier(solver="sgd"),并在调用clf.fit()之前设置coefs_intercepts_.

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

唯一剩下的问题是:sklearn会覆盖您的init吗?

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

代码看起来像:

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

在我看来,这不会取代您指定的coefs_(您也可以检查偏差).

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

打包和解包功能进一步表明这应该可行.这些可能在内部用于通过pickle进行序列化.

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

这篇关于如何在MLPClassifier中设置初始权重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆