【发布时间】:2020-07-01 13:51:57
【问题描述】:
我在 youtube 上观看了一个教程,并尝试根据我的需要调整源文本。是否允许链接到视频?
在教程中有一个输入数组,其中一行 3 列用数字 (1,2,3) 填充。还有一个相同大小的输出张量,也填充了三个数字(1,2,6)。数字之间的关系是学习的。在教程中,AI 认识到:输出 = 输入^2 并做出预测,例如 4 --> 8。
我想尝试使用数组进行预测。
我有几个测量值: 水:10、11、15、2 温度:2、5、17、4 速度:3、7、6、1
这包括以下值(计算值(来自测量值)): A = 1、5、7、4 B = 2, 4, 1, 5
我想预测A = 6 AND B = 3情况下的测量值
我已经尝试了很多东西。 在我看来,我在第一个神经元层上犯了一个错误:layer.dense(单位和形状)和命令 model.predict(数组维度)
import numpy as np
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.utils import np_utils
#the model from the tutorial
#model = keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
#my model
model = keras.Sequential([
keras.layers.Dense(units=3, input_shape=[2]), # units=???=colums from input_array? input_shape=?
keras.layers.Dense(units=128),
keras.layers.Dense(units=1)
])
#model.compile from the tutorial
model.compile(optimizer='sgd', loss='mean_squared_error')
#xs=[1, 2, 3] #input_array from tutorial
#ys=[2, 4, 6] #output_array from tutorial
#my output array
output_array = ( [10, 11, 15, 2], #Water, array shape = (3,4) ndim = Dimension = 2
[2, 5, 17, 4], #Temperature
[3, 7, 6, 1] #Speed
)
#my input array
input_array = (
[1, 5, 7, 4], #A
[2, 4, 1, 5], #B
)
#model.fit from the tutorial - I use the same one
model.fit(output_array, input_array, epochs=500)
print(model.predict([6],[3]))
我会很高兴得到帮助和一些源文本。
谢谢,罗科
【问题讨论】:
标签: python tensorflow machine-learning keras tf.keras