DEV Community

Cover image for Machine Learning For Newbies
Esther
Esther

Posted on • Updated on

Machine Learning For Newbies

What is Machine Learning?

Machine learning is a field in AI that revolves around training software (using large amounts of data) to act, think, and predict information the way humans do. This is why it's called machine learning. The software being trained to make predictions is called a model.

What is a Model?

A machine learning model is a software program that can predict new information based on the data it was trained on. The model consists of an algorithm that helps it make predictions. For a model to start making predictions, it has to be trained. The process of passing a lot of data to the model is called training. After a lot of training, it can begin to predict nearly accurate values. This prediction is called ‘inferencing’.

The training data usually consists of two things: features & labels. The features are the characteristics of the data while the label is the value you want to train the model to be able to predict. In Machine Learning, it is visualized as x and y: features(x), label(y).

Here's a simple example:

To train a model that can predict the number of jacket sales based on weather, we would give the model information such as - The weather measurements for the day e.g temperature, these are the features (x), and the number of jackets sold on each day, these are the labels (y).

To implement in code, it would like this:

//Javascript
const data = [
  {
    temperature: 20, //feature
    jackets sold: 30, //label
  },
  {
    temperature: 36, //feature
    jackets sold: 10, //label
  },
  .......
]
Enter fullscreen mode Exit fullscreen mode

This data is sent to the model, it runs an algorithm and studies the data. To validate what the model has learned, we send more data to evaluate its learning.

How Do We Actually Validate That The Model is Learning & What Data Do We Use?

When training the model, we can send 80% of the training data and keep 20% back for evaluation. After training, we send the evaluation data, the model makes a prediction and how far the prediction is from the correct value determines whether or not the model is learning enough & is ready to make predictions, kind of like a test run. The training data must be not be split in 2 ie 80%, 20%, you can train with entire data & test with fresh data.

Using the previous jacket example, this is what the process would look like:

Machine learning cycle

Input training data on jacket sales 
-> model runs algorithm 
-> algorithm studies relationship between temperature and jacket sales
-> input more jacket data to model to evaluate learning 
-> model predict jacket sales
-> compare predictions with the actual validation data 
-> evaluate false prediction rates using special calculations 
-> start over.
Enter fullscreen mode Exit fullscreen mode

This is an example an algorithm to run the training data on jacket sales.

The model is usually depicted as a function that takes in an input and returns an output: y = f(x)

Training a model is doing this over again with large amounts of data (this can be done with different algorithms). When a model is being trained, it runs a specific algorithm on the data to establish patterns and relationships, after training is over, the model will contain the learned patterns & relationships as well as algorithm configurations. Upon deployment, the model becomes a self-contained system that can process input data on its own without needing to run through an algorithm each time.

As you probably guessed, training a model on bad data will yield incorrect predictions which can be very costly. Data must be clean and pass several checks to produce the desired results.

Types of machine learning

  1. Supervised Machine Learning: This is a form of machine learning where we provide training data consisting of both the features & labels. In this method, we carefully curate the data we provide the model, giving it both attributes and labels to enable it to make predictions of its own.

    Types of Supervised Learning

    • Regression: This is a form of supervised learning where the model is trained to predict a numeric value. e.g The number of icecreams sold on a given day (label - y) based on weather (feature - x) or the number of shirts (label - y) sold based on salary of buyer (feature - x) etc. This data is passed through an algorithm such as linear regression and the predicted values (called y-hat in math speak ŷ) are compared with the actual values and based on that we understand how far off the model is in it's predictions.
    • Classification: This is another form of supervised learning where the model is trained to assign the label being predicted to a class. The "class" here is a terminology to mean grouping and they are predefined e.g If we wanted to predict the species of animals based on body structure, in the training data being passed to the model, we would specify animal features and their species. Based on this, after training, the model when given new data can assign it to a species and predict it as such.
      • Binary Classification: In this type of classification, the model is trained to predict only two classes - true or false. e.g A model that helps to predict if people can afford a certain school(label) based on age, salary, inheritance, parents careers(features). When given data, this model will either respond with a true or false. We can imagine a model such as this is trained on the data of the students that are already in the school. We can use algorithms such as Logistic regression to train for this outcome.
      • Multiclass Classification: In this type of classification, the model predicts input data as belonging to a single or multiple classes. e.g A model that can predict the genre of books (a book can have multiple genres). We can use algorithms such as One-vs-Rest(OVR) & multinomial algorithms to achieve this.
  2. Unsupervised Machine Learning: In unsupervised learning, we provide training data consisting of only features without any labels. In this method, the model itself will start to determine relationships between the features and come up with labels itself. We basically tell the model "figure it out".

    Types of Unsupervised Learning

    • Clustering: In clustering. the model identifies similarities in the data based on features and starts to group them based on that. It is similar to multiclass classification in the fact that it groups data but the difference is in multiclass, we already know what the classes are based on previous learning but in clustering, we don’t. So we give it a bunch of data and ask it to figure it out and learn on it’s own. e.g We can provide a model a bunch of student data and it will group the data by age, gender, class, tuition, address etc. We can use algorithms such as K-Means clustering for clustering.

This is a really simplified background on machine learning to introduce newbies to the field. There's a lot of technical speak surrounding AI today and I hope this article helps a confused person out there.

Thanks for reading!

Top comments (0)