Machine Learning with Python

Charlotte Miller

Updated on:

One of the most mystical words you will come across these days is Artificial Intelligence (AI) and Machine Learning. So, what is Machine Learning? What makes it so popular?  What purpose does it solve? And lastly, what are the tools and techniques required to develop Machine Learning Models?

In this article we will unravel all of the above one by one:

click here – KYC Full Form? What Is The Full Form Of KYC?

What is Machine Learning?

Machine Learning is a subset of Artificial Intelligence that makes a system capable enough to automatically learn and improve from experiences. In simpler words, Machine Learning or ML is a science of extracting hidden patterns and making predictions from the data without relying on rules-based programming. It is based on the underlying models which learn from the data.

In 1959, Arthur Samuel defined ML as a “Field of study that gives computers the ability to learn without being explicitly programmed”.

Machine Learning primarily falls into 3 major categories:

  • Supervised Learning: 

It is a type of Machine Learning technique which tries to establish the relationship between dependent and independent variables. It is an approach to model an algorithm which is trained on the input data that has been labelled for particular output.

Examples: Spam detection, Weather forecasting, etc.

click here – FMCG Full Form: What Is The Full Form Of FMCG?

  • Unsupervised Learning: 

It is a type of Machine Learning technique in which a model tries to make sense out of unlabeled data.

Ex: Customer segmentation, pattern detection etc.

  • Reinforcement Learning: 

It is a type of Machine Learning technique in which a model tries to maximize the award by learning continually from the environment with respect to the prevailing situation.

Ex: Self driving car

Let’s try to familiarize Machine Learning with Python:

Python was developed by Guido Van Rossum in the late 1980’s. It is a simple, general purpose, high-level, object-oriented programming language. Python’s simplicity doesn’t come at the cost of its efficiency in fact it has humongous set of library packages for doing data loading ,preprocessing , statistical analysis , graphical visualization , modelling and many more which makes it a perfect choice for doing Machine Learning projects.

Few of most popular python libraries for Machine Learning with Python are:

  • Scikit-learn 

It is an Open-source library which means that it can be used for free and distributed. It has many State-of-the-Art algorithms with comprehensive articulated documentation. It features ML algorithms such as Support Vector Machines, Random Forests, K-Nearest neighbours and provide tremendous support with numerical and Scientific Python (NumPy and SciPy)

If you have installed the Anaconda package then Scikit-Learn automatically comes along with it, but if you have separately installed python, then Scikit-learn can be installed using the below command in the terminal:

$ pip install numpy scipy matplotlib ipython scikit-learn pandas pillow

  • NumPy

NumPy is an abbreviation for Numerical Python. It is one of the most fundamental packages for performing scientific computations. It provides multi-dimensional arrays objects and supports high-level mathematical operations like trigonometric functions, arithmetic operations, complex computations etc.

NumPy library can be installed via pip using the below command:

$ pip install numpy

In order to use the predefined function in NumPy, it needs to be imported first using below code in the IDE

import numpy

x = numpy.array([1,2,3])

print(x)

  • Alias name can also be used instead of the complete name ‘numpy’

import numpy as np

y = np.array([4,5,6])

print(y) 

Below are a few operations on NumPy:

Arithmetic Operations on array are applied element wise. Please find the below examples:

  • Pandas

It is an open source, high performance python library used for doing data analysis. It is built around a structure called a DataFrame. 

DataFrame is nothing but a table look and feel of which is similar to a data in Excel sheet. Pandas provide a rich range of functions to perform on DataFrames.

What makes Pandas unique from NumPy is that pandas allows every column to have a separate type like strings, dates, floating point numbers.

Another tremendous feature of pandas is defined from its ability to ingest data into DataFrame from multiple sources like Excel Sheets, csv (comma separated values) files, SQL files, zip files and also from URLs as well.

Pandas can be installed via pip using below command:

pip install pandas

Note: If you have installed python using Anaconda distribution then libraries like NumPy and Pandas come pre-installed so explicit installation is not required in such cases.

Just like in NumPy, pandas also needs to be imported first in the IDE before using and below is the code to import pandas:

import pandas

df = pandas.read_csv(“<path to csv data>”)

We can make use of alias in pandas as well to use short form instead of writing the keyword every time we need to use and below is the syntax:

      import pandas as pd

      df1 = pd.read_csv(“<path to csv data>”)

Below are a few operation on Pandas:

1.) Analyzing data

Pandas head() function can be used to validate if data is loaded appropriately with proper header and indexes:

   import pandas as pd

   df = pd.read_csv(csv_conatining_data.csv)

   print(df.head())

   # head() will print top 10 rows of the data in the console of the IDE

Pandas tail() similar to head() is also used to validate data in DataFrame and the only difference between the 2 functions is tail() will print bottom 10 rows in the console instead of the top 10 in case of head().

    import pandas as pd

   df = pd.read_csv(csv_conatining_data.csv)

   print(df.tail())

   # tail() will print bottom 10 rows of the data in the console of the IDE

2.) Data Cleansing 

Pandas dropna() operation can be used to get a DataFrame with no empty cells. Please find the below code for the same.

  import pandas as pd

  df = pd.read_csv(data.csv)

  new_df = df.dropna()

Conclusion

This brings us to the end of the blog. Machine learning with python is a whole new world and to understand machine learning with Python, you need to have basic knowledge of Python programming along with a number of libraries and packages used in performing various machine learning tasks as listed below:

    • numpy 
    • pandas
    • matplotlib 
    • scikit-learn
  • seaborn 

Happy Learning!