Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Keras序列模型训练的Nan损失_Python 3.x_Tensorflow_Machine Learning_Keras_Neural Network - Fatal编程技术网

Python 3.x Keras序列模型训练的Nan损失

Python 3.x Keras序列模型训练的Nan损失,python-3.x,tensorflow,machine-learning,keras,neural-network,Python 3.x,Tensorflow,Machine Learning,Keras,Neural Network,我有一个Tensorflow序列网络,它在训练期间始终返回Nan的损失值。 我用的是熊猫和凯拉 数据的一个例子是: Actual_GP1 Budgeted_GP_Value_Cleanup Budgeted_GP_Value_New \ 0 2.0 2.0 95.00 1 2.0 2.0 6368

我有一个Tensorflow序列网络,它在训练期间始终返回Nan的损失值。 我用的是熊猫和凯拉

数据的一个例子是:

Actual_GP1  Budgeted_GP_Value_Cleanup  Budgeted_GP_Value_New  \
0          2.0                        2.0                  95.00   
1          2.0                        2.0               63684.55   
3          2.0                        2.0               26022.57   
4          2.0                        2.0              440759.17   
6          2.0                        2.0                  95.00   
7          2.0                        2.0             3519120.00   
9          2.0                        2.0                   4.00   
12         2.0                        2.0                   4.00   
13         2.0                        2.0              355960.00   
14         2.0                        2.0               62745.00  



Costing_Date  Created_Time  Date_Time_16  Delivery_Date  Engineering_Date  \
0              4      1.579523           4.0            4.0                 4   
1              4      1.575390           4.0            4.0                 4   
3              4      1.575471           4.0            4.0                 4   
4              4      1.575020           4.0            4.0                 4   
6              4      1.579508           4.0            4.0                 4   
7              4      1.578304           4.0            4.0                 4   
9              4      1.574600           4.0            4.0                 4   
12             4      1.570805           4.0            4.0                 4   
13             4      1.573831           4.0            4.0                 4   
14             4      1.576153           4.0            4.0                 4   

Exchange_Rate     GP  ...  Last_Activity_Time  Modified_Time  \
0             2.0  100.0  ...            4.000000       1.579523   
1             2.0   30.0  ...            1.579519       1.579519   
3             2.0   44.0  ...            1.579516       1.579516   
4             2.0   37.0  ...            1.579516       1.579516   
6             2.0  100.0  ...            4.000000       1.579508   
7             2.0   44.0  ...            1.579507       1.579507   
9             2.0  100.0  ...            1.579506       1.579506   
12            2.0   32.0  ...            1.579506       1.579506   
13            2.0   44.0  ...            1.579506       1.579506   
14            2.0   44.5  ...            1.579506       1.579506   

Next_step_actioned_by   PO_Date   PO_Week  Production_End_Date  \
0                     4.0  1.580429  4.000000                    4   
1                     4.0  1.579824  1.579478                    4   
3                     4.0  1.575850  1.575850                    4   
4                     4.0  1.575418  1.575245                    4   
6                     4.0  1.580429  4.000000                    4   
7                     4.0  1.583798  1.583798                    4   
9                     4.0  1.579219  1.578874                    4   
12                    4.0  1.580429  1.580083                    4   
13                    4.0  1.585613  1.585526                    4   
14                    4.0  1.580429  1.580083                    4   

Production_Start_Date  Project_Value  Prototype_Date  \
0                       4          95.00               4   
1                       4      212281.82               4   
3                       4           3.00               4   
4                       4           4.00               4   
6                       4          95.00               4   
7                       4     7998000.00               4   
9                       4           4.00               4   
12                      4           4.00               4   
13                      4      809000.00               4   
14                      4      141000.00               4   

