二层神经模型 数据集advertising
第一层模型的维数必须和输入数据的维数相同
import pandas as pd
import tensorflow as tf
data = pd.read_csv(r'C:\Users\zp\Desktop\新建文本文档 (5).txt')
x = data.iloc[:,:-1]
y = data.iloc[:,-1]
model = tf.keras.Sequential(
[tf.keras.layers.Dense(10,input_shape=(3,),activation='relu'),
tf.keras.layers.Dense(1)]
)
model.compile(optimizer='adam',loss='mse')
model.fit(x,y,epochs=800)
test = data.iloc[-10:,:-1]
print(model.predict(test))
结果
[[10.534118 ]
[ 7.598111 ]
[ 6.253477 ]
[19.597713 ]
[17.233036 ]
[ 4.2911315]
[ 6.849201 ]
[11.427596 ]
[25.407898 ]
[13.568398 ]]