DAY 2
2
Big Data

## Microsoft Azure Notebooks

Microsoft Azure Notebooks 是 M\$ 最新開出來的平台，不過在這裡不能稱呼他為 M\$ 因為這是完全免費的！可以在上面開 notebook 來使用 jupyter ，大家馬上趕快去試試看，不知道可以免費到多久呢．

## Check version

``````import sys
sys.version
``````
``````'2.7.11 |Anaconda custom (64-bit)| (default, Jun 15 2016, 15:21:30) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]'
``````

azure notebooks 的套件適用 Anaconda 安裝的，不過其中並沒有包含 tensorflow

``````sys.version_info
``````
``````sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)
``````

## Install tensorflow by pip

``````!pip install tensorflow
``````

## tensorflow with linear regression

``````import tensorflow as tf
import numpy as np

# 用 numpy 亂數產生 100 個點，並且
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3

# Try to find values for W and b that compute y_data = W * x_data + b
# (We know that W should be 0.1 and b 0.3, but TensorFlow will
# figure that out for us.)
# 等等 tensorflow 幫我們慢慢地找出 fitting 的權重值

W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b

# Minimize the mean squared errors.
loss = tf.reduce_mean(tf.square(y - y_data))
train = optimizer.minimize(loss)

# Before starting, initialize the variables.  We will 'run' this first.
init = tf.global_variables_initializer()

# Launch the graph.
sess = tf.Session()
sess.run(init)

# Fit the line.
for step in range(201):
sess.run(train)
if step % 20 == 0:
print(step, sess.run(W), sess.run(b))
plt.plot(x_data, y_data, 'ro', label='Original data')
plt.plot(x_data, sess.run(W) * x_data + sess.run(b), label='Fitted line')
plt.legend()
plt.show()

# Learns best fit is W: [0.1], b: [0.3]
``````

``````(0, array([-0.69138807], dtype=float32), array([ 0.36239833], dtype=float32))
(20, array([-0.28371689], dtype=float32), array([ 0.53784662], dtype=float32))
(40, array([-0.1455344], dtype=float32), array([ 0.45219433], dtype=float32))
(60, array([-0.0571136], dtype=float32), array([ 0.39738676], dtype=float32))
(80, array([-0.00053454], dtype=float32), array([ 0.36231628], dtype=float32))
(100, array([ 0.03566952], dtype=float32), array([ 0.33987522], dtype=float32))
(120, array([ 0.05883594], dtype=float32), array([ 0.32551554], dtype=float32))
(140, array([ 0.07365976], dtype=float32), array([ 0.31632701], dtype=float32))
(160, array([ 0.08314531], dtype=float32), array([ 0.31044737], dtype=float32))
(180, array([ 0.08921498], dtype=float32), array([ 0.30668509], dtype=float32))
(200, array([ 0.09309884], dtype=float32), array([ 0.30427769], dtype=float32))
``````

tensorflow 學習筆記30

### 3 則留言

0
hsuyen
iT邦新手 5 級 ‧ 2017-06-09 09:17:41

1
white455293
iT邦新手 5 級 ‧ 2017-08-25 11:12:13

c1mone iT邦新手 5 級‧ 2017-09-04 17:19:43 檢舉

0
moto
iT邦新手 5 級 ‧ 2018-02-09 13:37:29