With the explosion of Machine Learning, Artificial Intelligence, and Neural Networks recently, it can be difficult to decern how to get started learning all this fancy new tech. It can even be difficult to figure out how to set up your environment correctly to facilitate this learning with the majority of development being done in Python and R. This article shows how to get a basic setup going for both languages by using Anaconda, SciPy, and Tensorflow.
- Python 2.x or 3.x
- Anaconda-Navigator (A GUI and command line tool for managing the python environment packages needed)
Note: This setup will work on Linux, Windows 10 or MacOS but this article demonstrates the setup using MacOS so some of the installer options/commands may differ on other operating systems
If you have not already installed Anaconda-Navigator go ahead and do so. Anaconda is an industry standard for developing data science applications such as AI or machine learning applications. It can take advantage of either Python or R as its language of choice and allows users to easily configure their environments through a GUI or command line tool.
After you get Anaconda-Navigator installed launch it using the Launchpad (CMD + Space for a shortcut on MacOS) and then click on the environments tab.
This screen will show all your configured environments, the installed packages for each environment, and allows you to create and clone. Click on the base (root) environment, then the green arrow icon, and finally Open Terminal to launch a terminal session with the selected environment loaded.
Now we need to update some of the existing libraries and add a few new ones.
conda update conda conda update anaconda
These two commands will use the conda CLI to update itself, and then the anaconda package to make sure everything already installed is up to date.
conda update scikit-learn
This command will update the Python library scikit-learn which is a collection of libraries specifically made to make it simpler to implement machine learning, data mining, and data analysis algorithms.
For this setup, we are going to install the open source machine learning framework Tensorflow. This is one of the most popular ML frameworks and has a lot of good documentation and examples online. To install it run the following conda command:
conda install -c conda-forge tensorflow
And now you should have the machine learning framework and all the python libraries needed to get started learning the concepts being machine learning! Of course, there are thousands of other libraries and frameworks out there but this should be a good start.
The last thing for this setup is to write a simple Python script that prints out the versions of the main libraries we are using. This can be useful when trying to follow along with examples online as sometimes the syntax of library implementations will change over time.
In a new directory create a file versions.py and add the following Python code to it
## VERSIONS ## # SciPy Environment print('______ SciPy Environment ______') # scipy import scipy print('scipy: %s' % scipy.__version__) # numpy import numpy print('numpy: %s' % numpy.__version__) # matplotlib import matplotlib print('matplotlib: %s' % matplotlib.__version__) # pandas import pandas print('pandas: %s' % pandas.__version__) # statsmodels import statsmodels print('statsmodels: %s' % statsmodels.__version__) # scikit-learn import sklearn print('sklearn: %s' % sklearn.__version__) # conda import conda print('conda: %s' % conda.__version__) # Deep Learning Libraries print('______ Deep Learning Libraries ______') # tensorflow import tensorflow print('tensorflow: %s' % tensorflow.__version__) # keras import keras print('keras: %s' % keras.__version__)
python versions.py will now print out the versions of the installed Python libraries!
In this article, we saw how to set up a simple machine learning environment for developing in Python by using Anaconda to install the needed libraries and frameworks.