1 下载python-3.5.0-amd64.exe 安装
2 安装pycharm-professional-2017.2.3.exe
3 pip升级
C:\Users\***\AppData\Local\Programs\Python\Python35>python -m pip install --upgrade pip
4 在pycharm里安装matplotlib包(也可以python -m pip install --upgrade matplotlib)
5 C:\Users\***\AppData\Local\Programs\Python\Python35>python -m pip install --upgrade tensorflow
2 安装pycharm-professional-2017.2.3.exe
3 pip升级
C:\Users\***\AppData\Local\Programs\Python\Python35>python -m pip install --upgrade pip
4 在pycharm里安装matplotlib包(也可以python -m pip install --upgrade matplotlib)
5 C:\Users\***\AppData\Local\Programs\Python\Python35>python -m pip install --upgrade tensorflow
6 msvcp140.dll copy 到C:\Windows\System32
以下一个逻辑回归问题与模型。我们使用numpy构建一组线性关系的数据,通过TensorFlow实现的随机梯度算法,在训练足够长的时间后可以自动求解函数中的斜率和截距。
https://github.com/tobegit3hub/tensorflow_examples
import tensorflow as tf
import numpy as np
# Prepare train data
train_X = np.linspace(-1, 1, 100)
train_Y = 2 * train_X + np.random.randn(*train_X.shape) * 0.33 + 10
# Define the model
X = tf.placeholder("float")
Y = tf.placeholder("float")
w = tf.Variable(0.0, name="weight")
b = tf.Variable(0.0, name="bias")
loss = tf.square(Y - X * w - b)
train_op = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
# Create session to run
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
epoch = 1
for i in range(100):
for (x, y) in zip(train_X, train_Y):
_, w_value, b_value = sess.run([train_op, w, b],
feed_dict={X: x,
Y: y})
print("Epoch: {}, w: {}, b: {}".format(epoch, w_value, b_value))
epoch += 1
print("Optimization Finished!")