Getting started with Machine learning/AI

Overview

Data is the new oil. Everyday enormous amount of data is collected over the internet. Big tech giants like Google, Amazon, Netflix and others are using the artificial intelligence to improve their products and services using the large amount of data they have.

Currently we are surrounded with AI systems from voice assistant (Siri, Alexa, Google Assistant) to recommendation systems over the apps like Amazon, Netflix, Spotify and etc. From spam detecting filters(Gmail) to auto translation over different languages(Google Translate). The face ID in the iPhone also uses a type of Artificial Intelligence called Neural networks, which became better and better over the time in detecting the human face. Artificial Intelligence is affecting our everyday lives and making things easier.

Machine learning Vs Deep learning Vs AI

- Machine Learning is a technique of parsing data, learn from that data and then apply what they have learned to make an informed decision.

- Deep learning is a subset of machine learning which is used to model high-level abstractions in data through the use of model architectures, which are composed of multiple nonlinear transformations.

- AI is a ability of computer program to function like a human brain. Machine learning is the subset of AI.

According to Arthur Samuel, Machine Learning provides computers with the ability to learn without being explicitly programmed. In other words, it gives computer the ability to learn on their own and execute the correct instructions, without you providing them directions.

Artificial Intelligence is not a new field, actually it all started back in 1950 when Alan turing was testing whether a computer had the ability to think like a human being. But it got slow down because at that time it was suffering from two key problems. First it requires a good amount data to be feeded into the models to learn and collecting data at that time was expensive. Second, it also requires more computational power while training.

With the invent of internet and the advancements in processing power, it has gain more popularity in the recent years. In the past 20 years more data is collected than in the entire previous history of the human race. Also with the introduction to GPUs, computing becomes powerful than ever. This has given rise to new research and developments in the field on machine learning and AI.

Types of Learning

Machine learning can be categorised in three types according to problem definition and the data available.

Supervised learning

In supervised learning, we are given with a labelled dataset which means for every input there is a output. Model has to learn the mapping between input and output. Supervised learning is further divided into two types:

Classification: In this type, we have to categorized data into one of the defined unique classes(discrete variable) given. Example: spam detection (spam or ham)

Regression: In regression, the output is a real valued number(continuous variable), Example house prices prediction.

Unsupervised learning:

In unsupervised learning, model has to learn only from input variables without labelled responses. Unlike supervised learning we don't have output variable to guide the model while training. The most common unsupervised learning method is cluster analysis, where we group the data with similar properties called clusters.

Reinforcement learning

Reinforcement Learning is about taking suitable actions to maximixe reward in a particular situation. It is employed by various software and machines to find the best possible behavior or path to take in a specific situation.

Reinforcement learning differs from the supervised learning in a way that in supervised learning the training data has the answer key with it, so the model is trained with the correct answer itself whereas in reinforcement learning, there is no answer and the reinforcement agent decides what to do in order to perform the given task. In the absence of training data set, it is bound to learn from its experience.

Machine learning with Javascript

The Machine Learning process consists of two major steps: Training and Testing. Training involves giving a huge amount of data to the model, which the model will then process and recognize different patterns, which the model will then use to make future predictions.

We will be creating a simple app which takes an image and returns the prediction of what that image consist. Instead of training our own model with huge data, lets use a pre-trained model which can classify an image.

So, lets start first we will be using create-react-app to build a boilerplate React application. To do this, open a command terminal and run the following command:

 create-react-app ml-js-app

This command will create a folder named ml-js-app and build a start app in your system. Next, go back to your command terminal and run the following commands:

cd ml-in-js
npm run start

The npm run start command creates a local development level of your system and automatically opens it on the browser.

Tensorflow.js is the most popular library for building machine learning applications in Javascript. But for keeping this tutorial simple and easy for beginners we will be installing another library ML5.js which allow to do Machine Learning on the client-side. For installing the library type the following command:

npm install --save ml5

With that, we are done with the installation part. Now we need to create a function that can take in an image and classify it using a pre-trained model. To do this, write the following code inside the App component:

classifyImage = async () => {
  const classifier = await ml5.imageClassifier('MobileNet')
    this.setState({ ready: true })
    const image = document.getElementById("image")
    classifier.predict(image, 1, (err, results) => { 
      this.setState({ predictionLabel: results[0].label, predictionConfidence: results[0].confidence, predicted: true })
     })
}

Here we have an asynchronous function called classifyImage. Inside this function, we first define our Image Classifier by loading the MobileNet data as the training set. Once this classifier is ready, we set the ready state to true. Then, we select the image inserted by the user and pass it to the classfier and run the predict function. We save the highest prediction’s label and confidence level in the state object.

That's it, we have created an image classifier machine learning app in using a Javascript library.

Example:

Giving this image to our classifyImage function will returns a prediction result from the pre-trained model that we have used from ML5.js library.

The app is 90.23570418357849% sure that this is Border collie.

Conclusion

Almost all the industries are now disrupted by Artificial Intelligence. Its now helping in automating manual tasks which requires less human cognitive abilities.

There is more to explore in the field of machine learning and AI, although I assume that now have got the basic understanding and a starting point.

Thank you for reading!!🙂

References:

Getting started with Machine learning/AI
Share this

Subscribe to Logicwind