Model Prediction and Evaluation

9 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.89
List Price:  €65.66
You save:  €18.76
£40.14
List Price:  £56.20
You save:  £16.06
CA$68.77
List Price:  CA$96.29
You save:  CA$27.51
A$77.85
List Price:  A$109
You save:  A$31.14
S$68.06
List Price:  S$95.29
You save:  S$27.23
HK$391.53
List Price:  HK$548.18
You save:  HK$156.64
CHF 45.40
List Price:  CHF 63.57
You save:  CHF 18.16
NOK kr551.72
List Price:  NOK kr772.45
You save:  NOK kr220.73
DKK kr349.96
List Price:  DKK kr489.98
You save:  DKK kr140.01
NZ$84.81
List Price:  NZ$118.75
You save:  NZ$33.93
د.إ183.59
List Price:  د.إ257.05
You save:  د.إ73.45
৳5,486.08
List Price:  ৳7,680.95
You save:  ৳2,194.87
₹4,172.99
List Price:  ₹5,842.52
You save:  ₹1,669.52
RM239.12
List Price:  RM334.79
You save:  RM95.67
₦64,837.03
List Price:  ₦90,777.03
You save:  ₦25,940
₨13,921.65
List Price:  ₨19,491.43
You save:  ₨5,569.77
฿1,842.30
List Price:  ฿2,579.37
You save:  ฿737.06
₺1,629.48
List Price:  ₺2,281.41
You save:  ₺651.92
B$262.04
List Price:  B$366.88
You save:  B$104.84
R959.90
List Price:  R1,343.94
You save:  R384.03
Лв91.81
List Price:  Лв128.54
You save:  Лв36.73
₩69,005.19
List Price:  ₩96,612.79
You save:  ₩27,607.60
₪189.25
List Price:  ₪264.97
You save:  ₪75.71
₱2,877.72
List Price:  ₱4,029.04
You save:  ₱1,151.32
¥7,722.83
List Price:  ¥10,812.58
You save:  ¥3,089.75
MX$863.38
List Price:  MX$1,208.81
You save:  MX$345.42
QR183.01
List Price:  QR256.24
You save:  QR73.22
P692.91
List Price:  P970.12
You save:  P277.21
KSh6,673.66
List Price:  KSh9,343.66
You save:  KSh2,670
E£2,416.04
List Price:  E£3,382.65
You save:  E£966.61
ብር2,855.11
List Price:  ብር3,997.39
You save:  ብር1,142.27
Kz41,788.72
List Price:  Kz58,507.55
You save:  Kz16,718.83
CLP$48,306.33
List Price:  CLP$67,632.73
You save:  CLP$19,326.40
CN¥361.98
List Price:  CN¥506.81
You save:  CN¥144.82
RD$2,964.58
List Price:  RD$4,150.64
You save:  RD$1,186.06
DA6,727.90
List Price:  DA9,419.60
You save:  DA2,691.70
FJ$113.77
List Price:  FJ$159.29
You save:  FJ$45.51
Q390.19
List Price:  Q546.30
You save:  Q156.11
GY$10,464.15
List Price:  GY$14,650.65
You save:  GY$4,186.49
ISK kr7,049.58
List Price:  ISK kr9,869.98
You save:  ISK kr2,820.40
DH508.26
List Price:  DH711.61
You save:  DH203.34
L895.32
List Price:  L1,253.52
You save:  L358.20
ден2,892.26
List Price:  ден4,049.40
You save:  ден1,157.13
MOP$403.21
List Price:  MOP$564.53
You save:  MOP$161.31
N$955.36
List Price:  N$1,337.58
You save:  N$382.22
C$1,846.22
List Price:  C$2,584.86
You save:  C$738.63
रु6,679.70
List Price:  रु9,352.12
You save:  रु2,672.41
S/188.05
List Price:  S/263.28
You save:  S/75.23
K190.63
List Price:  K266.90
You save:  K76.27
SAR187.52
List Price:  SAR262.55
You save:  SAR75.02
ZK1,278.41
List Price:  ZK1,789.88
You save:  ZK511.46
L233.40
List Price:  L326.78
You save:  L93.38
Kč1,184.86
List Price:  Kč1,658.90
You save:  Kč474.04
Ft18,513.99
List Price:  Ft25,921.07
You save:  Ft7,407.07
SEK kr547.37
List Price:  SEK kr766.36
You save:  SEK kr218.99
ARS$43,479.20
List Price:  ARS$60,874.37
You save:  ARS$17,395.16
Bs346.66
List Price:  Bs485.36
You save:  Bs138.69
COP$194,909.58
List Price:  COP$272,889.01
You save:  COP$77,979.42
₡25,134.79
List Price:  ₡35,190.72
You save:  ₡10,055.92
L1,238.50
List Price:  L1,734
You save:  L495.50
₲371,169.19
List Price:  ₲519,666.57
You save:  ₲148,497.37
$U1,936.04
List Price:  $U2,710.62
You save:  $U774.57
zł202.87
List Price:  zł284.04
You save:  zł81.16
Already have an account? Log In

