Predicting best quality of wine using Linear Regression and PyTorch

Rishabh Roy
2 min readJun 30, 2020

--

In this notebook we will predict the best quality of the wine using PyTorch and linear regression. If you haven't checked out my previous blog on Linear Regression check this out .

Lets see what we are dealing with…

First of all lets import required libraries..

Lets load our dataset.

You can download the dataset from this link .

Now lets analyse our dataset.. its important to analyse to see what we are dealing with..

Lets separate our input and output vectors columns

now initialise input and output vectors

Its really important to convert our datatype of the vectors to the float… because the PyTorch always takes the float type tensors only

Now we have to separated our data in two parts… Training and Validation Datasets

Training Dataset: The sample of data used to fit the model. The actual dataset that we use to train the model (weights and biases in the case of a Neural Network). The model sees and learns from this data.

Validation Dataset: The sample of data used to provide an unbiased evaluation of a model fit on the training dataset while tuning model hyper-parameters. The evaluation becomes more biased as skill on the validation dataset is incorporated into the model configuration.

DataLoader

We have to keep in mind that in some cases, even the most state-of-the-art configuration won’t have enough memory space to process the data the way we used to do it. That is the reason why we need to find other ways to do that task efficiently. Using PyTorch DataLoader we can divide our datasets into batches which are being load in our memory one at a time.

Our train and validation loader has both inputs and target vector lets see how we can seperate them..

Model

After preparing data for our model now its time to create our first Machine Learning model. We will extend the nn.Model class present in PyTorch.. In this model we have some functions

Constructor:

In this function we initialise our ML model

Forward:

In this we call our ML model and predict the output on the input vectors

Training Step:

In this first we split the data into inputs and target vector from the batches and generate the prediction on the basis of input vector and calculation the loss on comparing the prediction and target vectors

Using evaluate and fit function we train our model by tuning the parameters of the model

we have successfully created our model now lets make our model predict something for this lets define a function which will predict some outputs

Congratulations you save successfully create a working ML model

download my notebook from this link → Click Here

--

--