当前位置:网站首页>Tensorflow realize parameter adjustment of linear equations

Tensorflow realize parameter adjustment of linear equations

2022-08-09 10:46:00 qq_26391203

import tensorflow as tfimport numpy as np#create datax_data=np.random.rand(100).astype(np.float32)y_data=x_data*0.1+0.3 #target resultspan>#create tensorflow structure startWeights=tf.Variable(tf.random_uniform([1],-1.0,1.0))biases=tf.Variable(tf.zeros([1])) # The weights and biases are continuously learned from the initial value and approach the target valuey=Weights*x_data+biasesloss=tf.reduce_mean(tf.square(y-y_data))# mean square erroroptimizer=tf.train.GradientDescentOptimizer(0.5)train=optimizer.minimize(loss)init=tf.initialize_all_variables()# create tensorflow structure endsess=tf.Session()sess.run(init) #points to the processing placefor step in range(201):sess.run(train)if step%20==0:print(step,sess.run(Weights),sess.run(biases))

Experiment results:
Write image description here

The final experimental results shown above show that Weight is close to the target value of 0.1, and biases is close to the target value of 0.3

原网站

版权声明
本文为[qq_26391203]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091039085645.html