Setup Guide

Intro to Python for Machine Learning & AI

Introduction



    Before you can do machine learning from your own computer, we need to make sure your computer's environment is ready.

    In terms of computers, an environment is just the state of the computer based on the software, hardware and settings that it has.

    This means that your computer's hardware, software and settings must be compatible and configured correctly.

    This lesson will contain instructions for setting up Python for Windows and Mac.

    We have designed this course to be compatible with Chrome and Firefox web browsers. If you are using a different web browser, we recommend you download and open the site in Chrome or Firefox before continuing.

    You can Download Chrome Here or Download Firefox Here.

Hardware Requirements



    Machine learning and deep learning can be intensive on a computer. In this course, you will be performing basic machine learning calculations, so while these minimum settings may work with the projects for this course, you may need a more powerful computer if you want to continue creating more advanced machine learning programs after the course.

    Make sure that your computer meets these minimum requirements.

    Windows
    1. Windows OS version - Windows 7 or later
    2. RAM - 4 GB minimum, 16 GB or higher is recommended for advanced work in machine learning, but not necessary for this course's material.


    Mac
    1. OS Version - MacOS 10.9 or later (earlier versions may still work, but the provided installation instructions here may not work)
    2. RAM - 4 GB minimum, 16 GB or higher is recommended for advanced work in machine learning, but not necessary for this course's material.

Software



    There are many different software, tools and packages that are used for machine learning with python.

    We will be using a few of the most common ones:
    1. Python Distribution - The python install comes with many of the essential tools we need such as IDLE, Pip and the Python language itself. You can download python distributions with different versions of python, so pay attention to the distribution version when you download python. If you download the wrong version of a distribution, some code may not work.
    2. IDLE - IDLE (Integrated DeveLopment Environment) is a GUI application where you can write python programs. This is the application that you will use to write python programs for this course.
    3. Pip - Pip (Pip Installs Packages) is a program that will install python packages that aren't included with the python distribution that you downloaded. You will use Pip to install machine learning packages that aren't included in the python distribution you will download.
    4. Packages - Programs with additional libraries, such as code that performs machine learning. You will be shown how to install all the packages you will need for this course.

Installing Python



    Before you can start writing machine learning programs, you will need to install Python on your machine.

    Start by downloading Python here. Choose a release version.

    The Python programming language is very frequently updated. The current version of this course was developed in Python 3.8. This course has been tested for Python 3.9.6. Later versions of Python 3 will likely work as well.



    This will take you to the downloads page. You will see the downloads in the Files section at the bottom of the page. Choose the installer for your operating system.

    For Windows users, If you don't know if your system is 32-bit or 64-bit, the Microsoft FAQs Page provides instructions on how to look up this information on your computer.

    Windows 64-bit: Windows x86-64 executable installer

    Windows 32-bit: Windows x86 executable installer

    macOS: macOS 64-bit installer




    If you're having trouble finding the files after you downloaded them, you can follow the instructions in one of these links, depending on your web browser.

    Firefox Downloaded File Locations

    Chrome Downloaded File Locations

    Internet Explorer Downloaded File Locations

    Safari Downloaded File Locations


    Open the installer and follow the installation instructions. If you are installing with windows, make sure to check the options on the guide below. If you don't follow these instructions, you may need to reinstall python to ensure you can follow the instructions in all of the lessons.

    Select the box for Add Python X.X to PATH which tells the computer where to find Python when we search in the command line.

    Click Install Now. This is the default installation option that includes Python, IDLE (Integrated Development Environment), pip and the official documentation.

    Do not use 'customize installation' unless you have advanced knowledge.


    Once the install has finished, click close to close the installer.

    Below is a video showing the process to download and install IDLE for Macs.



