【发布时间】:2021-12-18 13:15:27
【问题描述】:
我找到的任何关于解释输出的教程或示例总是关于 keras model.predict 分类。即答案是从 0 到 1,表示属于 1 个类别或其他类别的概率。
我传递的数据量非常小
time_list = [1296000.0, 19350000.0, 29635200.0, 48294000.0, 45961200.0]
tax_list = [0.1, 0.25, 0.3, 0.35, 0.6]
price_list = [0.05, 0.1, 0.5, 0.0, 1.0]
然后最终得到这个输出
[[-0.34306246] ## prediction output
[-0.34306246]
[-0.34306246]
[-0.34306246]
[-0.34306246]]
这是对未来价格的预测还是分类尝试?我怎么能说出来?两者似乎都不合理。
完整的源代码
import numpy as np
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense, LSTM
from sklearn.preprocessing import MinMaxScaler
tf.random.set_seed(0)
# sample data
time_list = [1296000.0, 19350000.0, 29635200.0, 48294000.0, 45961200.0]
tax_list = [0.1, 0.25, 0.3, 0.35, 0.6]
price_list = [0.05, 0.1, 0.5, 0.0, 0.1]
# generate the feature matrix
X = np.hstack([np.array(time_list).reshape(- 1, 1), np.array(tax_list).reshape(- 1, 1)])
print(X.shape)
# (5, 2)
# generate the target array
Y = np.array(price_list)
print(Y.shape)
# (5,)
# reshape the features
X = X.reshape(X.shape[0], 1, X.shape[1])
print(X.shape)
# (5, 1, 2)
# define the model
model = Sequential()
model.add(LSTM(10, return_sequences=False, input_shape=( 1 , len(X[0][0]))))
model.add(Dense(1))
# compile the model
model.compile(optimizer='adam', loss='mse')
# fit the model
model.fit(X, Y, batch_size=1, epochs=10)
# generate the model predictions
pred = model.predict(X)
print(pred)
我怀疑诚实的答案可能是“对此的正确解释是您从某个数字开始,计算机添加了更多数字,而现在您只是获得了新数字。”但至少目的是什么?是在尝试将事物组织到类中,或者在不同的日子预测新价格还是其他什么?
这让我很困惑,因为我没有为模型提供要考虑的类别,也没有提供未来的日期来预测,所以它可能是什么?
【问题讨论】:
-
您的模型配置为进行回归,因此它只是近似于您训练时使用的任何标签。
-
所以用莱曼术语来说你是说它试图做一个“最合适的线”来预测未来的价格和税收?但它会预测什么日期?
-
您一直在询问“日期”,我们对此一无所知,这取决于您的标签对应于哪个“日期”。该模型没有做任何魔术,它完全按照您训练它的目的进行。
-
抱歉,time_list 是日期列表。所以如果它“近似”我的特征,我们是说它以某种方式取了我的特征的平均值吗?
-
不,我说的是 Y,模型没有对特征进行平均。
标签: tensorflow keras lstm recurrent-neural-network predict