当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
k9s-终端UI工具
MySQL最左前缀原则【我看懂了hh】
postgres 递归查询
SQl练习 2022/6/29
TensorFlow2 study notes: 5. Common activation functions
Install dlib step pit record, error: WARNING: pip is configured with locations that require TLS/SSL
【CV-Learning】卷积神经网络预备知识
flink-sql查询配置与性能优化参数详解
(五)栈及其应用
Zend FrameWork RCE1
flink onTimer定时器实现定时需求
MySql--存储引擎以及索引
sklearn中的pipeline机制
Kubernetes集群安装
【CV-Learning】线性分类器(SVM基础)
IvNWJVPMLt
【CV-Learning】卷积神经网络
(TensorFlow)——tf.variable_scope和tf.name_scope详解
VScode配置PHP环境
【深度学习21天学习挑战赛】0、搭建学习环境









