Okay.
Good. So now we're going to test that out.
Of course this whole implementation is over
because all the rest comes from our different templates.
The data preprocessing template, the data preprocessing toolkit
and the logistic regression implementation.
You know, for the rest.
So now we can just run the whole code and see what happens in the end.
So basically we are ready to run this code.
But before let's not forget to upload the data sets inside this notebook.
So let's click this button.
Then please find your machine learning.
Is that folder on your machine wherever you downloaded it.
And then let's go inside.
Part nine dimensionality reduction.
Then principal component analysis then Python.
And there we go.
In the Or wine dataset click open and click okay.
And now now you're ready to run this
implementation with simple run all.
So let's click runtime here.
And are you ready.
Let's do this in 321.
Go. Run all.
All right.
Importing the libraries and importing the data set.
Or applying the data preprocessing phase.
Then applying PCA.
Well it goes way faster than me.
And what do we end up with?
Well, we actually end up with an amazing accuracy of 97%.
So this business owner, you know, of this wine shop definitely
had a great intuition with this idea of applying dimensionality reduction.
Because, you know,
dimensionality reduction doesn't only consist of reducing the complexity
of your data set, it can also improve the final results, you know,
by combining dimensionality reduction and your predictive model.
And here this is exactly what happens.
We get an amazing accuracy of 97% with actually only one incorrect prediction.
Right. And here by the way this is interesting.
This is the first time you see a confusion matrix of three rows and three columns.
And that of course this time we have three classes, right.
We have three customer segments one, two and three.
Therefore we have three classes to predict.
And so this is the number of correct predictions of customer segment one.
This is number of great predictions of customer segment two
this is the number of repetitions of customer segment three.
And this is the number of incorrect predictions of customer segment one.
Right.
So anyway only one incorrect prediction in total.
And that's why we end up with such a great accuracy.
And so now we should see amazing results on the graphs.
You know, for us with visualizing the training set results.
And indeed well, you know, these are our two principal components
PC1 on the x axis and PC2 on the y axis.
And then these are you know, the different prediction regions.
This is the prediction region of class number three where each one of which
the extracted coordinates of PC1 and PC2 are in this blue
region will be predicted to belong to customer segment number three.
Then this is the prediction region of customer segment number two,
where all the wines for which the PC1 and PC2 extracted features
that fall in this green region will be predicted to belong to customer
segment number two.
And finally, this prediction region red corresponds to customer segment number
one, inside which all the wines of which the extracted feature is PC1 and PC2
fall in this region will be predicted to belong to customer segment number one.
All right. And then of course all the dots.
You know the green dots here,
the blue dots here and the red dots here are the real observations.
You know the real wines themselves of the training set.
And so here we can indeed see that we have a few incorrect predictions.
But that's only on the training set.
For example, this is a green wine meaning a wine that belongs to customer
segment number two,
which was predicted by the model to belong to customer segment number three.
And these are two other incorrect predictions of wines
that belong in reality to customer segment number two,
but were predicted by the model to belong to customer segment number one.
All right.
And then another incorrect prediction here.
But to look at the incorrect predictions,
it's more interesting to check them out on the test set.
And here is a test set.
And indeed even on new observations.
Well our logistic regression model combined to dimensionality
reduction was perfectly able to separate well the three classes.
And we can see very well that, you know, incorrect prediction that we saw here
in the confusion matrix, which is, you know, right here
that's the incorrect prediction and corresponds to a green wine,
meaning a wine that in reality belongs to customer segment number two,
but was predicted by the model to belong to customer segment number one.
That's okay.
You know, any business owner or data scientist that ends up with such
result with only one incorrect prediction can just be super happy.
But let's see if we can beat that with our other
dimensionality reduction techniques like linear discriminant analysis.
And you know, to beat that, well, we'll have to simply get 100% accuracy.
So we'll see if you know the linear discriminant,
which are the extracted features of the LDA technique, can build, you know,
a prediction boundary that can separate, well, all these three classes.
So this will be quite challenging.
But this is doable.
And then we'll check if we can also do the same with kernel PCA
which is our final dimensionality reduction technique.
All right.
So as soon as you're ready for the next technique well I'll be super
happy to join you in the next practical activity to implement LDA.
And until then, enjoy machine learning.