我有下表,想找出输入和输出之间的关系,以便作出预测
稍后我要输入加热器功率、电压、加热器效率和加热器质量的输入值,并生成输出预测
在表中您可以看到我有4个输入参数和3个输出参数
我已经创建了一个代码。输入和输出的值手动写入数组
import tensorflow as tf
import numpy as np
inputMatrix = np.array([(100,230,0.95,100),
(200,245,0.99,121),
( 40,250,0.91,123)],dtype=float)
outputMatrix = np.array([(120, 5,120),
(123,24,100),
(154, 3,121)],dtype=float)
for i,c in enumerate(inputMatrix):
print("{}Input Matrix={}Output Matrix".format(c,outputMatrix[i]))
l0 = tf.keras.layers.Dense(units = 4, input_shape = [4])
l1 = tf.keras.layers.Dense(units = 64)
l2 = tf.keras.layers.Dense(units = 128)
l3 = tf.keras.layers.Dense(units = 3)
model = tf.keras.Sequential([l0,l1,l2,l3])
model.compile(loss='mean_squared_error', optimizer=tf.keras.optimizers.Adam(0.1))
history = model.fit(inputMatrix,outputMatrix,epochs=500,verbose=False)
print("Finished training the model!")
import matplotlib.pyplot as plt
plt.xlabel('Epoch Number')
plt.ylabel('Loss Magnitude')
plt.plot(history.history['loss'])
print(model.predict(np.array([120,260,0.98,110]).reshape(1,4)))
我现在想从csv文件中自动读取表。数据应按输入、输出和读入分开
我该怎么做?在这里使用数组有意义吗?还是有更好的可能性
我怀疑我的方法是否基本正确。我的密码似乎很短。还是我必须为我的问题选择不同的方法
目前没有回答
相关问题 更多 >
编程相关推荐