Transcript

Now we have trained the model. Let's see, let's evaluate the model by running them on the test data set right. So test data set what we have done is we are giving the image So, once we train the model, the model has a predict method to which we just to feed Third, the test input dataset. So, here we just feed the test data set without any labels, and the model will predict certain data, right. So this is the actual output the model will predict. And we will compare with the test accuracy expected output.

And then we can plot the confusion matrix and the model can tell you what is the procedure and recall the f1 score for the test. So let's do that here. Let me run this again. So it's predicting now it will take few moments. Okay. So the model has been prediction has been done.

And the model is printed the evaluation report where it has outputted procedure recall f1 score and other metric right. The most important metric is precision recall the f1 score that we want to understand here. Now understand it came can And one important thing to note is, unlike a traditional ml model, it's not learning anything during training time. It actually does the calculation during the prediction time because as we saw in our model right algorithm here What it does is given a test it as it as a code, it computes the distance between each of the available training data set. And then it will, and then it sorts, the nearest neighbor and then based on the majority voting, it will compute the output, right? That's all it's doing.

So for each label, like zero is dog, one is cat, and two is panda. It outputs the matrix right? So as you can see, for Panda, the precision is really high. I think that's because if you think about it, pandas are really easy to identify because they just can be of two color red, black and white. But if you take example of a dog or an image, the precision would be a little bit lower because because you know there are variations rights. Cats and Dogs are different colors.

They have a different type of four and they will be different positions, different background. So in that case, the procedure is little bit lower for dogs and four cats, right? And the recall is high for cats, but it's lawyers for better, right. Now, as you know, in the evaluation matrix study, we know that our goal is to maximize the f1 score. And here we observe that the f1 score is good for cats, and it's lower for dogs and then is lower for panda. So this is the ad if you just average our accuracy, this is also the accuracy about 55%.

Right? So So our procedures overall our f1 score, if it were random guess right our parameter prediction mean you can get a 33% probability, right? So as long as our model predicts, with There are three different outputs and all of them are of equal value. So random prediction will give you one third which is point three 3% 10% accuracy. So our definitely model is doing definitely better, right? As compared to the random prediction.

Now, how you can hyper tune the parameters of this model and see how the model metrics would vary, that will definitely vary because, as you can see here, number of ports we considered as to in this particular case, right. So, at least the two levers have to vote consistently to say that it's a dog. What would happen if we lower the number of neighbors instead of two? Let's say if we do one, what would happen do you think? Can you guess? Let's try it out.

So I'm going to change the number of neighbors to one and see Output change, as you can see, this is remember with a number output score with the number of neighbors to Let's run, I'm going to run the whole program again. So you can see the kernel and restart and run all. Let's see what happens in this particular case. This reading the entire code again now instead of doing cell by cell running, and let's see how it changes. So they attend the training and now it's doing the prediction Alright, so here the maximum precision that you can get is 70%. Right and the maximum score we can get is point four, five.

So as you can see the full score is lowered as you change the value of neighbors from two to one, right? So I think so. So that's how you play with the score edit, because our goal is to maximize f1 score. So number of neighbors two was definitely a better choice, right. So as you can see, then recall has increase in this particular case, because as you reduce the number of neighbors, you will get more and more true positive at the same time, you will get more and more false positive as well. So this is definitely not a good choice number of neighbors one, let's see what happens you should change to three, right?

And then run the whole program again. So this is how you should do this kind of hyper parameter of you. model, this is how you should keep playing with the different hyper parameters and choose the value that gives you maximum f1 score. So the training is done in leads to the prediction. So as you can see prediction. So the position is very good for Panda, but the f1 score isn't changed significantly.

So what we observed is so when the number of papers were two, we got a maximum of f1 scores. So that should be the choice for running your code. So you saw the typical process that you go through when you're training and after doing a prediction. You First pre process your data set, make sure you flatten your data set, then you split into train and test dataset, then you use to train the model and then you use to do the actual prediction and then you evaluate your score. And then choose the model with the x maximum f1 score. Now in practice, this is good lesson, you know, just for beginners.

Now in practice, you know, this much of FIFO score is not good enough. So we need to use more sophisticated algorithms like CNN, or LST M's. But if you start doing that, right from the beginning, you will get turned off because of the complexities into the algorithms. So by learning about kn and most of the basic stuff, you can get out of the way, and all you can actually focus on just selecting an actual algorithm. Now you've actually understood the skeletal structure of choosing any algorithm in your code, and you can easily swap in K nearest neighbor with some other algorithm Engines run the entire code in a similar fashion right? So that basically is out of the way and you could keep playing with new algorithms and see what best f1 score you get and then you can arrive at that algorithm.

So this is how you evaluate a model.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.