Supervised Learning made easy

In the previous articles, we had a short introduction to artificial intelligence and machine learning. In this article, we start to introduce the first technique for machine learning, Supervised Learning.

What is Supervised Learning

If we read Wikipedia we can read this definition of Supervised Learning:

Supervised learning (SL) is the machine learning task of learning a function that maps an input to an output based on example input-output pairs. It infers a function from labeled training data consisting of a set of training examples. In supervised learning, each example is a pair consisting of an input object (typically a vector) and a desired output value (also called the supervisory signal).

However, for a better understanding of how a supervised algorithm works, let’s define some basic terms useful to build our algorithms.

How we know the fuel of every machine learning algorithm, is the data, a supervised learning algorithm used as an input a dataset as a collection of labelled data

Figure 1 – An example of labelled data

More formally we can describe the dataset of the labelled data in this way:

    \[ \{(x_i,y_i)\}^N_i_=_1 \]

Each element of xi among N is called a feature vector. A feature vector is a vector in which each dimension, j=1,…., N contains a value that describes the example in analysis. This value is called feature and is denoted by the syntax x (j).

The goal of supervised learning is to predict the data in input based on the feature present on the data and then classify the data itself. Figure 1 shows how a feature work, in the figure we see the labelled data, Dog and the different weight, for example, 18 lbs or 14 lbs. A feature is essentially the characteristic connected with the data, the feature is important when we want to classify.

Classification vs Regression

When we talk of Supervised Learning, the idea is generally to solve two major types of problems:

  • Classification
  • Regression

A classification problem is a type of problem where machine learning tries to classify the data based on the previous observation.

A typical example is a spam filter, the filter learns the common rules to classify the mail as spam or not, this type of classification is called binary classification.

Another type of classification is called multiclass classification, this type of classification can be used for example to recognize different types of animals, we feed the algorithm with different pictures and the algorithm classify the animal on unseen data.

The essence of the Classification is essential to assign a categorical label to unordered and unseen data.

There is another important task connected with Supervised Learning, this is called regression.

Regression analysis is used to predict a continuous outcome variable based on a prediction, if we want to be more formal, a regression analysis is for finding a correlation between some independent variable and one dependent variable. A classical example of regression analysis is the prediction of the price of a house based for example on the square feet or the location.

Algorithm for Supervised Learning

We now have an idea about supervised learning, and what type of problem we can solve with this technique, for a better understanding of how to use let’s see the major algorithm used with supervised learning.

K-Nearest Neighbor

The KNN or K-Nearest Neighbor is a simples algorithm used to classify data based on the similarity of the data. In the algorithm, the ‘k’ is used to identify the value of neighbour near the data point, this is used to analyze the value near the data point and then classify the data, new data are classified by the majority of vote of the neighbour, the number of neighbours used is identified by the value k.

Naive Bayes

Naive Bayes classifier is a probabilistic algorithm, this is based on the Bayes Theorem and is used to solve a classification problem. This type of algorithm is essentially a probabilistic classifier, this means the classification is done using a probability of an event using the Bayes Theorem:

    \[ P(A|B) = \frac{P(B|A) P(A)}{P(B)} \]

Where:

  • P(A|B) is the posterior probability, the probability of hypothesis A on the observed event B
  • P(B|A) is the likelihood probability, the probability of an hypothesis is true
  • P(A) is a prior probability, the probability of the hypothesis before observing the evidence
  • P(B) is the marginal probability, the probability of the evidence

Naive Bayes is used for spam classification or text classification.

Decision Trees

Decision Trees are used in both the problem from the supervised learning, Classification and Regression, for this reason, are sometimes called Classification And Regression Trees (CART).

In the Decision Trees, the prediction of the response is made directly by learning the feature derived from the features themselves.

In decision analysis, the decision tree can be used to visualize the data and explicitly represent decision and decision making.

Linear Regression

Linear Regression is one of the most basic algorithms for Machine Learning, with the linear regression algorithm, the model tries to find the best linear between dependent and independent variables.

Linear regression can be split into two main types:

  • Simple Linear Regression, where we have only one independent variable
  • Multiple Linear Regression, where we have more than one independent variable

In both cases, the model tries to find the correlation between the independent variable and the dependent one.

Support Vector Machine (SVM)

Support Vector Machine is another algorithm that can be used in both cases, classification and regression.

The SVM algorithm plot each data item as a point in the n-dimensional space, where n is the number of features we have in the model, each point represent a coordinate in the space.

With the coordinate defined, we use classification to find a hyper-plane used to differentiate the data.

