Hello my friends, welcome to this new tutorial.
And now we're about to train the SVR model on the whole data set.
After a successful data preprocessing phase
with your new experience in feature scaling,
because now you can handle very well all the different situations.
All right.
So let's train that SVR model on the whole data set.
Of course,
because we did not do a split of the data set between training and test sets.
So there you go.
Let's create a new code cell.
And now let's build of course in the most efficient way the SVR model.
So we're going to build it with scikit learn.
Of course I remind that scikit learn is the best data science library
excluding deep learning, because of course we have TensorFlow and PyTorch.
But for any machine learning model that is not based on neural networks,
well, scikit learn is definitely by far the best data science library.
And for what we are interested in right now, you know the SVR model.
Well, we will build it with a class called SVR, as simple as that,
which belongs to a module of scikit learn called SVM.
And so we have to start here from
first scikit learn to access the scikit learn library from which
we're going to get access to that SVM modules.
That's the module from which we're going to import that SVR class.
Perfect.
Now we have the class.
And you of course know the next natural step.
Any time you import a class, next natural step is, of course,
to create an object or an instance of this class.
And we're going to call that object regressor.
Just like before.
Because this instance or object of the SVR class
is nothing else than the SVR regressor itself.
You know, the support vector for regression regressor.
So regressor.
And then of course we are going to call this class SVR.
Add some parenthesis.
And this time we have to input a parameter
because indeed remember in the intuition lecture of support vector regression.
And you will also see in the intuition lecture of the support
vector machine in the next part, part three classification.
Well, you actually have what we call kernels
which can either learn some linear relationships and that's the linear
kernel or non-linear relationships in your data set,
which are the nonlinear kernels such as the RBF radial basis.
I will actually show it to you right away.
You know, that's the Gaussian RBF kernel which is given by this formula.
And I can actually show you the plot of that kernel.
Here it is.
So that's the Gaussian RBF kernel.
And then you also have some other kernels which I've prepared
here on this great website, showing clearly the different kernels
of the support vector machine, but also the SVR, because as we are,
is nothing else than a support vector machine model for regression.
So let's see here they are.
There is the polynomial kernel adapted for a non-linear data set.
You have two Gaussian kernel which has a classic Gaussian function.
Then the Gaussian radial basis function.
The most widely used one.
And that's actually the one we will use.
Then you have the Laplace one, the hyperbolic tangent kernel as well.
That's a popular one sigma one.
Well you have all of them here.
And so if you're curious yes, you can have a look at them.
But the one we will use for our implementation will be
and that's the one I recommend each time you experiment with an SVR model.
And that's the radial basis function kernel, the RBF kernel.
And that's exactly what we have to input here in our parameters.
And so the name of that parameter is kernel.
So that's the name of the parameter.
And then the value we want for that parameter which you know
corresponds to the radial basis function has the code name in quotes are the f.
And that's it.
That's only what we have to input here.
So that basically creates the SVR model with the radial basis function kernel.
And so now that means only one thing.
That means that we already have built the model.
We already have the SVR model itself.
And so now the last final natural step is to of course
train that regressor on the whole data set.
Right. Which is also the training set. Okay.
So let's do this. You know exactly how to do this.
You know from this point it's exactly the same as before.
You know, the same function, which is of course the fit function
and which will train this SVR model on your whole data set,
right, to learn the correlations between the position levels and the salaries.
And all this done with the radial basis function kernel.
All right.
So let's do this. Let's train our regressor.
So we take our regressor object first.
And as usual we add here a dot.
And then the fit method which takes as input this time not xtrain
and y train because we have not created a separate training set.
But of course this time the whole data set which remember was feature scaled,
you know, both on the matrix of features export and the dependent variable y part.
And so that's exactly what we have to input here both x and y.
And that's it. Congratulations.
Now you know how to build and train and SVR model.
After a successful data preprocessing phase including special feature scaling.
All right.
And so now we have a very interesting next step.
It is the step where we predict the new result.
And this next step is very interesting because it will teach you
how to reverse the scaling of your prediction.
Because you will see that when we apply the predict method to predict
this new result, well, it will be returned in the scale that was used for Y.
Right?
The new scale of Y after it was transformed.
And so we will have to reverse this transformation.
We'll have to reverse the scaling in order to get the original scale of Y.
And now we'll teach you exactly how to do it in the next tutorial.