Getting Started with TensorFlow by Zaccone Giancarlo

Getting Started with TensorFlow by Zaccone Giancarlo

Author:Zaccone, Giancarlo [Zaccone, Giancarlo]
Language: eng
Format: azw3
Publisher: Packt Publishing
Published: 2016-07-29T04:00:00+00:00


Building the training set

Import all the necessary libraries to our simulation:

import matplotlib.pyplot as plt import numpy as np import tensorflow as tf import pandas as pd

Note

Pandas is an open source, easy-to-use data structure, and data analysis tool for the Python programming language. To install it, type the following command:

sudo pip install pandas

We must define the parameters of our problem. The total number of points that we want to cluster is 1000 points:

num_vectors = 1000

The number of partitions you want to achieve by all initial:

num_clusters = 4

We set the number of computational steps of the k-means algorithm:

num_steps = 100

We initialize the initial input data structures:

x_values = [] y_values = [] vector_values = []

The training set creates a random set of points, which is why we use the random.normal NumPy function, allowing us to build the x_values and y_values vectors:

for i in xrange(num_vectors): if np.random.random() > 0.5: x_values.append(np.random.normal(0.4, 0.7)) y_values.append(np.random.normal(0.2, 0.8)) else: x_values.append(np.random.normal(0.6, 0.4)) y_values.append(np.random.normal(0.8, 0.5))

We use the Python zip function to obtain the complete list of vector_values:

vector_values = zip(x_values,y_values)

Then vector_values is converted into a constant, usable by TensorFlow:

vectors = tf.constant(vector_values)

We can see our training set for the clustering algorithm with the following commands:

plt.plot(x_values,y_values, 'o', label='Input Data') plt.legend() plt.show()



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.