Join my course at Udemy (Python Programming Bible-From beginner to advanced )

Blogger templates

Monday, 6 April 2020

Machine Learning & Intelligence


Introduction to Machine Learning

Machine Learning and intelligence has become essential in our daily life. For any product to be successful in the market following components are required :

1) GUI- The user interface should be intuitive so that any user of the product can quickly understand to operate the product. One need not go through a manual to understand the working of the product. For example one need not read a manual to operate an android application. The App is so intuitive that anyone, regardless of age, can easily understand how to work with the App. Now even a kid can operate application without any difficulty and assistance.

2) Infrastructure - Infrastructure plays very important role in defining the user base of the product across the world. In today's global world, if a user uploads a video on youtube, anyone in the world can easily access the video. A message in facebook and twitter is available instantly for anyone in the world to view provided they have the internet connection. Infrastructure define the reach of the product across the world.


3) Intelligence - Mankind has done tremendous progress in GUI and Infrastructure field. The latest addition for must have feature in the product is Intelligence. Idea is that product should be intelligent enough to read the mind of its user. When we try to write a sentence in google, google is intelligent enough to suggest a set of words based on our search. Facebook is able to suggest us who can be our friends based on similarities. There are tremendous example of face recognition system, where the application can identify the person based on their behavior, past history and so on. Bottom line is in current global environment, for product to be ssuccesful in the market, it needs to be intelligent enough to read the mind of its user.

What is Intelligence ?

So now the question is what is intelligence ? How do we define intelligence ?
Let's consider the following example.


A normal human being will be able to identify all the digits from 0 to 9 very easily. Note that all humans would not have seen the same shape of digit before but we all can understand how 0 looks like and how it is different from digit 1 and 2 and so on. And so we will be able to easily identify the digit 0, digit 1 and so on.

Based on the above example we can define the intelligence as 'Generalization'. It is  'Ability to predict or assign a label to an new or unseen observation based on the past experience.' Note that all humans would not have seen the 'same shape' of digit before but we all would have seen digit 0, 1, to 9 in some form. Based on the past experience we would have made a model in our mind how digit 0 to digit 9 should look like 'in general'. And hence if we see some "unseen" shape of the digit 0 to 9, we can easily identify the digit. 

Intelligence is not a lookup the way we do by storing the information in database. Lookup require exact match of "unseen" observation from the data stored in database. Intelligence is not about lookup but it is all about 'Generalization'.

How do we make a Machine intelligent ? 

Let's consider another example for identification of mail-spam. There can be two way to approach this use case. 

First approach  - Lookup approach

In the first approach we can list all the words that can appear in the mail as a lookup and if any of the words appear in the mail, we would tag the mail as SPAM. For example, if a mail has words like "Subscribe", "Chat" or "credit card" etc then we can tag the mail as SPAM. We will need to create a database of these words and everytime a mail comes, we need to lookup the database and conclude whether mail is SPAM or not. In this approach if the sender changes the word or introduce a new word in the mail, the model would not be able to recognize the mail a SPAM. This will again require update in the database to introduce the new word. 


Second Approach - ML way 

In the second approach we provide intelligence to our machine. Based on past email history, we create a model with the title, message length, repeated words etc to classify whether mail is SPAM or not a SPAM. In other words intelligent model will not be based on words in the model but will be based on unusual pattern derived from historical data of SPAM mail. 


Types of Machine Learning

Most of the machine learning use cases falls into one of two categories :
  • Supervised Learning
  • Unsupervised Learning

Supervised Learning

In supervised learning each of the observation is associated with the response. The goal is to fit a model that aims to predict the response based on the set of the observation. It is about creating an algorithm that detects a pattern between an observation and the response. Classifying e-mail as SPAM mail, predicting the resale value of house, predicting the future stock price are some of the examples of supervised learning. Linear Regression, Logistics Regression, SVM, Decision Tree, Random Forest etc are some of the examples of supervised learning.

Unsupervised Learning

In unsupervised learning, there are no response variable. The goal is to detect pattern among the observation in the dataset and come up with important insights in the dataset. Cluster analysis is one of important mechanism of unsupervised machine learning. Market segmentation to understand the buying pattern of people, recommendation algorithm to recommend next set of merchandise for the buyer are some of the examples of unsupervised learning. K-Means and hierarchical clustering, PCA, Apriori learning etc are some of the examples of unsupervised learning.


