当前位置:网站首页>tensorflow实现线性方程的参数调整
tensorflow实现线性方程的参数调整
2022-08-09 10:39:00 【qq_26391203】
import tensorflow as tf
import numpy as np
#create data
x_data=np.random.rand(100).astype(np.float32)
y_data=x_data*0.1+0.3 #目标结果
#create tensorflow structure start
Weights=tf.Variable(tf.random_uniform([1],-1.0,1.0))
biases=tf.Variable(tf.zeros([1])) # 权重和偏值从初始值开始不断学习,靠近目标值
y=Weights*x_data+biases
loss=tf.reduce_mean(tf.square(y-y_data))# 均方差
optimizer=tf.train.GradientDescentOptimizer(0.5)
train=optimizer.minimize(loss)
init=tf.initialize_all_variables()
# create tensorflow structure end
sess=tf.Session()
sess.run(init) #指向处理的地方
for step in range(201):
sess.run(train)
if step%20==0:
print(step,sess.run(Weights),sess.run(biases))
实验结果:
如上所示最终实验结果表明Weight接近目标值0.1,biases接近目标值0.3
边栏推荐
猜你喜欢
随机推荐
shap库源码和代码实现
Win32控件------------显示系统使用的控件版本
Qt 国际化翻译
[贴装专题] 基于多目视觉的手眼标定
商业技术解决方案与高阶技术专题 - 数据可视化专题
MySQL索引的B+树到底有多高?
情感分析SowNLP词库
Win7 远程桌面限制IP
json库的dumps()方法和loads()方法
Pyhton实战汇总篇
Probably 95% of the people are still making PyTorch mistakes
How tall is the B+ tree of the MySQL index?
BERT预训练模型(Bidirectional Encoder Representations from Transformers)-原理详解
Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 1 Find programs in the PATH
jvm-类加载系统
SQL Server查询优化
研发需求的验收标准应该怎么写? | 敏捷实践
第二周作业
Cpolar内网穿透的面板功能介绍
中断系统结构及中断控制