[英]Neural Network in python: WARNING:tensorflow:Model was constructed with shape (None, 7) for input
i have data that 60 rows and nine columns from xlsx (8 columns for x and 1 columns for y).我有来自 xlsx 的 60 行和 9 列的数据(x 为 8 列,y 为 1 列)。 i devided it to data training 80% and data testing 20%.
我将其分为 80% 的数据训练和 20% 的数据测试。 so i have 12 for testing and 48 for training.
所以我有 12 个用于测试,48 个用于培训。 so i have x test, y test, x train and y train.
所以我有 x 测试,y 测试,x 训练和 y 训练。 i use neural network in python and i have this code
我在 python 中使用神经网络,我有这个代码
import tensorflow as tf
from tensorflow.keras.optimizers import Adam
model = tf.keras.models.Sequential()
adam = Adam(learning_rate=0.01)
model.add(tf.keras.layers.Dense(units=8, activation='relu')) #input ada sembilan belas
model.add(tf.keras.layers.Dense(units=4, activation='relu')) #hidden layer 19 node
model.add(tf.keras.layers.Dense(units=1, activation='linear')) #output layer tidak menggunakan aktivasi
model.compile(loss='mae', optimizer=adam)
model.fit(x_train_CWA, y_train_CWA, epochs=1000)
then i predict x test with this code然后我用这段代码预测 x 测试
y_pred_CWA=model.predict(x_test_CWA)
After that i can predict thats data then, i want to input a new data with this code之后我可以预测那个数据,我想用这个代码输入一个新数据
A = float(input("A : "))
B = float(input("B: "))
C = float(input("C: "))
D = float(input ("D: "))
E = float(input ("E : "))
F = float(input ("F: "))
G = float(input ("G: "))
H = float(input ("H"))
then i entering new data and i want to predict the new data so i array the input data with this code然后我输入新数据,我想预测新数据,所以我用这段代码排列输入数据
Prediction_CWA = np.array([A, B, C, D, E, F, G, H])
Then i predict with this code然后我用这段代码预测
CWA_Prediction = model.predict(Prediction_CWA)
but i found an error like this但我发现了这样的错误
ValueError: Exception encountered when calling layer "sequential_11" (type Sequential).
Input 0 of layer "dense_25" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (None,)
Call arguments received:
• inputs=tf.Tensor(shape=(None,), dtype=float32)
• training=False
• mask=None
when using model.predict for a SINGLE prediction you need to expand the dimensions of the array to provide for the batch dimension so try当使用 model.predict 进行 SINGLE 预测时,您需要扩展数组的维度以提供批量维度,因此请尝试
Prediction_CWA = np.expand_dims(Prediction_CWA, axis=0)
then do model.predict然后做 model.predict
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.