Summary

In summary, ML is about making machine more intelligent by deriving unusual pattern from the historical data. It is one step ahead from the lookup pattern to make machine solve the use case in an intelligent manner.

Reference

1.  Hands-On Machine Learning with Scikit-Learn and TensorFlow by Aurélien Géron

2. An Introduction to Statistical Learning: With Applications in R, by Jareth James, Trevor Hastie, Robert Tibshirani, Daniels Witten






Share:

Introduction to Python


Introduction to Python

Python implementation was started by Guido Van Rossum in the year 1989. First release of Python came out in the year 1990. Python 2.0 was released in 2000 and Python 3.0 was released in 2008.

To start with let's write HelloWorld program in Python and C++ to see the comparison between Python and C++

Python and C++ HelloWorld Program

HelloWorld code in Python can be written in one line but same code in C++ require around 5+ lines. Based on the above simple code, we can't make any conclusions but we can easily see that Python provides a framework to write simple and compact code.

Why use Python ?

This is the basic question that comes into the mind of every programmer.  Why to choose python when there are so many programming languages available. Many times the decision is guided by project implementation. But for a new application development one needs to know the advantages and disadvantages to take the right decision about Python.

Readability, Uniformity & Code reuse

Python focus on software quality makes it very different from other programming language. Python focus on readability, uniformity and Code reuse makes it very different. Python follows forceful formatted code and this make Python code uniform. This also takes care of any mistakes that may happen because of unformatted code as shown below :


Possible If/else error because of badly formatted code
From first look, the ELSE statement looks to be ELSE of outer IF. Even a seasoned programmer will make this error in first glance of code.  On the other hand, this type of error is not possible in Python as ELSE of corresponding IF will always be aligned to its IF. 

Python supports code reuse through the implementation of 'class', modules and procedural programming that reduces the code redundancy and increases the code reuse. OOPs functionality in Python is optional as this is not required to start on Python.

Developer productivity

Python has many features/advantages that makes it well suited to increase the productivity of developer.
- Python code size is generally lesser than other programming languages (like C++ and JAVA ). It has been observed that Python code is 1/3rd or 1/5th of C++/JAVA coding for same functionality. Less coding means lesser time to develop, lesser code to debug and maintain and hence increased productivity for developer.
- Dynamic typing allows developer not to worry about the datatype of a variable. Python internally takes care of resolving the data type in python statement. Developer can concentrate of application design free from the worries of data type.
- Python does not have the compile and link step. Developer write the code and proceed to run the code. The intermediate steps of compile and link does not exist in Python. This contributes to rapid development cycle.

 Support Libraries 

Python comes with good collection of support libraries. It has prebuilt library for basic python functionality, text pattern support, application support, network programming support etc. In addition to this there is good support for other domains. With Python one can do System programming, Database Programming, GUI based programming, Data Science, Machine Learning etc. It has grown over many domains and the list will continue to grow.

Others

The list for python features continue to grow. Python has tremendous support for cross platform. Same python code can run on Windows, Linux and other platforms without any change. Python code can invoke C/C++ library that makes the Python as fast as C/C++ platform. Many machine learning and data science platform invokes C/C++ APIs that make Python code execute faster. Python can also integrate with JAVA, and .NET platforms helping in product customization.

Python is completely free with great Python online support. Python source code is completely free and is available over internet.

Performance implication with Python

There are performance implication with Python. Python code does not run as fast as C/C++ code and it may not be very good choice if timing is a factor.
But Python capability to invoke C/C++ APIs make it quite interesting that combines the Python capability for ease of use and maintenance with C/C++ capability to run faster. For example NumPy libraries uses C API that makes Python faster by passing the data to external low level APIs. 
PyPy is another step towards making Python faster. According to Python creator (Guido van Rossum) "If you want your code to run faster, you should probably just use PyPy". On an average PyPy code runs 4.4 times faster than CPython.

Summary

The reach of Python is huge and now a days it is being used by many companies in diverse domains. Python has its own advantages and disadvantages. Python capability to integrate with C/C++/JAVA/.NET etc platforms provides us the capability to use Python's strength of 'ease to use' with the the speed of low level compiler language. PyPy work to make Python faster will be interesting to follow in future.












Share:

Feature Top (Full Width)

Pageviews

Search This Blog