Want to learn machine learning? In this tutorial, we will get to know about what is machine learning? Machine learning using Python. We will discuss also, types of machine learning, various software required for machine learning, how to do environment setup for machine learning, and various popular libraries for machine learning.
Introduction to Machine Learning
- Machine Learning is the engineering of making machines act like humans.
- Machine Learning uses algorithms to make predictions about the future upon similar data.
- Machine Learning is a hot topic in today’s market & every company wants to implement it.
- Machine Learning is all about using data & making predictions.
- In traditional times, data was stored & processed on paper, with the rapid growth in data we started using spreadsheets, later Relational Databases came into the picture followed by big data, and then Machine Learning was introduced.
- technology improved with the increase in data with respect to time.
- Machine Learning is the subset of Artificial Intelligence.
- The algorithm created in Machine Learning is called Modals.
Machine Learning Types
There are mainly three types of machine learning and they are:
- Supervised Machine Learning
- Unsupervised Machine Learning
- Reinforcement Machine Learning
Now you know the names of ML types, Lets study about these names & understand why, when and how they are used.
You may like Pandas in Python.
Supervised Machine Learning
- Supervised Learning is a process in which Data (input) and label (output) are provided. The algorithm uses data to predict output as mentioned in the Label. If it fails to do so then it makes some changes and retries. The process keeps on going until & unless prediction is as per the label or close to the label.
- Example: an artist is drawing an apple. He has the picture of an apple and keeps on drawing it until both the pictures look similar.
- Supervised Learning is further divided into:
- Classification generates output in binary. It is used to identify if the thing is that or not. Example fever or no fever, available or not available, etc.
- Regression deals with the values. It talks about the numbers mostly monitor values.
Unsupervised Machine Learning
- Unsupervised Learning has data (input) but no label (output). Using data the algorithm tries to find patterns in data. It is used to find similarities in two or more things.
- The goal is to approximate the mapping function so well that the algorithm can predict the new data output.
- Neural Networks are the best example of unsupervised learning.
- Unsupervised Learning is further divided in into:
- Clustering refers to grouping the similar things or features.
- Association discover rules that describe large portions of your data.
Reinforcement Machine Learning
- Reinforcement Learning trains the model to make a sequence of decisions. Models are rewarded for every right decision and penalized for every wrong decision. In that way, they get to under what is right & wrong.
- The algorithm records both right & wrong & use it when exposed to new data or in real life. It is similar to training a pet. We offer food every time the pet does what we aspect him to do.
- Games are the best example of reinforcement learning.
Machine learning software
In this section, we will talk about the software we will use to perform Machine Learning models.
- Python 3
- Jupyter Notebook
You need this three software to get started with machine learning. Let’s understand why we need them & who is their competitor.
- Python is an interpreted, interactive, object-oriented, high-level language created by Guido van Rossum back in 1990.
- Python offers concise & readable code whereas Machine Learning has a complex algorithm. The simplicity of python helps developers to build complex Machine Learning models with less pain. That is why python famous among developers.
- Machine Learning models can also be written in R Programming.
- We will be using Python 3 for this tutorial. Click here to know how to download install python.
- Miniconda is the package manager that helps to
- create an environment for project
- installation of important libraries
- Miniconda is the lighter version of anaconda. Anaconda comes with preinstalled libraries which facilitates users to get started with work immediately after installing it. Whereas miniconda does not have any installed libraries.
- We highly recommend using miniconda so that you know what you have. Understanding your system is equally important to write better python codes. Paying attention and doing things manually will create a better understanding of the machine.
- The more you understand the machine, the better you write code.
- Click here to download miniconda depending upon your operating system.
- We have highlighted options that are common nowadays. If you have a 32 bit OS system then you can download to 32-bit miniconda. But make sure to download it for Python 3.
Installation of Miniconda
click on the downloaded file & you will see this interface. This program is executed in windows 10 but the similar screen will appear on mac & linux.
- Click on Next button.
2. Click on I Agree to accept the License Agreement.
3. Select Just Me radiobutton and click Next.
4. You can change the path incase you want to install the program on other location. It is fine then click Next.
5. If you will click on the add to PATH checkbox then you will be able to access conda on command Prompt, Powershell & Terminal. It completely depends upon the user preference for us we want to use conda from the miniconda prompt only.
The second checkbox will set Python 3.8 to default use for miniconda. Click on Install.
6. Once the installation is complete, click on the Next button.
7. Click on Finish button with all boxes unchecked.
8. Search for miniconda on windows search for windows, spotlight search for mac and
9. This is the interface you will see for miniconda
- Jupyter notebook is a web application that allows creating, read, share documents. It uses code to display output in a textual & visualization form. It is a powerful platform to write machine learning models.
- Jupyter notebook is a widely used tool for Machine Learning due to its simple look and effective work.
- ML operations can also be performed on vscode, google collab, Ibm platform, etc. But for this course, we will be using jupyter notebook.
Machine learning environment setup
- In Machine Learning setting up the Environment plays a major role. If you mastered the art of setting up the environment for your machine learning project then you are already a half legend.
- Projects in Machine Learning are big and include a group of people. So it is important that every teammate must have configured their system in a similar way to avoid confusion. Things not only end here, but the same configuration is also required when the project is shared with the users. that is why environment setup is considered to be an important step.
- In this section, we will learn how to
- create an environment
- activate and deactivate the environment
- store all the libraries in one environment
- Share Environment with others
- Create a project folder on your computer. In my case, the name of the folder is ‘PythonGuides-ML’
- Open miniconda and navigate to this folder
- We will name our environment folder as env.
- we can either provide the name of libraries while creating env or we can install it later.
- Here we will install pandas and NumPy libraries while creating env.
conda create --prefix ./env pandas numpy
- Conda is a cross platform package and environment manager that installs and manages conda packages from the Anaconda repository as well as from the Anaconda Cloud.
- create is an instruction to create environment
- –prefix is used when we have to create environment at a specific location. In case we want to create global environment than we can use –name. this will give name to that environment. We can’t use name and prefix in a same command.
- pandas & numpy are the libraries we are installing while creating environment.
In this way, we can create an environment for our project inside the project folder. This entire folder can be shared with other teammates & they will have the same setup.
Activate and deactivate the environment
Before we can start working on our created environment we have to activate it. Once the environment is activated then we can start installing more packages or libraries. In real life, we have multiple projects on which we work on so we need to switch among the environments. to access another environment first we have to deactivate this environment.
Here is the syntax to activate and deactivate the environment. Here path refers to the path of your project.
# activate environment
conda activate path/env
# deactivate environment
In this example, we will be activating our environment created in the previous section.
# to view the existing environment
conda env list
# activating environment
# deactivate enviroment
Store all the libraries in one environment
Now we have learned how to create environment and install libraries while creating environment. In this section, we will learn how to install more libraries inside a particular environment. Storing all the libraries in one environment helps the developer to keep all the necessary things of project in one folder & it becomes easy to share.
Step 1. Activate environment in which to start start working.
Step 2. type
conda install <name of the package>, here make sure that the package you are installing is available in the anaconda package. Typing an incorrect or incomplete name will show an error.
To verify if the package exists or not in the anaconda package list either you can try with the package name. If an error appeared that means package is not available or you can check the documentation of the anaconda.
Share Environment with others
While working in a team it becomes important that every member has the same environment set up on their machine. This helps in avoiding current or futures issues. On the other hand, if you have shared code on open-source platforms like GitHub. Then you can simply add instructions to activate the environment. Users will fall for your post as it will appear easy peasy setup.
There are two ways to share the project:
- Share Project Folder
If the project is small and has few libraries then you can simply share the project folder with others. The environment folder is surprisingly a large file so it takes time & bandwidth to upload or download the file.
- Share YAML file
Sharing .yaml file is an efficient way of sharing project environment as they are light weighted & have dependencies with the version. Later when another user will use the .yaml file then he will able to have the same dependencies with the same version.
Here is the code to export to YAML file.
conda env export --prefix C:\Users\MainFrame\Desktop\PythonGuides-ML\env > environment.yaml
conda env export: this is the main instructions to export the file.
--prefix C:\Users\MainFrame\Desktop\PythonGuides-ML\env: this is our environment that we want to export.
environment.yamlis the name you want to provide to the exported file.
- one the command is executed you can see the environment.yaml file in the project folder.
- Open the file and change the name of the environment. In our case we have given new name as newenv
Once we have changed the name of the environment now we need to create environment using this yaml file.
Here is the code to import or create environment using YAML file.
# create envirnoment using yaml file
conda env create -f environment.yaml
# activating environment
conda activate newenv
conda env create -f environment.yamlwill be created with this command.
conda activate newenv: since we have renamed our environment to newenv so we have to provide the same name here to activate the environment.
Machine Learning Popular Libraries
In this section, we will brief you about the popular libraries used in Machine Learning using Python for beginners.
You may like the following Python tutorials:
- Python Tkinter TreeView Example
- Python Turtle Commands
- Python Tkinter Canvas Tutorial
- Python naming conventions
- Python download and Installation steps
- Python Hello World Program
In this tutorial we have understood what is machine learning, machine learning using python, environment setup, using various popular libraries for machine learning like Pandas, NumPy, matlpotlib & scikit-learn. We will talk more about more Python machine learning libraries with dedicated blogs. Stay tuned with us, if you have any doubts or suggestions please leave a comment.
I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.