当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
自动化运维工具Ansible(3)PlayBook
k3s-轻量级Kubernetes
flink-sql查询配置与性能优化参数详解
逻辑回归---简介、API简介、案例:癌症分类预测、分类评估法以及ROC曲线和AUC指标
VScode配置PHP环境
TensorFlow2 study notes: 4. The first neural network model, iris classification
【CV-Learning】目标检测&实例分割
flink-sql自定义函数
Commons Collections2
智能合约安全——delegatecall (2)
TensorFlow2 study notes: 5. Common activation functions
with recursive用法
Th in thymeleaf: href use notes
PHP课堂笔记(一)
剑指 Offer 2022/7/2
RecyclerView的用法
flink-sql所有语法详解
SQl练习 2022/6/29
TensorFlow2学习笔记:6、过拟合和欠拟合,及其缓解方案
完美解决keyby造成的数据倾斜导致吞吐量降低的问题









