导入必须的包
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')
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,)))
model
.summary
()
将建立好的模型进行编译
model
.compile(
optimizer
='adam',loss
='mse'
)
使用模型进行训练
history
= model
.fit
(x
,y
,epochs
=5000)
使用训练好的模型进行数据预测
model
.predict
(pd
.Series
([15]))
转载请注明原文地址: https://lol.8miu.com/read-8759.html