Thursday, November 30, 2017

Predicting Values By Using k-nearest Neighbors Machine Learning Algorithm


The k-nearest neighbors algorithm (k-NN) is a non-parametric method used for classification and regression in machine learning. This is the simplest and easiest algorithm which can be used to predict the outcome values. K-NN is also known as lazy learning, which stores the training data and waits until given a test tuple.

K-Nearest Neighbor Algorithm Has Below Mentioned Steps:
1. Pick a value of K
2. Search for K observations in the training data that are nearest to the measurements of the unknown data
3. Use the most popular response value from the K nearest neighbors as presicted response value for the unknown data or iris data in our example.
In the previous post we have loaded our first dataset which is IRIS. Now use the same dataset to train our model by using KNN neighbor algorithm and predict the values or outcomes. Click here to check which algorithm is used when.

Follow the code as explained in the previous post to load the IRIS dataset by using Scikit Learn.

# Below code will load the 4 attributes of IRIS in x_train_data object. The same can be verifies by using shape command
x_train_data = iris.data
y_train_data_outcome = iris.target

#Import KNN classifier from sklearn
from sklearn.neighbors import KNeighborsClassifier

#Define the neighbors value, I have used 1 you can try with 2, 3 4 or 5 and check the results.
knn = KNeighborsClassifier(n_neighbors=1)
print(knn)

#Training the KNN Classifier by loading test samples which is nothing but the 4 attributes of iris.data and 1 outcome of iris target

knn.fit(x_train_data, y_train_data_outcome)

#Define predict_species with 4 attributes
predict_species = ([3,5,4,2])

# Using Knn predict method to predict the species class.
print(knn.predict([predict_species]))

You can change the n_neighbors value and see what happens.

Click Here To Read Rest Of The Post...

Wednesday, November 29, 2017

Loading First Data Set In Machine Learning


In my previous post, I have already explained the difference between the Deep Learning and Machine Learning. In this post, I going to talk more about how to load the data set in Scikit learn which is machine learning library for new comers.

This post is more focus on loading IRIS dataset from Scikit Learn library by using Jupyter notebook. In 1936 Edgar Anderson collected 50 samples of 3 different species of IRIS for each sample he measured the sepal length, sepal width, petal length and petal width and record the measurements along with its species.

Use the below code to load the CSV file in your Jupyter notebook directly from internet.
from IPython.display import HTML
Use this link to load it in your Jupyter Notebook http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data

Output: There are 150 rows but I have only pasted sample from each row.
5.1,3.5,1.4,0.2,Iris-setosa
7.0,3.2,4.7,1.4,Iris-versicolor
5.9,3.0,5.1,1.8,Iris-virginica

The above output is comma separated output starting with sepal length, sepal width, petal length and petal width. The dataset also covers the species setosa, versicolor and virginica. With this dataset we can predict the species of the flower. This problem is also known as supervised learning because we are trying to learn the relationship between the data namely the IRIS measurements and the outcome is the species of IRIS.

I am using Scikit learn library for writing machine learning code. You can also install it from here. The best way to learn the machine learning or deep learning is to use the anaconda package on your laptop. This has lot of inbuilt libraries which can help you to sharpen your skills with GUI. GUI is nothing but it’s Jupyter iPYTHON version.

The IRIS dataset is the most famous dataset in machine learning and it is already built in Scikit-Learn. So we don’t need to load it from anywhere else as it is already built in function in Scikit-Learn. Let’s load the dataset.

#import Load_iris function from SKlearn datasets
from sklearn.datasets import load_iris

#Save iris dataset and it’s attributes in object called iris
Iris = load_iris()
type(iris)

#Iris is a object which has special container called bunch which is scikit learn special object type for storing datasets and it’s attributes.

#to check what’s in the dataset we can run the below code
print (iris.data)

#to check all about the dataset we can run the below code
Print(iris.DESCR)

In Machine Learning, each row is known as observation and column is known as feature.

#The below command will let you know about the features of the IRIS dataset
print (iris.feature_names)
['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']

#The below command will let you know about the type of IRIS category
print (iris.target_names)
['setosa' 'versicolor' 'virginica']

Each value what we are predicting is the response or target or outcome. In machine learning features and responses are separate objects and it can be numeric too. All the features and responses must be in numpy format else it will not going to work. We can check the type of the dataset by using “type(iris.data)” command.

In this dataset, we have X axis which is nothing but the attributes and we have outcome which is nothing but the Y axis. So lets’ store the attributes in X and outcome in Y.

#Store the IRIS features in X
X = iris.data

#Store the IRIS outcome in Y
Y = iris.target

Stay tuned for the next post which will help to understand how to use this dataset to write your first machine learning algorithm and check it's accuracy score.

Click Here To Read Rest Of The Post...

Sunday, November 26, 2017

What is Perceptron in Deep Learning?


To get the better understanding of neural networks, we first need to understand what is perceptron? Perceptron is nothing but its a type of artificial neuron. Artificial neuron is nothing but it mimics our brain as explained in my previous post.

Let's understand what is perceptron and how does perceptron algorithm works. As per the below image we are adding some inputs and every input as specific weight attached to it. The weights define how important the input is. After multiplication all are summed together and send it to activation function. The reason for using activation function is to use the threshold value. If the signal is above that threshold value the neuron or perceptron will fire else it will not. There are different kind of activation functions like sigmoid, step function, sign function depending on use case. The main idea was to define an algorithm in order to learn the values of weights which are then multiplies with the input features in order to make a decision whether the neuron will fire or not. We can even call perceptron as single layer binary linear classifier because it is able to classify the inputs which are linearly separable.