Command Line - Windows



    To check that Python has installed correctly and for things we will do later, we need the command line.

    The command line is a text interface for your computer that takes in commands for the operating system to run.

    It is also referred to as the terminal, prompt, shell, console and more.

    If you are using a Mac, skip ahead to the next section, which explains using the command line on Macs, called the Terminal.

    Opening the command line - You can open this by clicking Start and in the Search or Run line, type cmd (short for command), and press Enter.

    Read more about How to use the Windows command line.
    We will be using the command line just for installations, but you can use the links to learn other ways to use the command line if you're interested.

    Cannot load image

    Once you have your command line open, type python and hit Enter.

    You should then see information about your Python version, meaning that it has installed correctly and you are ready to code.



    You can also now use your command line as an interpreter meaning you can type code and it will be executed. E.g. type 2 + 3 and hit Enter.

    The code will execute and you will see the result in the terminal. You can then type exit() or quit() and hit Enter to exit Python.

    Remember that if you see three greater than signs (>>>), you are running Python in the command line and only Python code will work. If you do not see >>> then you are just in the regular command line and Python code will not work.



    We won't be using the command line to write code (we will use IDLE for that). However, we do need to use the command line to install additional packages.

Command Line - Mac (Terminal)



    To check that Python has installed correctly and for things we will do later, we need the terminal.

    The terminal is a text interface for your computer that takes in commands for the operating system to run.

    You can open this by going to your Applications folder, then the Utilities folder and clicking on Terminal. Alternatively you can just type Terminal in the Spotlight search.

    Read more about How to use the Mac command line.

    Below is a video showing the process to open the terminal on Mac.



    We will be using the command line just for installations, but you can use the links to learn other ways to use the command line if you're interested.

    Cannot load image

    Once you have the your command line open, type python3 and hit Enter.

    You should then see information about your Python version, meaning that it has installed correctly and you are ready to code.

    You can also now use your command line as an interpreter meaning you can type code and it will be executed. E.g. type 2 + 3 and hit Enter.

    The code will execute and you will see the result in the terminal. You can then type exit() or quit() and hit Enter to exit Python.

    Remember that if you see three greater than signs (>>>), you are running Python in the command line and only Python code will work. If you do not see >>> then you are just in the regular command line and Python code will not work.

    When you are in the Python interpreter, there will be no differences between Mac and Windows.



    We won't be using the command line to write code (we will use IDLE for that). However, we do need to use the command line to install additional packages.

Pip Installing



    One of the simplest ways to install libraries for Python is through Pip.

    Pip is a package manager for Python packages/modules. Modules are Python code libraries you can include in your project. A package contains all the files you need for a module.

    Pip comes by default with Python so you should already have it installed.

    Windows: You can check this by typing pip -V or pip --version in the command line to show the pip version.

    Mac: You can check this by typing pip3 -V or pip3 --version in the command line to show the pip version. In the future, when you see a reference to pip, make sure that you use the command pip3 instead. If you do not, you will see the error message --bash: pip: command not found



    To install a Python package, just type pip install <package> in the command line where <package> is the name of the package you want to install.

    Here are the packages you must install for this course.
    1. Numpy - To install type: pip install numpy
    2. Pandas - To install type: pip install pandas
    3. Matplotlib - To install type: pip install matplotlib
    4. Scikit-learn - To install type: pip install -U scikit-learn
      Note: This command also has -U in the command. This is short for upgrade, and ensures that packages related to scikit-learn are upgraded to the correct versions that scikit-learn uses.


    Each of these packages adds different functionality important for machine learning.

    1. Numpy - Adds functionality to improve the speed and organization of data. Because machine learning occurs on large sets of data, it needs to be organized in a way the computer can process it quickly.
    2. Pandas - Adds dataframes, a data science concept that works much like a spreadsheet.
    3. Matplotlib - Adds graphs so that you can visualize your data and present your results to others in an easy-to-view format.
    4. Scikit-learn - Adds basic machine learning models to python.




    If you see one of the below errors.

    Cannot Load Image

    Cannot Load Image

    You need to exit out of the python interpreter and go back to the command line before you use pip. You can see that you are still in the python interpreter because of the three greater than signs (>>>).

    Type exit() and press Enter to exit the interpreter. Type the pip command again and it will run.


    If you see a WARNING message with the text WARNING: You are using pip version... you do not need to do anything different, just keep installing packages using the commands above.

    After this you should have these packages with all the necessary files installed.

    You can check what you have installed by typing pip list.



    There are many other useful commands and you can see them all by typing pip.

    You are now setup and ready to use Python, as well as the extra 4 packages, for starting data science and machine learning.