Conclusion

In this article, we introduce the supervised learning algorithm, this is the first algorithm used in Artificial Intelligence and Machine Learning.

In the next articles, we start to see how to implement some of the algorithms presented and we see how this algorithm can be used to build our Machine Learning model.

If you are interested to go deeper into the algorithm I can suggest some amazing books:

If you like the article feel free to add a comment and ask any question you can have

Machine Learning an introduction

What is Machine Learning

Machine Learning is actually everywhere in our daily life. When we use the Netflix suggestion for the next film, or when Spotify suggest us a song that can match our taste, all of these are an example of applied machine learning. But how does all this software work and what are the ingredients for a machine learning system?

How a machine learn?

Machine Learning is a subfield of artificial intelligence, as we had seen in the previous article, often the term is used interchangeably, but they are different. Machine learning is a set of algorithms that allows the machine to learn how to perform a specific task based on the data. But how a machine can learn?

First of all, it is important to understand the basis of machine learning, and how this helps a machine to “learn”, and all start from the data.

In our modern world, we are overwhelmed by the data, every single minute of our life we produce or consume data, just think on every time you read a post on Facebook and leave a like, or when you post a tweet on Twitter, all this incredible amount of data, are the fuel for the machine learning algorithms.

In machine learning, we can adopt three major techniques for learning:

  • Supervised learning
  • Unsupervised learning
  • reinforcement learning

Supervised learning, is a technique where the data are labelled, this helps the computer to correctly classify the data, which means the data are grouped for types.

Figure 1 – The MIST dataset an example of Supervised Learning

On the other side, we can find the unsupervised learning technique where the data are not labelled, this means the algorithm classifies the data based on the data itself, for example finding information in common.

The last technique for learning is called reinforcement learning, this technique is probably the most complex, in reinforcement learning, we create a system, aka an agent, that learn based on the feedback the agent received from the external environment, for example, in a game the result of a win or lose can indicate a correct or wrong path to follow.

Both the technique, supervised and unsupervised, have a common base, they learn from the data, data are the fuel for the machine learning algorithms.

The last technique, reinforcement learning, is on the other side based on a different principle, this technique uses the feedback received for improving and learning.

Supervised learning

Supervised learning is a family of algorithms, used in machine learning to make a prediction based on evidence in the presence of uncertainty.

This technique is the most simple in machine learning, and it’s similar to what we do when we teach our kids, we essentially provide an example, the labelled data, and teach how to use and recognize the data.

Supervised learning uses two specific techniques for developing machine learning models:

  • Classification
  • Regression

Classification is used for simple classification problems, is used to recognize if a mail is genuine or spam, or for example is used to classify the type of cancer benign or not. A classification always split the data into two specific categories.

Common classification algorithms are:

  • Logistic Regression
  • Naive Baysen
  • K-Nearest Neighbors
  • Support Vector Machine
  • Decision Tree

We see in detail all these algorithms in a few future articles, for now, let’s just say this is all algorithms for classification.

Regression is used to predict continuous response, this is used for example to classify the forecast value for a financial market, or for example for understanding the variance of a temperature or a house price variation.

Common regression algorithms are:

  • Multi Linear Regression
  • Support Vector Machine
  • Decision Tree

We see and go deeper on classification and regression problems in the future article, where we can have a clear identification of the problem and a better understanding of the algorithm.

Unsupervised Learning

In supervised learning, we have labelled data and we apply an algorithm to predict and assign a label to new data. With unsupervised learning, the learning is different.

Unsupervised learning is used to learn directly from the data, without having any knowledge about the data before, the principal algorithm for unsupervised learning are:

  • clustering
  • neural network

We see more about unsupervised learning later in the series, and we see how to use and powerful this technique is, let’s now introduce the last of the three types of machine learning, reinforcement learning.

Reinforcement learning

The last technique of machine learning we present is reinforcement learning, this technique is probably the most complex but probably the most near to the human way to learn.

The goal of reinforcement learning is to develop a system, aka an agent, that improves performance based on the interaction with the environment, this means every iteration of the result predicted by the agent, will be validated by the environment.

In reinforcement learning, the agent receives rewards for every interaction, this reward indicates how good the model score versus the result we want to achieve, one good example of reinforcement learning is an engine of the game of Go, the agent can try to predict the next move based on the actual position of the piece on the board, if the prediction is right, the reward will be positive, in case the prediction is false, the reward will be negative.

Conclusion

In this article, we just had a short introduction to the basic types of machine learning. We saw what are the three main types of machine learning and we see the main difference between the types.

