Okay, my friends, let's do this.
Are you ready to implement the code to visualize your results?
Here we go. Let's do it together.
So we're going to do it efficiently.
We're going to start from
our polynomial regression implementation the visualization code at the end.
So we're going to copy it.
Then we're going to create a new code cell here and paste it.
Okay.
And now the exercise is to figure out what we have
to change here in order to adapt to our SVR model.
So let's do this. First let's make the obvious change.
Let's replace here polynomial regression by SVR.
And then let's see row by row what we have to change.
Okay.
So for the first row remember that x and y
are the scaled values of the inputs and the outputs.
So if we want to have a nice plot with the original values
of the position levels and the salaries, well the first thing we have to do
is to reverse the scale of the inputs x and y to put them in their original scale.
Okay.
And to do so well, we're going to take our scaler objects
X, NSC, y and applied inverse transform method on each of them.
Okay. So let's do this. Let's start with x.
We take our c x scaler object from which we apply
the inverse underscore transform method onto x.
Okay. Perfect.
Now these are the same for y.
Let's take our c y scaler
object from which we call again to inverse
transform form method onto y.
Excellent.
And we're done with the first row.
Now second row.
Let's take care separately of the input x and the prediction.
So for x once again we have to apply the reverse transformation
to get the original square.
So there we go again we call our c underscore x square object
from which we apply again the inverse transform method.
There we go. Apply to x. Okay.
And now this is where things get interesting.
We're going to take care of the predictions now of the inputs and x.
So of course we have to remove this whole line rect to predict fully
rect fit transform x and replace it by something.
And now the question is what do we have to replace it with.
Well it is going to be something similar to the prediction we made here.
Only here we made it for a single observation.
And so we need to adapt this to X. Right.
Because now we're making the predictions of the inputs in the x.
Okay.
So what we're going to do is take this whole prediction here.
We're going to replace
that whole line rect to predict rect fit transform x by the prediction.
We just copied.
And now let's see how we have to adapt this.
So let's start from inside the predict method.
Of course we want to replace 6.5 by x.
But here we had to apply x transform on 6.5.
Because 6.5 is the original square.
And the predict method has to be applied on the scaled values.
But now since we apply the break method on x and since x is already scaled
well, we must not reapply the transform method on x,
and therefore what we need to replace here is this whole six transform 6.5
by indeed x because x is already scaled.
So there we go.
And now I think that's it. I think we're done.
That was pretty efficient.
But you know we're never too safe from human error.
So we're going to double check this by executing right away.
Could see up here.
So there we go.
Let's click run cell here.
And let's see what happens. And there we go.
We did it all correctly.
This is indeed the curve of the SVM model.
And as we can see the predictions in blue go pretty close to real outcomes in
red except for that last one which would make it an outlier.
But that's how it is.