Last active
July 2, 2019 01:03
-
-
Save xunge/c14404c0b87f791400966836411b1d47 to your computer and use it in GitHub Desktop.
定义训练样本X和Y、定义输入x,输出y,定义权重w和偏置b,定义线性回归输出out,定义损失函数为均方差损失函数loss,并且使用Adam算法的Optimizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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