Steps of Perceptron Learning Algorithm
1. Initialize the weights and threshold
2. Provide the input and calculate output
3. While training artificial neuron we have set of output values. So we know the output values. To test it, we give the input and check it’s output and match it with the existing output.
4. If the output doesn’t match with the given one, in that case we need to update the weights accordingly in order to reduce the loss.

Click Here To Read Rest Of The Post...

Thursday, November 23, 2017

What is neuron and artificial neuron in deep learning?


Deep learning is a form of machine learning that uses a model of computing that’s very much inspired by the structure of the brain.

With the help of deep learning, we are trying to mimic the human brain. We are trying to train the machine the way human brain thinks and works.

To get better understanding of how does machine learning works, we need to first understand how human brain works.

The brain works with the help of brain cells which we called as neurons. Neurons has dendrites which receive signals from other neurons. The cell body which is surrounded by the dendrites receive all the signals and summed them and forward these signals to axons. With the help of axons these signals are fired to the next neurons. The next neuron is present at some distance and that distance is known as synapse. It fires only to the next neuron when the signals coming from cell body exceeds a particular limit.

By copying the same process we can create artificial neuron and it does the same function as the brain does. Read more about Machine Learning Algorithms: When To Use Which Machine Learning Algorithm


Now the questions comes, if our brain can does all the work then we need artificial neuron. The advantage of having artificial neuron is that it can mimic our brain by getting training data. It never ever tires, it can handle multiple inputs without any causes and provide more likely accurate answers with lot of permutations and combinations which human brain can never does.

Click Here To Read Rest Of The Post...

Tuesday, November 21, 2017

All About Machine Learning Algorithms: When To Use Which Machine Learning Algorithm


People always find hard to understand which machine learning algorithm has to be applied on given problem. Today we have infinite number of problem and we might think that we have infinite number of solution available around it. But when we start classifying the problems in different categories we usually find that these infinite problems can fir in finite categories and infinite solutions change to finite solutions. In this post, will try to explain more on what is an Algorithm and under which circumstances we have to use which type of machine learning algorithm.

To tell a computer what it has to do, in that case you need to write a program. A program is nothing but a set of instructions in the form of some syntax. This syntax can be written in any programming language like Java, C, Python, Ruby on Rails etc. e.g if you have to write a program to print 1 to 20 numbers, in this case you can opt for any kind of programming language. The syntax will be different but the logic will remain be the same. Now the question comes what is Logic? Logic is nothing but it’s an algorithm. An algorithm is a step by stem procedure of solving a problem in computer world.

Machine learning focuses on the development of the computer programs that can change when exposed to new data. Learning comes from the past experience and accordingly Machine Learning tune to itself. Read More about types of Machine Learning

How Does Machine Learning Helps To Solve Any Kind Of Problem? The problem can be divided into different kind of category as mentioned below:- 1. Classification Problem: When we know that any problem is having set number of outputs during that time we can use classification algorithm. E.g. Differentiating between apple and oranges is a type of classification problem.
2. Anomaly Detection Problem: When a same type of input is given to system and if any deviations happen in that input in that case anomaly detection algorithm is used to detect that change. It analyzes a certain type of pattern and alerts whenever there is change in pattern.
3. Regression Problem: Whenever we want machine to give us a number as output during that time we have to apply the regression algorithm. It is used to calculate numeric values. E.g. what is the minimum investment should I put in to become millionaire in 10 years.
4. Clustering Problem: Trying to find what is the structure behind the given data sets during that time clustering algorithm is required. By understanding how data is organized you can better predict the behavior of particular event.
5. Reinforcement Problem: When decision has to be made in that case, reinforcement learning algorithm is applied.

Click Here To Read Rest Of The Post...

Sunday, November 19, 2017

Difference Between Artificial Intelligence, Machine Learning and Deep Learning


Artificial Intelligence is the capability of a machine to imitate intelligent human behavior. It is accomplished by studying how human brain things, learns, decide and work while trying to solve a problem. The main applications of Artificial Intelligence are Speech Recognition, Image Recognition, Self-Driving Cars, Self-Driving Networks, Siri, YouTube and Pandora. AI was first coined in 1956 but due to limitation of computation network it couldn’t be used that time.

After AI, Around 1990’s Machine Learning came into picture. Machine Learning in nothing but is type of Artificial Intelligence that provides computers with the ability to learn without being explicitly programmed. Machine Learning is of different types and can be found in the previous post.
Machine learning couldn’t fly high because of its below mentioned limitations:
1. Data with large number of inputs and outputs
2. High Dimensionality of data
3. It can solve NLP and Image Recognition up to some extent but not at deep level.
4. It doesn’t support feature extraction. Feature extraction is nothing but it’s a way to solve the problem without giving all the required inputs.

Click here To know more about Machine Learning Algorithms: When To Use Which Machine Learning Algorithm Deep Learning is subset of Machine Learning. It came into existence around 2005-2006 and the motive behind Deep learning is to overcome the existing problems of Machine Learning. Deep Learning is collection of statistical machine learning techniques used to learn feature hierarchies often based on artificial neural networks. Deep Learning models are capable to focus on the right features by themselves but requiring some little guidance from the programmer. These models also solve the dimensionality problem too. The main idea behind Deep Learning is to build learning algorithms that mimic brain. It is implemented with the help of neural network.

Click here to know about what is neuron in deep learning.

Click Here To Read Rest Of The Post...