如何用TensorFlow实现线性回归
环境Anaconda 废话不多说,关键看代码 import tensorflow as tf import os os.environ['TF_CPP_MIN_LOG_LEVEL']='2' tf.app.flags.DEFINE_integer("max_step", 300, "训练模型的步数") FLAGS = tf.app.flags.FLAGS def linear_regression(): ''' 自实现线性回归 :return: ''' #1.准备100个样本 特征值X,目标值y_true with tf.variable_scope("original_data"): #mean是平均值 #stddev代表方差 X = tf.random_normal(shape=(100,1),mean=0,stddev=1) y_true = tf.matmul(X,[[0.8]])+0.7 #2.建立线性模型: with tf.variable_scope("linear_model"): weigh = tf.Variable(initial_value=tf.random_normal(shape=(1,1))) bias = tf.Variable(initial_value=tf.random_normal(shape=(1,1))) y_predict = tf