Revenue_Forecast_Probability_Weighting  
0                                      1.0  
1                                      2.0  
3                                      3.0  
4                                      4.0  
6                                      1.0  
7                                      5.0  
9                                      4.0  
12                                     4.0  
13                                     7.0  
14                                     8.0  
据我所知,此示例中的一些日期是分类标记的,但这是由于缺少值。 这个模型的目标值是成功的概率,这是基于历史数据的,我没有考虑这个问题。这是一个值[0100]。 网络配置为:

dataset=tf.data.Dataset.from_tensor_slices((df.values, target.values))
train_dataset=dataset.shuffle(len(df)).batch(1)
print(df.shape)
def get_compiled_model():
    model = tf.keras.Sequential([
    tf.keras.layers.Dense(24, activation='relu', input_shape=(df.shape[-1],)),
    tf.keras.layers.Dense(16, activation='relu'),
    tf.keras.layers.Dense(8, activation='relu'),
    tf.keras.layers.Dense(1, activation='sigmoid')
    ])


    model.compile(optimizer='adam', loss='mse',metrics=['accuracy'])

    return model
model=get_compiled_model()
model.fit(train_dataset, epochs=20)
model.save("keras_saved_model.h5")
输出为

(574, 24)
WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
Train on 574 steps

Epoch 1/20
574/574 [==============================] - 2s 3ms/step - loss: nan - acc: 0.3275
Epoch 2/20
574/574 [==============================] - 1s 1ms/step - loss: nan - acc: 0.6655
Epoch 3/20
574/574 [==============================] - 1s 1ms/step - loss: nan - acc: 0.6655
Epoch 4/20
574/574 [==============================] - 1s 1ms/step - loss: nan - acc: 0.6655
Epoch 5/20
574/574 [==============================] - 1s 1ms/step - loss: nan - acc: 0.6655
Epoch 7/20
574/574 [==============================] - 1s 1ms/step - loss: nan - acc: 0.6655
and so on. 
请有人给我指出正确的方向,关于这个一致的准确性和这些零损失值

编辑: 解决方案是将目标值除以100,使其适合范围[0,1],因为最终激活层是一个sigmoid函数。
感谢您指出这一点

在这里为社区提供答案,即使答案在评论部分提供

由于目标值在[0100]范围内,因此用户通过将其除以100来规范化该值,并使用了sigmoid激活功能,从而解决了该问题。
您可以使用以下代码为特征应用规格化功能

要获取数值列的最小值和最大值,请执行以下操作:

def _z_score_params(column):
    mean = traindf[column].min()
    std = traindf[column].max()
    return {'min': min, 'max': max}


def zscore(col):

  min_value = _z_score_params(col)[min]
  max_value = _z_score_params(col)[max]
  return (col - min_value)/max_value 

feature_name = ‘column_name_to_normalize’
normalized_feature = tf.feature_column.numeric_column(
  feature_name,
  normalizer_fn=zscore) 

在这里为社区提供答案,即使答案在评论部分提供

由于目标值在[0100]范围内,因此用户通过将其除以100来规范化该值,并使用了sigmoid激活功能,从而解决了该问题。
您可以使用以下代码为特征应用规格化功能

要获取数值列的最小值和最大值,请执行以下操作:

def _z_score_params(column):
    mean = traindf[column].min()
    std = traindf[column].max()
    return {'min': min, 'max': max}


def zscore(col):

  min_value = _z_score_params(col)[min]
  max_value = _z_score_params(col)[max]
  return (col - min_value)/max_value 

feature_name = ‘column_name_to_normalize’
normalized_feature = tf.feature_column.numeric_column(
  feature_name,
  normalizer_fn=zscore) 

目标值真的在[01100]范围内吗?由于在输出(范围[0,1])处有一个sigmoid激活,因此范围不匹配,梯度可能很大,请确保网络可以输出标签的范围。目标值是否真的在范围[0,100]内?由于在输出(范围[0,1])处有一个sigmoid激活,因此范围不匹配,梯度可能很大,请确保网络可以输出标签的范围。