Skip to content

Commit 8315ccb

Browse files
committed
Added Linear Regression Model and MNIST.
1 parent 7daa1a3 commit 8315ccb

File tree

3 files changed

+576
-12
lines changed

3 files changed

+576
-12
lines changed

0_tf_hello_world.ipynb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"You can press `shift + enter` to quickly advance through each line of a notebook. Try it now!"
7+
"You can use `ctrl-enter` to execute each snippet of code. The first snippet will check that TensorFlow is installed. "
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"import tensorflow as tf"
819
]
920
},
1021
{
1122
"cell_type": "markdown",
1223
"metadata": {},
1324
"source": [
14-
"This snippet of Python creates an extremely simple graph and runs."
25+
"Now, create an extremely simple graph and run it!"
1526
]
1627
},
1728
{
@@ -22,18 +33,10 @@
2233
},
2334
"outputs": [],
2435
"source": [
25-
"import tensorflow as tf\n",
26-
"\n",
2736
"hello = tf.constant('Hello, TensorFlow!')\n",
2837
"sess = tf.Session()\n",
29-
"print(sess.run(hello))"
30-
]
31-
},
32-
{
33-
"cell_type": "markdown",
34-
"metadata": {},
35-
"source": [
36-
"If you see \"Hello, TensorFlow!\", everything is working well."
38+
"print(sess.run(hello)) \n",
39+
"print tf.__version__"
3740
]
3841
}
3942
],

Linear_Regression_Model.ipynb

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"import tensorflow as tf\n",
12+
"import numpy as np"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": null,
18+
"metadata": {
19+
"collapsed": true
20+
},
21+
"outputs": [],
22+
"source": [
23+
"# Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3\n",
24+
"x_data = np.random.rand(100).astype(np.float32)\n",
25+
"y_data = x_data * 0.1 + 0.3"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {
32+
"collapsed": true
33+
},
34+
"outputs": [],
35+
"source": [
36+
"# Try to find values for W and b that compute y_data = W * x_data + b\n",
37+
"# (We know that W should be 0.1 and b 0.3, but TensorFlow will\n",
38+
"# figure that out for us.)\n",
39+
"W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))\n",
40+
"b = tf.Variable(tf.zeros([1]))\n",
41+
"y = W * x_data + b"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {
48+
"collapsed": true
49+
},
50+
"outputs": [],
51+
"source": [
52+
"# Minimize the mean squared errors.\n",
53+
"loss = tf.reduce_mean(tf.square(y - y_data))\n",
54+
"optimizer = tf.train.GradientDescentOptimizer(0.5)\n",
55+
"train = optimizer.minimize(loss)"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"metadata": {
62+
"collapsed": true
63+
},
64+
"outputs": [],
65+
"source": [
66+
"# Before starting, initialize the variables. We will 'run' this first.\n",
67+
"init = tf.initialize_all_variables()"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"metadata": {
74+
"collapsed": true
75+
},
76+
"outputs": [],
77+
"source": [
78+
"# Launch the graph.\n",
79+
"sess = tf.Session()\n",
80+
"sess.run(init)"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"metadata": {
87+
"collapsed": false
88+
},
89+
"outputs": [],
90+
"source": [
91+
"# Fit the line.\n",
92+
"for step in range(201):\n",
93+
" sess.run(train)\n",
94+
" if step % 20 == 0:\n",
95+
" print(step, sess.run(W), sess.run(b))"
96+
]
97+
}
98+
],
99+
"metadata": {
100+
"kernelspec": {
101+
"display_name": "Python 2",
102+
"language": "python",
103+
"name": "python2"
104+
},
105+
"language_info": {
106+
"codemirror_mode": {
107+
"name": "ipython",
108+
"version": 2
109+
},
110+
"file_extension": ".py",
111+
"mimetype": "text/x-python",
112+
"name": "python",
113+
"nbconvert_exporter": "python",
114+
"pygments_lexer": "ipython2",
115+
"version": "2.7.10"
116+
}
117+
},
118+
"nbformat": 4,
119+
"nbformat_minor": 1
120+
}

0 commit comments

Comments
 (0)