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
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.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7852)
Learning SQL by Alan Beaulieu(5412)
Weapons of Math Destruction by Cathy O'Neil(5037)
Big Data Analysis with Python by Ivan Marin(3012)
Blockchain Basics by Daniel Drescher(2891)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(2519)
Pandas Cookbook by Theodore Petrou(2502)
Building Statistical Models in Python by Huy Hoang Nguyen & Paul N Adams & Stuart J Miller(2480)
Mastering Python for Finance by Unknown(2476)
Azure Data and AI Architect Handbook by Olivier Mertens & Breght Van Baelen(2450)
Serverless Machine Learning with Amazon Redshift ML by Debu Panda & Phil Bates & Bhanu Pittampally & Sumeet Joshi(2385)
How The Mind Works by Steven Pinker(2214)
Data Wrangling on AWS by Navnit Shukla | Sankar M | Sam Palani(2165)
Building Machine Learning Systems with Python by Richert Willi Coelho Luis Pedro(2059)
Data Engineering with dbt by Roberto Zagni(2057)
Driving Data Quality with Data Contracts by Andrew Jones(2032)
Network Science with Python and NetworkX Quick Start Guide by Edward L. Platt(1973)
Python Natural Language Processing by Jalaj Thanaki(1892)
Machine Learning Model Serving Patterns and Best Practices by Md Johirul Islam(1828)