In the next articles, we go deeper on the different types starting with Supervised Learning. Machine Learning is one of the most fascinated fields in computer science, in this article and in the next of the series, I try to help you to develop some basic knowledge about machine learning.

An introduction to Artificial Intelligence

Artificial Intelligence, is the science of making machines do things that would require intelligence if is done by a men – Marvin Minsky

Artificial Intelligence is a term first coined at Dartmouth college in 1956, the term was coined by the Cognitive scientist Marvin Minsky.

When we talk about Artificial Intelligence, we talk about a different set of mathematical algorithms used for learning from the data.

Types of Artificial Intelligence

By definition, Artificial Intelligence is the science of making a machine, do things that would require intelligence.

Based on the definition we can define three types of artificial intelligence:

  • Artificial Narrow Intelligence, aka Weak AI, is the type of AI we saw every day, this is a basic type of intelligence and is used in our actual technology, this type of intelligence is used for one scope only, example of this type of Intelligence are for example the voice assistant like Srini or Alexa, the raking system, the NLP
  • Artificial General Intelligence, this type of intelligence is when the machine are able to learn and generalize like an human do, is able to learn and produce generic result, for some expert this type of artificial intelligence is impossible to achieve
  • Artificial Super Intelligence, this type of intelligence is a type of artificial intelligence where the intelligence is more higher then an human can do

How we can see there are different types of artificial intelligence, at least the theoretical level, and all have in common the goal to make a machine learn.

Domains of artificial intelligence

In this article, we talk about Weak AI, the actual AI we see and work on every day.

Figure 1 – The domain of the artificial intelligence

Figure 1 shows the subdomain of artificial intelligence, Machine Learning and Deep Learning.

Machine Learning is essentially a set of algorithms used for allowing a machine to learn, on the other side the Deep Learning, is a subset of methods direct derived from Machine Learning.

Machine Learning and Deep Learning

Machine Learning and its subfield Deep Learning are the core of the actual artificial intelligence, the weak AI.

Machine Learning is a subfield of computer science, the aim of machine learning, is to learn to execute a task, for which is not directly programmed, from the data.

The capability to learn from the data is an important capability from machine learning, and for artificial intelligence in general, this because, similarly how a man, or an animal, learn from experience, a computer learn from the data.

Deep Learning, is a subset of machine learning, deep learning uses a subset of the algorithm designed for machine learning and is used to solve some practical industrial problem. Some deep learning applications are for example computer vision, or natural language processing/natural language understanding.

Deep Learning differs from machine learning, and in some way expand machine learning, because in deep learning we use a set of algorithm called artificial neural network. This family of algorithms is inspired by the human brain.

Conclusion

In this short article, we just introduce what is artificial intelligence and what is the basic component of artificial intelligence. This is a first of a series of articles where we explore the different methods and algorithms used in artificial intelligence.

Every article made a deeper knowledge around a specific area of the field and is designed to give some practice knowledge in the exciting science of artificial intelligence.

How journaling can be useful for you

Journaling is a great way to express yourself and write down your emotions, the journal is a great way to analyse your emotion and create a space just for you.

What is a Journal

If we search in the dictionary what the term “Journal” means, we can find this definition:

“a written record of what you have done each day, sometimes including your private thoughts and feelings”.

This definition describes perfectly, what the practice of Journaling is and what the idea behind him, the Journal is essentially a “journey” of your day. In the journal you can write all you have done and most importantly all you have felt during the day, without any fear of any judgment, the journal is your personal space and is the time you dedicate to the most important person of your life, yourself.

The benefit of the Journaling

Journaling offers a huge benefit for our mental health. One of the most important is how to deal with overwhelming emotions.

Our daily life can be stressful, in particular with the Covid-19 pandemic crisis, most of us can fell under pressure, the work from home lifestyle most of us are pushed for, the kids at home and the problem with the on house schooling can create a lot of pressure to everyone, and this can lead to an overwhelming of emotions and stress.

Journaling can help us with:

  • Help us manage the anxiety
  • Help us to reduce the stress
  • Help us with depression

Write a journal, and adopt the journaling practice, help us to write down the situation we had lived during the day, this helps us to identify what situation create the stress or the anxiety. When we have identified the situation, we can easily work on a plan to reduce it.

How to journaling

There is no correct or wrong way to do journaling, you can write a journal in a simple notepad or on your computer, the only important thing for journaling is to write down what you have felt during the day, and keep in mind journaling is your daily personal space.

