variant_scaling_initializer()得到了意外的关键字参数'distribution'

时间:2018-08-27 04:25:55

标签: python-3.x tensorflow scikit-learn jupyter-notebook sklearn-pandas

在这里,我想使用python预测相同的时间值(回归神经网络)。在这里,我有两个输出和三个输入。当我运行代码时,它给我一个错误“ variance_scaling_initializer()得到了意外的关键字参数'distribution'”。您能帮我解决问题吗? 在这里,我上传了我的代码,

n_neurons_1 = 24
n_neurons_2 = 12
n_target = 2
softmax = 2
weight_initializer = tf.contrib.layers.variance_scaling_initializer(mode= "FAN_AVG", distribution ="uniform", scale = softmax)
bias_initializer = tf.zeros_initializer()
w_hidden_1 = tf.Variable(weight_initializer([n_time_dimensions,n_neurons_1]))
bias_hidden_1= tf.Variable(bias_initializer([n_neurons_1]))
w_hidden_2= tf.Variable(weight_initializer([n_neurons_1,n_neurons_2]))
bias_hidden_2 = tf.Variable(bias_initializer([n_neurons_2]))
w_out = tf.Variable(weight_initializer([n_neurons_2,2]))
bias_out = tf.Variable(bias_initializer([2]))

                        
hidden_1 = tf.nn.relu(tf.add(tf.matmul(X, w_hidden_1),bias_hidden_1))
hidden_2 = tf.nn.relu(tf.add(tf.matmul(X, w_hidden_2),bias_hidden_2))

out = tf.transpose(tf.add(tf.matmul(hidden_2, w_out),bias_out))

我的数据集是

date	       time g	   p	c	apparentg
6/8/2018	0:06:15	141	131	136	141
6/8/2018	0:09:25	95	117	95	95
6/8/2018	0:11:00	149	109	139	149
6/8/2018	0:13:50	120	103	95	120
6/8/2018	0:16:20	135	97	105	135
6/8/2018	0:19:00	63	NaN	97	63
6/8/2018	0:20:00	111	NaN	100	111
6/8/2018	0:22:10	115	NaN	115	115
6/8/2018	0:23:40	287	NaN	NaN	287
错误是

TypeError                                 Traceback (most recent call last)
<ipython-input-26-9ceeb97429b1> in <module>()
     31 n_target = 2
     32 softmax = 2
---> 33 weight_initializer = tf.contrib.layers.variance_scaling_initializer(mode= "FAN_AVG", distribution ="uniform", scale = softmax)
     34 bias_initializer = tf.zeros_initializer()
     35 w_hidden_1 = tf.Variable(weight_initializer([n_time_dimensions,n_neurons_1]))

TypeError: variance_scaling_initializer() got an unexpected keyword argument 'distribution'

1 个答案:

答案 0 :(得分:1)

查看文档https://www.tensorflow.org/api_docs/python/tf/contrib/layers/variance_scaling_initializer

DECLARE
   curSel SYS_REFCURSOR;
BEGIN
   OPEN curSel FOR ...;
   sqldynamic(curSel);

END;

tf.contrib.layers.variance_scaling_initializer(
    factor=2.0,
    mode='FAN_IN',
    uniform=False,
    seed=None,
    dtype=tf.float32
)

所以尝试

uniform: Whether to use uniform or normal distributed random initialization.

代替

uniform = True

在函数调用中

distribution ="uniform"

该函数中似乎也没有 tf.contrib.layers.variance_scaling_initializer(mode= "FAN_AVG", distribution ="uniform", scale = softmax) 属性。