# How to Predict using a Machine Learning Model?

Most beginners don’t know how to predict values using a machine learning model. What they do is train a model and check its accuracy and they end the task. But before you complete it, you should test how the model predicts on the test set or some other dataset that your machine learning model has never seen before. So, if you want to learn how to predict values using a machine learning model, this article is for you. In this article, I’ll walk you through how to predict using a machine learning model.

## How to Predict using a Machine Learning Model?

As a newbie to Data Science, you need to be clear about some fundamentals about the values you use to train a model and the values you predict by your trained model. The values that you use to train a model are called features, and the target values that we want to predict are called labels.

Before predicting values using a machine learning model, we train it first. To train a model, we first distribute the data into two parts: x and y. In x we store the most important features that will help us predict target labels. In y, we only store the column that represents the values we want to predict. For example, when training a model to predict future stock prices, we usually use open price, high price, and low price as features to train the model and we use the closing price for the target label.

Then the next step is to split the data into training and test sets for which we use the train_test_split method from the scikit-learn library inÂ Python. Then we choose an algorithm and fit the training set to train a model on the data. This is where most beginners stop after calculating the accuracy of the model.

## Here’s How to Predict using a Machine Learning Model

After training the model, you need to use it somewhere to see if it predicts labels on the test data or a dataset that your model has never seen before. So, to predict values using your machine learning model, you just need to write just a few lines of code as shown below:

Here are some examples that will give you a complete idea of predicting values using a machine learning model:

### Summary

So this is how you can predict values on unseen data by using your trained model. As a beginner, you should always test how the model predicts on the test set or some other dataset that your machine learning model has never seen before. I hope you liked this article on how to predict values using a trained model. Feel free to ask your valuable questions in the comments section below.

##### Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of dataðŸ“ˆ.

Articles: 1535