You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To get started, first import TensorFlow, TF.Learn, and numpy:
93
+
To get started, first import TensorFlow and numpy:
50
94
51
95
```python
52
96
import tensorflow as tf
53
-
from tensorflow.contrib import learn
54
97
import numpy as np
55
98
```
56
99
57
-
Next, load the training and test sets into `Dataset`s using the [`load_csv()`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/base.py#L36)
58
-
method in `learn.datasets.base`. `load_csv()` has two required arguments:
59
-
`filename`, which takes the filepath to the CSV file,
60
-
and `target_dtype`, which takes the [`numpy` datatype](http://docs.scipy.org/doc/numpy/user/basics.types.html)
61
-
of the dataset's target value. Here, the target (the value you're training the model to predict) is
62
-
flower species, which is an integer from 0–2, so the appropriate `numpy` datatype is `np.int`:
100
+
Next, load the training and test sets into `Dataset`s using the [`load_csv()`]
101
+
(https://www.tensorflow.org/code/tensorflow/contrib/learn/python/learn/datasets/base.py) method in `learn.datasets.base`. The
102
+
`load_csv()` method has two required arguments:
103
+
104
+
*`filename`, which takes the filepath to the CSV file, and
105
+
*`target_dtype`, which takes the [`numpy` datatype](http://docs.scipy.org/doc/numpy/user/basics.types.html) of the dataset's target value.
106
+
107
+
Here, the target (the value you're training the model to predict) is flower
108
+
species, which is an integer from 0–2, so the appropriate `numpy`
Later on, in "Fit the DNNClassifier to the Iris Training Data," you'll use `x_train` and `y_train` to
85
-
train your model, and in "Evaluate Model Accuracy", you'll use `x_test` and `y_test`. But first,
86
-
you'll construct your model in the next section.
133
+
Later on, in "Fit the DNNClassifier to the Iris Training Data," you'll use
134
+
`x_train` and `y_train` to train your model, and in "Evaluate Model
135
+
Accuracy", you'll use `x_test` and `y_test`. But first, you'll construct your
136
+
model in the next section.
87
137
88
138
## Construct a Deep Neural Network Classifier
89
139
90
-
TF.Learn offers a variety of predefined models, called [`Estimator`s](https://www.tensorflow.org/versions/r0.9/api_docs/python/contrib.learn.html#estimators),
91
-
which you can use "out of the box" to run training and evaluation operations on your data.
92
-
Here, you'll configure a Deep Neural Network Classifier model to fit the iris data. Using TF.Learn,
93
-
you can instantiate your [`DNNClassifier`](https://www.tensorflow.org/versions/r0.9/api_docs/python/contrib.learn.html#DNNClassifier)
94
-
with just one line of code:
140
+
tf.contrib.learn offers a variety of predefined models, called [`Estimator`s
141
+
](../../api_docs/python/contrib.learn.html#estimators), which you can use "out
142
+
of the box" to run training and evaluation operations on your data. Here,
143
+
you'll configure a Deep Neural Network Classifier model to fit the Iris data.
144
+
Using tf.contrib.learn, you can instantiate your
145
+
[`DNNClassifier`](../../api_docs/python/contrib.learn.html#DNNClassifier) with
146
+
just one line of code:
95
147
96
148
```python
97
149
# Build 3 layer DNN with 10, 20, 10 units respectively.
The code above creates a `DNNClassifier` model with three [hidden layers](http://stats.stackexchange.com/questions/181/how-to-choose-the-number-of-hidden-layers-and-nodes-in-a-feedforward-neural-netw),
@@ -106,7 +158,7 @@ classes (`n_classes=3`).
106
158
## Fit the DNNClassifier to the Iris Training Data
107
159
108
160
Now that you've configured your DNN `classifier` model, you can fit it to the Iris training data
109
-
using the [`fit`](https://www.tensorflow.org/versions/r0.9/api_docs/python/contrib.learn.html#BaseEstimator.fit)
161
+
using the [`fit`](../../api_docs/python/contrib.learn.html#BaseEstimator.fit)
110
162
method. Pass as arguments your feature data (`x_train`), target values
111
163
(`y_train`), and the number of steps to train (here, 200):
The `predict()` method returns an array of predictions, one for each sample:
230
+
231
+
```python
232
+
Prediction: [12]
233
+
```
234
+
235
+
The model thus predicts that the first sample is *Iris versicolor*, and the
236
+
second sample is *Iris virginica*.
237
+
156
238
## Additional Resources
157
239
158
-
* For further reference materials on TF.Learn, see the official [API docs](https://www.tensorflow.org/versions/r0.9/api_docs/python/contrib.learn.html).
240
+
* For further reference materials on tf.contrib.learn, see the official
<!-- David, will the below be live when this tutorial is released? -->
161
-
* To learn more about using TF.Learn to create linear models, see
162
-
[Large-scale Linear Models with TensorFlow](https://www.tensorflow.org/versions/r0.9/tutorials/linear/index.html).
244
+
* To learn more about using tf.contrib.learn to create linear models, see
245
+
[Large-scale Linear Models with TensorFlow](../linear/).
163
246
164
-
* To experiment with neural network modeling and visualization in the browser, check out [Deep Playground](http://playground.tensorflow.org/).
247
+
* To experiment with neural network modeling and visualization in the browser,
248
+
check out [Deep Playground](http://playground.tensorflow.org/).
165
249
166
-
* For more advanced tutorials on neural networks, see [Convolutional Neural Networks](https://www.tensorflow.org/versions/r0.9/tutorials/deep_cnn/index.html)
167
-
and [Recurrent Neural Networks](https://www.tensorflow.org/versions/r0.9/tutorials/recurrent/index.html).
250
+
* For more advanced tutorials on neural networks, see [Convolutional Neural
0 commit comments