import numpy as np
=== Create data and simulate results =====
x_data = np.random.randn(200,3)
w_real = [0.3,0.5,0.1]
b_real = -0.2
noise = np.random.randn(1,200)*0.1
y_data = np.matmul(w_real,x_data.T) + b_real + noise
................................................................................................
import tensorflow as tf
................................................................................................
NUM_STEPS = 10
g = tf.Graph()
wb_ = []
with g.as_default():
x = tf.compat.v1.placeholder(tf.float32,shape=[None,3])
y_true = tf.compat.v1.placeholder(tf.float32,shape=None)
with tf.name_scope('inference') as scope:
w = tf.Variable([[0,0,0]],dtype=tf.float32,name='weights')
b = tf.Variable(0,dtype=tf.float32,name='bias')
y_pred = tf.matmul(w,tf.transpose(x)) + b
with tf.name_scope('loss') as scope:
loss = tf.reduce_mean(tf.square(y_true-y_pred))
with tf.name_scope('train') as scope:
learning_rate = .4
optimizer = tf.compat.v1.train.GradientDescentOptimizer(learning_rate)
train = optimizer.minimize(loss)
Before starting, initialize the variables. We will 'run' this first.
init = tf.compat.v1.global_variables_initializer() #variables given memory
with tf.compat.v1.Session() as sess:
sess.run(init)
for step in range(NUM_STEPS):
sess.run(train,{x: x_data, y_true: y_data})
print(step, sess.run([w,b]))
wb_.append(sess.run([w,b]))
print(10, sess.run([w,b]))
Auf dieser Seite können Sie das Online-Video Tensorflow: 13 Linear Regression using Tensorflow mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer BharatOnlineDS 02 Oktober 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 99 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!