Javatpoint Logo
Javatpoint Logo

Prediction and linear class

In this, we took a brief introduction to implement a machine learning based algorithm to train a linear model to fit a set of data points.

For this purpose, there is no need to have any prior knowledge of deep learning. We will start with the discussion of supervised learning. We will discuss the notion of supervised learning and how it relates to it.

Machine Learning

Machine learning is an application of AI. ML (Machine Learning) provides systems the ability to learn and improve with the help of experience automatically. ML focuses on the development of computer programs which can access data and use it for themselves to learn.

The process of learning begins with data or observation, such as examples, instructions or direct experience, in order to look for patterns in data and make better decisions in the future based on the examples which we provide. Its aim is to allow the computers to learn automatically without human intervention and adjust actions accordingly.

Prediction and linear class

Supervised Learning

As the name indicates about the presence of a supervisor as a teacher. In supervised learning, we train or teach the machine using well-labeled data. Well labeled means few of the data is already tagged with the correct answer. After that, the machine is provided with a new set of data. Supervised learning algorithm analyses the training data and produces a correct outcome from labeled data.

Supervised learning is classified into two broad categories of algorithm:

  1. Classification: A classification problem is a problem when the output variable or simply output is a category such as "red" or "blue" or "disease or no disease."
  2. Regression: A regression problem is a problem when the output variable or simply output is a real or continuous value such as "salary" or "weight."

Unsupervised Learning

In unsupervised learning, the machine is trained using information which is neither classified nor labeled and allow the algorithm to act on that information without guidance. In unsupervised learning, the task is to group unsorted information according to similarities, differences, and patterns without any prior training of data.

There is no supervisor, which means no training will be given to the machine. So, the machine is restricted to find the hidden structure by itself.

Unsupervised learning is classified into two broad categories of algorithm:

  • Clustering: A clustering problem is a problem where we have to discover the inherent groupings in the data. Such as grouping students by course or age behavior.
  • Association: An association problem is a problem where we have to discover rules which describe a large portion of our data, such as people who buy apple also want to buy a banana.

Making Prediction (Creating Data Model)

Making a prediction is the initial step of making a linear regression model. In a linear regression model, we use supervised learning because regression is its second broad category. So the learner is trained and makes use of data sets associated with labeled features which define the meaning of our training data.

The learner is able to predict a corresponding output before giving the newly input data to the machine.

Steps to find the prediction

  • The first step is to install the torch and import it to work with it.
  • Next step is to initialize the variable c and c to know the equation of a line.
  • Initialize the equation of line such that y=w*x + b, here w is slop and b is the bias term, and y is the prediction.
  • Prediction is calculated inside the forward () method.

Let see an example to understand how prediction is made in linear regression.

For single data

Output:

tensor([13.], grad_fn=<AddBackward0>)

Prediction and linear class

For multiple data

Output:

tensor([[13.],
        [16.],
        [19.]], grad_fn=<AddBackward0>)

Prediction and linear class

Prediction using linear class

There is another standard way of binding prediction. For this, we have to import the linear class of torch.nn package. In this, we use manual_seed() method to generate random numbers. When we are creating a model with linear class, it will be given random number values for the linear class, which makes sense since the recall.

Let see an example of how prediction is made with the model and manual_seed() method.

For single data

Output:

<torch._C.Generator object at 0x000001FA018DB2B0>
Parameter containing:
tensor([-0.4414], requires_grad=True) Parameter containing:
tensor([[0.5153]], requires_grad=True)
tensor([0.5891], grad_fn=<AddBackward0>)

Prediction and linear class

For multiple data

Output:

<torch._C.Generator object at 0x00000210A74ED2B0>
Parameter containing:
tensor([-0.4414], requires_grad=True) Parameter containing:
tensor([[0.5153]], requires_grad=True)
tensor([[0.5891],
        [1.6197],
        [2.6502]], grad_fn=<AddmmBackward>)

Prediction and linear class




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA