简体   繁体   English

Keras LSTM 输入和输出变量范围

[英]Keras LSTM input and output variable ranges

I am fairly new to machine learning but I have put together a LSTM network for educational purposes that seems to be working fairly well.我对机器学习还很陌生,但我已经建立了一个用于教育目的的 LSTM 网络,该网络似乎运行良好。

I have not been able to fully understand the numerical ranges for input and output variables.我一直无法完全理解输入和输出变量的数值范围。 I normalized my input and training data so all variables are centered at 0 with a standard deviation of 1. When I test the network, all of my predictions are positive between 0 and 1, there are never any negative values even though the training data contained negative values.我标准化了我的输入和训练数据,所以所有变量都以 0 为中心,标准差为 1。当我测试网络时,我的所有预测在 0 和 1 之间都是正值,即使训练数据包含负值。

I have worked around this by creating one output for positive numbers and another for negative in my training data.我通过在训练数据中为正数创建一个输出,为负数创建另一个输出来解决这个问题。 For example:例如:

Original training data:原始训练数据:

data
-1.0
-0.5
0.0
0.5
1.0

becomes:变成:

pos_data   neg_data
0.0        1.0
0.0        0.5
0.0        0.0
0.5        0.0
1.0        0.0

After I run the model, I convert the pos_data and neg_data back to a single column with positive and negative values.运行模型后,我将 pos_data 和 neg_data 转换回具有正值和负值的单个列。 This seems to work, but feels like it should be unnecessary.这似乎有效,但感觉应该没有必要。

Does Keras allow negative values in the input or training data? Keras 是否允许输入或训练数据中出现负值? If so, does anyone have any ideas why I would only be getting positive predictions when the model was trained with both positive and negative values?如果是这样,有没有人知道为什么当模型同时使用正值和负值进行训练时我只会得到正预测?

Thank you!谢谢!

Does Keras allow negative values in the input or training data? Keras 是否允许输入或训练数据中出现负值?

Yes, a good example would be BERT word embeddings while doing natural language processing.是的,一个很好的例子是在进行自然语言处理时 BERT 词嵌入。 Some data scalers are on the interval -1 to 1一些数据缩放器的区间为 -1 到 1

If so, does anyone have any ideas why I would only be getting positive predictions when the model was trained with both positive and negative values?如果是这样,有没有人知道为什么当模型同时使用正值和负值进行训练时我只会得到正预测?

If your model is a single LSTM cell then your output is run through softmax before you are given your output.如果您的模型是单个 LSTM 单元,那么您的输出会在您获得输出之前通过 softmax 运行。

在此处输入图片说明

Image Provided by Rosand Liu 图片由 Rosand Liu 提供

The range of the softmax function is between 0 and 1. Which would explain why you are getting only positive values! softmax 函数的范围在 0 和 1 之间。这就解释了为什么你只得到正值!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM