I started to learn Machine Learning and TensorFlow at 2nd day.
This article shows TensorFlow tutorial codes and some description for ML term.
๐ฏ Basic Usage
To use TensorFlow you need to understand how TensorFlow
- Represents computations as graphs
- Executes graphs in the context of Sessions
- Represents data as tensors
- Maintains state with Variables
๐ Terms
- ops (short for operations) : Nodes in the graph
- Tensors : Data structure as an n-dimensional array or list having Rank, Shape and Type
- Tensor : A typed multi-dimensional array
- Construction phase : Assembling a graph to represent and train a neural network
- Execution phase : Using a session to execute repeatedly a set of training ops in the graph
๐ Building the graph
import tensorflow as tf |
The default graph now has three nodes: two constant() ops and one matmul() op.
๐ธ Launching the graph in a session
# Launch the default graph. |
๐ Interactive Usage
# Enter an interactive TensorFlow Session. |
๐ Variables
Variables maintain state across executions of the graph
import tensorflow as tf |
๐ Fetches
import tensorflow as tf |
๐ฃ Feeds
import tensorflow as tf |
๐น Tensor Ranks, Shapes, and Types
Rank
Examples of Rank
are as follows:
- Rank 0 : Scalar (magnitude only) : s = 483
- Rank 1 : Vector (magnitude and direction) : v = [1.1, 2.2, 3.3]
- Rank 2 : Matrix (table of numbers) : m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
- Rank 3 : 3-Tensor (cube of numbers) : t = [[[2], [4], [6]], [[8], [10], [12]], [[14], [16], [18]]]
- Rank n : n-Tensor (you get the idea) : โฆ.
Shape
The following list shows how these relate to one another:
- Rank 0 : Shape [] : Dimension number 0-D : A 0-D tensor. A scalar
- Rank 1 : Shape [D0] : Dimension number 1-D : A 1-D tensor with shape [5]
- Rank 2 : Shape [D0,D1] : Dimension number 2-D : A 2-D tensor with shape [3,4]
- Rank 3 : Shape [D0,D1,D2] : Dimension number 3-D : A 3-D tensor with shape [1,4,3]
- Rank n : Shape [D0,D1,โฆ,D(n-1)] : Dimension number n-D : A tensor with shape [D0,D1,D(n-1)]
Shapes can be represented via Python lists/tuples of inits.
Data types
There are folloing data types to tensor:
- DT_FLOAT / tf.float32 / 32 bits floating point.
- DT_DOUBLE / tf.float64 / 64 bits floating point.
- DT_INT8 / tf.int8 / 8 bits signed integer.
- DT_INT16 / tf.int16 / 16 bits signed integer.
- DT_INT32 / tf.int32 / 32 bits signed integer.
- DT_INT64 / tf.int64 / 64 bits signed integer.
- DT_UINT8 / tf.uint8 / 8 bits unsigned integer.
- DT_STRING / tf.string / Variable length byte arrays. Each element of a Tensor is a byte array.
- DT_BOOL / tf.bool / Boolean.
- DT_COMPLEX64 / tf.complex64 / Complex number made of two 32 bits floating points: real and imaginary parts.
- DT_COMPLEX128 / tf.complex128 / Complex number made of two 64 bits floating points: real and imaginary parts.
- DT_QINT8 / tf.qint8 / 8 bits signed integer used in quantized Ops.
- DT_QINT32 / tf.qint32 / 32 bits signed integer used in quantized Ops.
- DT_QUINT8 / tf.quint8 / 8 bits unsigned integer used in quantized Ops.
๐ Introduction to Machine Learning Theory
Type
Supervised machine learning
The program is โtrainedโ on a pre-defined set of โtraining examplesโ,
which then caficiltates its ability to reach an accurate conclusion when given new data.
Unsupervised machine learning
The program is vien a bunch of data and must find patterns and relationships therein.
๐ผ Liner Regression
# A linear regression learning algorithm example using TensorFlow library. |
๐ฝ tf.contrib.learn Quickstart
import tensorflow as tf |
๐ Special Thanks
๐ Sample Code
๐ฅ Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!