当前位置:网站首页>TensorFlow2 study notes: 8. tf.keras implements linear regression, Income dataset: years of education and income dataset
TensorFlow2 study notes: 8. tf.keras implements linear regression, Income dataset: years of education and income dataset
2022-08-04 06:05:00 【Live up to [email protected]】
1、Income数据集
IncomeThe dataset is machine learning、Typical learning data for linear regression in a deep learning experiment:下载Income数据集
It mainly has two types of data,受教育年限和对应的收入情况
It can be observed by the scatter plot,apparently linear relationship
数据预览:
散点图:
2、创建模型
2.1导入数据、定义特征和标签
import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv("./Income.csv")
# Define input featuresx 和对应标签y
x=data.Education
y=data.Income
2.2创建模型
#顺序模型:只有一个输入和一个输出.tf.keras.Sequential()is a sequential model
model=tf.keras.Sequential() #初始化模型
model.add(tf.keras.layers.Dense(1,input_shape=(1,))) #添加层
model.compile(optimizer='adam',loss='mse') # Configure training items mse均方差 梯度优化Adam
通过:model.summary()
function to look at the model
3、训练模型
model.fit(x,y,epochs=500)
#x y Feed the data features and labels defined above epochsis the number of training iterations
训练结果:
4、完整代码
import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv("./Income.csv")
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')
h=model.fit(x,y,epochs=500)
版权声明
本文为[Live up to [email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/216/202208040525327517.html
边栏推荐
猜你喜欢
随机推荐
Polynomial Regression (PolynomialFeatures)
【深度学习21天学习挑战赛】3、使用自制数据集——卷积神经网络(CNN)天气识别
k3s-轻量级Kubernetes
【go语言入门笔记】13、 结构体(struct)
(六)递归
【深度学习21天学习挑战赛】0、搭建学习环境
BUUCTF——MISC(一)
自动化运维工具Ansible(3)PlayBook
自动化运维工具Ansible(4)变量
AIDL communication between two APPs
yolov3中数据读入(一)
oracle的number与postgresql的numeric对比
Zend FrameWork RCE1
(十二)树--哈夫曼树
对象存储-分布式文件系统-MinIO-1:概念
Commons Collections2
CAS与自旋锁、ABA问题
Delphi-C side interesting menu operation interface design
SQL的性能分析、优化
TensorFlow2学习笔记:4、第一个神经网模型,鸢尾花分类