Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@xunge
Last active July 2, 2019 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xunge/c14404c0b87f791400966836411b1d47 to your computer and use it in GitHub Desktop.
Save xunge/c14404c0b87f791400966836411b1d47 to your computer and use it in GitHub Desktop.
定义训练样本X和Y、定义输入x,输出y,定义权重w和偏置b,定义线性回归输出out,定义损失函数为均方差损失函数loss,并且使用Adam算法的Optimizer
import tensorflow as tf
import numpy as np
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
Y = np.array([[0], [1], [1], [0]])
x = tf.placeholder(tf.float32, [None, 2])
y = tf.placeholder(tf.float32, [None, 1])
w = tf.Variable(tf.random_normal([2, 1]))
b = tf.Variable(tf.random_normal([1]))
out = tf.matmul(x, w) + b
loss = tf.reduce_mean(tf.square(out - y))
train = tf.train.AdamOptimizer(0.01).minimize(loss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment