Importing Libraries

10/12/2018

Most of the developers currently are using Python for their Machine Learning projects and there is a reason for it. Python has a lot of in-built libraries that are ready to use by just importing them. So today the topic will be importing useful libraries that you can use in your programs.


Starting of you will need two libraries for sure while taking up any project in Machine Learning. These libraries are open-source so their source codes are available on github for editing.

1. Numpy - https://www.numpy.org/

This library is used for mathematical calculation in the dataset. As all the models of Machine Learning include mathematical calculations, you will need this library. This library basically includes creating and manipulating arrays and strings, implementing common mathematical functions and some statistics function.

2. Pandas - https://pandas.pydata.org/

This library is mostly used for reading and writing data in various formats like csv file, Excel, HDF5 format. After reading the data in a variable, a number of functions can be performed on it such as getting the length, index and column names of the dataframe in which the data is stored. As we all know that the data available is not always the data we need so to remove and add data in the dataframe, Pandas is used as there are ready made functions for it.

Other than these two libraries there are a lot of libraries available on GitHub, which can be imported but mostly used are Scikit learn and Matplot library.

Scikit Learn - https://scikit-learn.org/stable/

This can be called as the main library for all Machine Learning purposes as this library includes all the models and some famous datasets in it. This library includes all the calculations of all the models so that we do not have to hard code them.

Matplot lib - https://matplotlib.org/

This library is the basic library for plotting out graphs to get an insight about the data and also sometimes to visualise the results. There are dozens of different types of graphs available within the library which could be implemented with a single line of code.

You all might be thinking of how to get these libraries on your devices so that you could use them. Well as it turns out that there is also just a single line of code to do it. When you install python to your windows, by default Python 2.7.9+ comes with a pip installer. Even if you do not have it, you can easily download 'get-pip.py' file from the internet and run it in the command prompt of your device.

To install all these libraries, you need to open command prompt and type in

pip install numpy

This will install numpy library with which you will be able to import it in your programs in that environment.

Similarly,

pip install pandas

pip install -U scikit-learn

pip install matplotlib

The next step is to download an IDE where you will be running your scripts. There are two of them available in the market which are widely used, Spyder and Jupyter. (Notice the py for python instead of pi)

You can download them individually (Not recommended for new users) or download and install them from Anaconda. Once you have downloaded the exe file, run it and you will find an Anaconda Navigator looking somewhat like this.

Jupyter and Python can be installed and launched from here easily. After firing up the IDE of your choice, the fun part comes where you start to code. Usually all the libraries that you will be needing are imported in the start of the code and it is done very easily. All you need to do is write the following line of code.

import numpy as np

import pandas as pd

What these two lines of code does is the libraries named numpy and pandas are imported by the names of np and pd as a reference to them. This is mostly done so that the next time when we need to use these libraries, we can do it just by using np and pd.

Well now we have imported these libraries which are ready to use. Next step will be getting the dataset on which we will be working and building models on.

Hope you like this post and do tell if you find it useful. Everybody stay Awesome!

Total Hits: hit counter
Jay Nankani - Blog
All rights reserved 2018
Powered by Webnode
Create your website for free! This website was made with Webnode. Create your own for free today! Get started