导入必须的包 import tensorflow as tf import matplotlib.pyplot as plt %matplotlib inline import pandas as pd 导入测试数据 data = pd.read_csv('E:\\pycharm_Projects\\test\\dataset\\Income1.csv') #print(data) plt.scatter(data.Education,data.Income) 定义x、y变量 x=data.Education y=data.Income 建立顺序模型 #顺序模型 model = tf.keras.Sequential() model.add(tf.keras.layers.Dense(1,input_shape=(1,))) #输出维度为1,输入维度为1 model.summary() #查看建立模型的详细信息 将建立好的模型进行编译 model.compile( optimizer='adam',loss='mse' ) 使用模型进行训练 history = model.fit(x,y,epochs=5000) 使用训练好的模型进行数据预测 model.predict(pd.Series([15]))