Book Image

Predictive Analytics with TensorFlow

By : Md. Rezaul Karim
Book Image

Predictive Analytics with TensorFlow

By: Md. Rezaul Karim

Overview of this book

<p>Predictive analytics discovers hidden patterns from structured and unstructured data for automated decision-making in business intelligence.</p> <p>This book will help you build, tune, and deploy predictive models with TensorFlow in three main sections. The first section covers linear algebra, statistics, and probability theory for predictive modeling.</p> <p>The second section covers developing predictive models via supervised (classification and regression) and unsupervised (clustering) algorithms. It then explains how to develop predictive models for NLP and covers reinforcement learning algorithms. Lastly, this section covers developing a factorization machines-based recommendation system.</p> <p>The third section covers deep learning architectures for advanced predictive analytics, including deep neural networks and recurrent neural networks for high-dimensional and sequence data. Finally, convolutional neural networks are used for predictive modeling for emotion recognition, image classification, and sentiment analysis.</p>
Table of Contents (20 chapters)
Predictive Analytics with TensorFlow
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
Index

Installing and getting started with Python


Python is one of the most popular programming languages. It is a high-level, interpreted, interactive, and object-oriented scripting language. Unfortunately, there has been a big split between Python versions: 2 versus 3, which could make things a bit confusing to newcomers. You can see the major difference between them at https://wiki.python.org/moin/Python2orPython3. But don't worry; I will lead you in the right direction for installing both major versions.

Installing on Windows

On the Python download page at https://www.python.org/downloads/, you'll find the latest release of Python 2 or Python 3 (2.7.13 and 3.6.1, respectively, at the time of writing). You can now select and download the installer (.exe) of either version. Installation is similar to installing other software on Windows.

Let's assume that you have installed both versions and now it's time to add the installation path to the environmental variables.

For doing so click on Start, and then type advanced system settings, then select the View advanced system settings | System Properties | Advanced | Environment Variables... button:

Figure 5: Creating a system variable for Python

Python 3 is usually listed in the User variables for Jason, but Python 2 is listed under the System variables as follows:

Figure 6: Showing how to add the Python installation location as system path

There are a few ways you can remedy this situation. The simplest way is to make changes that can give us access to python for Python 2 and python3 for Python 3. For this, go to the folder where you have installed Python 3. It should be something like this: C:\Users\[username]\AppData\Local\Programs\Python\Python36 by default.

Make a copy of the python.exe file, and rename that copy (not the original) to python3.exe as shown in the following screenshot:

Figure 7: Fixing Python 2 versus Python 3 issue

Open a new Command Prompt (the environmental variables refresh with each new Command Prompt you open), and type python3 --version:

Figure 8: Showing Python 2 and Python 3 version

Fantastic, now you're ready for whatever Python project you want to tackle.

Installing Python on Linux

For those of you who are new to Python, Python 2.7.x and 3.x are automatically installed on Ubuntu. Make sure to check if Python 2 or Python 3 is installed using the following command:

$ python -V 
>> Python 2.7.13
$ which python
>> /usr/bin/python

For Python 3.3+ use the following:

$ python3 -V  
>> Python 3.6.1

If you want a very specific version:

$ sudo apt-cache show python3
$ sudo apt-get install python3=3.6.1*

Installing and upgrading PIP (or PIP3)

The pip or pip3 package manager usually comes with your Ubuntu. Make check to sure if pip or pip3 is installed using the following command:

$ pip -V >> pip 9.0.1 from /usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg (python 2.7)

For Python 3.3+ use the following:

$ pip3 -V >> pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4)

It is to be noted that pip version 8.1+ or pip3 version 1.5+ are strongly expected to give better results and smooth computation. If version 8.1+ for pip and 1.5+ for pip3 are not installed, see the following command to either install or upgrade to the latest pip version:

$ sudo apt-get install python-pip python-dev

For Python 3.3+, use the following command:

$ sudo apt-get install python3-pip python-dev

Installing Python on Mac OS

Before installing the Python, you should install a C compiler. The fastest way of doing so is to install the Xcode command-line tools by running the following command:

xcode-select –install 

Alternatively, you can also download the full version of Xcode from the Mac App Store.

If you already have Xcode installed on your Mac machine, do not install OSX-GCC-Installer. In combination, you can experience some unwanted issues that are really difficult to diagnose and get rid of.

Although Mac OS comes with a large number of Unix utilities, however, one key component called Homebrew is missing, which can be installed using the following command:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Set the Homebrew installation path to the PATH environment variable to the ~/.profile file by issuing the following command:

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

Now, you're ready to install Python 2.7.x or 3.x. For Python 2.7.x issue the following command:

$ brew install python

For Python 3 issue the following command:

$ brew install python3

Installing packages in Python

Additional packages (other than built-in packages) that will be used throughout this book can be installed via the pip installer program. We have already installed Python pip for Python 2.7.x and Python 3.x. Now to install a Python package or module, you can execute pip on the command line (Windows) or terminal (Linux/Mac OS):

$ sudo pip install PackageName # For Python3 use pip3

However, already installed packages can be updated via the --upgrade flag by issuing the following command:

$ sudo pip install PackageName –upgrade # For Python3, use pip3