In this post, we will learn Machine learning from scratch. Basically, we will be using Python2 for our purpose. To start machine learning using python, we will use two open source libraries, SciKit Learn and Tensor Flow. In this tutorial we are going to use the SciKit Learn, in the later tutorials, we will use Tensor Flow. Before we begin let’s know the answers to the questions like what is machine learning and why machine learning.
What is machine learning ?
Machine learning is the subfield of artificial intelligence. Early AI programs were typically made to excel in a particular thing (Problem Statement). For example deep blue, it can play chess at a championship level, but apart from that it cannot do anything else. Nowadays we want to write a single program which can solve multiple problems without been rewritten. Here is where Machine Learning comes into the role.
There are many types of Machine Learning, in this post, we will use supervised machine learning. It basically trains itself from an existing dataset and predicts the output. We can simply say that this code can learn from examples and experience.
Problem: Determine if input is an Apple or an Orange
For these type of problems, we need to train a classifier. We can think classifier as a function which takes data as input and label as output. We will distinguish both the fruits on the basics of characters like the shape and weight which are also called as features. The output generated from the classifier is known as a label.
Before we start coding, make sure you have installed SciKit Learn, numpy, Scipy and of course python. If not, bellow block will help you.
//To install Numpy ans SciPy
sudo apt-get install python-numpy python-scipy
//To insatll SciKit Learn
sudo pip install scikit-learn
Before we start the program, let’s look at the training data
Let us assume all as integers, so we will consider Orange as ‘1’, Apple as ‘0’. Similarly Bumpy as ‘0’ and Smooth as ‘1’. This conversion is completely random,just make sure what you opt. The more training data you have, the better classifier will be generated.
Code for Machine Learning using python
Step 1: Extracting features and labels from dataset
labels = [0,0,1,1]
Step 2: Train the Classifier using Decision Tree
from sklearn import tree
labels = [0,0,1,1]
#Setting an empty box of rules
clf = tree.DecisionTreeClassifier()
#Training the Classifier
clf = clf.fit(features, labels)
#fit can be thought as the synonym to find patterns in data
#testing the trained classifier
op = clf.predict([[input("Weight: "),input("Texture 0/1: ")]])
Hope you enjoyed so far. If this post was helpful, share it with your friends and help us grow. Got any queries do comment.