If you want to start journaling there are some tips that can help you to start your journey, at least this is what helps me with my journey:

  • Write at least three A5 pages per day, sometimes you can write less sometimes you can write more, but try to write 3 pages daily
  • Be open and honest, don’t worry about any judgment, write exactly what you feel
  • Schedule daily time for your journaling, have a booked time for the journaling help to be consistent, remember you want to build a habit around the journaling, and have a specific time dedicated to that help
  • When you start, don’t stop just continue to write. Start writing can be hard, for this reason when you start to write don’t stop, just write down what you have in mind
  • Take your time, when you write don’t rush, remember journaling is your time and is the time you use to reduce anxiety and stress

Writing a journal helps us to organize our thoughts and our emotions, this can drive the way to our self-awareness and helps to reduce the stress and the anxiety of the day.

Be a better person with the Emotional Intelligence

one can become angry, that is easy. But to be angry with the righe person, to the right degree, at the right time, for the right purpose, and in the right way, this is not easy. (Aristotele, The Nicomachean Ethics)

What is emotional intelligence?

If we search online for a definition for emotional intelligence, we can found this definition: “Emotional intelligence refers to the ability to identify and manage one’s own emotions, as well as the emotions of others”.

Emotional intelligence plays an important role in our daily life and can be defined using four attributes:

  • self-awareness, the ability to understand our own emotions recognize our strengths and our weakness and how these emotions affect our job and our relations
  • Self-management, the ability to manage our emotions and our behaviour in a productive and efficient way
  • Social awareness, this skill is directly related to empathy, you can understand other people emotions, you recognize and understand the power and the dynamics of a group of people
  • Relationship management, you can have a good relationship, you can communicate clearly and efficiently, and you can influence others and you can manage conflicts in a correct way

The importance of emotional intelligence for your success

My main job is as a Software Engineer, and of course, I daily interact with other team members. In this context, emotional intelligence is more important the IQ.

The why can be easily understood if we think about the four attributes of emotional intelligence.

When we work as a team, have good relations with other members of the team and understand what help others to give the best, is the golden ticket to drive the team productivity.

A recent study from Havard University and released by the National Bureau of Economics Research highlight the importance of emotional intelligence instead of IQ when we work as a group.

The study was made with 255 volunteers and evaluated using a standard test for intelligence and personality, the study shows how people with high EQ are more consistent instead people with only a high IQ.

The reason is simple, people with high emotional intelligence are able to understand how another member of the team feeling simple seeing their face, or during the meeting, they are able to “feel the room temperature” and because of that they can solve the conflict first this start and made all the member of the team motivated.

What makes emotional intelligence so important for our workplace is the capacity to be able to cool down under stress and because of that, people with high emotional intelligence are more successful instead people with the only IQ.

If we want to summarize what emotional intelligence can be useful for us this will be:

  • Help to make better decisions and a better process for problem-solving
  • Help us to stay calm under pressure
  • Help us to resolve conflict
  • Help us to listen better, and because of that to communicate more effectively

These are just some of the benefits brought to us by emotional intelligence.

How we can improve our emotional intelligence

How we can see emotional intelligence is an important skill to add to our repertory.How we can see emotional intelligence is an important skill to add to our repertory. Unfortunately, not everyone has the same level of emotional intelligence, but luckily for us, we can learn how to improve our emotional intelligence.

If we want to improve our emotional intelligence we can follow some simple strategies:

  • learn how we react to different situations, why we react in this way? what emotion trigger us? Do we have some bias? what are our beliefs? This can be done with journaling, for example, journaling is a great way to analyse our behaviour, you can have a small introduction about journaling in my previous post
  • Do a test to understand our weaknesses and our strength, for example, we can use the Gallup test in order to identify our weaknesses and strength
  • Examine how your behaviour impacts others, this helps you to raise empathy
  • Ask for feedback, this can be scary and for sure out of our comfort zone, but ask for feedback is a great way to collect information about ourself

These strategies can help to improve your emotional intelligence, but this is nothing we can do is not an easy task and require a lot of work on ourselves, this means leaving our comfort zone and investing a lot of energy in ourselves.

Personally, when I start my journey to improve my emotional intelligence, I start to read literature around that, one book I highly recommended is Emotional Intelligence: Why It Can Matter More Than IQ by Dr Daniel Goleman, this is one of my favourite books on the topics. But online you can find a lot of documentation on this topic, the important is to start the journey.

Conclusion

How we can see emotional intelligence becomes a very important skill to have in our “toolbox”. Luckily we can learn this skill and we can improve our emotional intelligence and this can help us to have a better quality of life not only in our work but as well in our private life.