You are on page 1of 15

NEAREST NEIGHBOUR 1

Wind
(kph) Humidity Conditions
10 74% Clear
12 62% Clear
9 44% Rain
3 77% Rain
7 61% Rain
8 33% Clear

The prediction will be made using three (3) nearest neighbours.

Given data point:

Wind 7 kph
Humidity 53%

Question 1

Using majority voting, predict whether the conditions will be clear or it will rain.

Question 2

Using the nearest neighbours, predict the probability of rain.

SOLUTION

% Sq Distance from
Wind Wind = Humidity = Corresponding Kth Smallest
(kph) Humidity Conditions 7 53% AVG Conditions k
10 74% Clear 0.1837 0.1570 0.17033 Clear 1
12 62% Clear 0.5102 0.0288 0.26952 Clear 2
9 44% Rain 0.0816 0.0288 0.05523 Rain 3
3 77% Rain 0.3265 0.2051 0.26579 Rain
7 61% Rain 0.0000 0.0228 0.01139 Rain
8 33% Clear 0.0204 0.1424 0.08140 Clear

Q1 The frequency of the 'y' values:


Clear 1
Rain 2 <<< Predicted value #AYMAN CHOWDHURY: Found the predicted value

Q2 Prob of Rain 66.7%


Kth Smallest
Distance Conditions
0.01139 Rain
0.05523 Rain
0.08140 Clear

URY: Found the predicted value by counting the number of times 'Rain" appears as a weather condition
NEAREST NEIGHBOUR 2

Profit Sales PE
Margin Growth Ratio
17.50% 5.28% 21.7
13.11% 4.14% 25.9
6.69% 3.44% 34.8
11.61% 1.61% 17.7
15.84% 3.03% 24.9
5.22% 1.72% 24.5
16.64% 6.07% 37.3
9.54% 6.06% 23.2
17.87% 4.82% 29.4
19.39% 5.37% 30.1

The prediction will be made using five (5) nearest neighbours.

Given data point:

Profit margin 14.7%


Sales growth 4.9%

Question 1

Using uniform weights, predict the PE ratio.

Question 2

Using weights inverse to the distance, predict the PE ratio.

SOLUTIONS
% Sq Distance from
Profit Sales Corresponding
Profit Sales PE Margin Growth PE Kth Smallest
Margin Growth Ratio 14.7% 4.9% AVG Ratio k
17.50% 5.28% 21.7 0.0363 0.0060 0.02115 21.7 1
13.11% 4.14% 25.9 0.0117 0.0241 0.01788 25.9 2
6.69% 3.44% 34.8 0.2969 0.0888 0.19285 34.8 3
11.61% 1.61% 17.7 0.0442 0.4508 0.24750 17.7 4
15.84% 3.03% 24.9 0.0060 0.1456 0.07583 24.9 5
5.22% 1.72% 24.5 0.4159 0.4212 0.41853 24.5
16.64% 6.07% 37.3 0.0174 0.0570 0.03722 37.3
9.54% 6.06% 23.2 0.1232 0.0560 0.08963 23.2
17.87% 4.82% 29.4 0.0465 0.0003 0.02338 29.4
19.39% 5.37% 30.1 0.1018 0.0092 0.05550 30.1
Q1 Using uniform weights, predicted P/E ratio: 28.88 #AYMAN CHOWDHURY: Found the predicted P/E r

Q2 Weights inverse to the distance:


Kth Smallest Inverse PE
k Distance Weight Ratio
1 0.01788 55.93477 25.9
2 0.02115 47.28653 21.7
3 0.02338 42.76258 29.4
4 0.03722 26.87068 37.3
5 0.05550 18.01936 30.1

Preidcted weighted average P/E ratio: 27.64499 #AYMAN CHOWDHURY: Found the weighted average P/E rati
Kth Smallest PE
Distance Ratio
0.01788 25.9
0.02115 21.7
0.02338 29.4
0.03722 37.3
0.05550 30.1
URY: Found the predicted P/E ratio by calculating the average of PE Ratios

the weighted average P/E ratio by finding the sumproduct of the inverse weightd and PE Ratios and dividing that by the sum of PE ratios
that by the sum of PE ratios
NEAREST NEIGHBOUR 3

Temperature Humidity Color


16 79% Yellow
10 64% Red
13 41% Red
14 77% Red
17 59% Yellow
12 33% Yellow

The prediction will be made using three (3) nearest neighbours.

Given data point:

Temperatu 11
Humidity 53%

Question 1

Using majority voting, predict whether the conditions will be yellow or red.

Question 2

Using the nearest neighbours, predict the probability of red


NEAREST NEIGHBOUR 4

Length Width Result


77 36 Pass
38 29 Fail
43 38 Fail
48 34 Fail
69 33 Pass
56 27 Fail

The prediction will be made using three (3) nearest neighbours.

Given data point:

Length 55
Width 32

Question 1

Using majority voting, predict whether the conditions will pass or fail.

Question 2

Using the nearest neighbours, predict the probability of fail


NEAREST NEIGHBOUR 5

NumberParticipation Rate
Results
110 84% legal
88 92% illegal
92 77% illegal
105 93% legal
130 72% illegal
126 95% legal

The prediction will be made using three (3) nearest neighbours.

Given data point:

Number 109
Participati 88%

Question 1

Using majority voting, predict whether the conditions will be legal or illegal.

Question 2

Using the nearest neighbours, predict the probability of legal.


NEAREST NEIGHBOUR 6

Price Popularity Trends


1088 76% down
1216 66% down
947 44% up
366 88% up
727 61% up
809 43% down

The prediction will be made using three (3) nearest neighbours.

Given data point:

Price 747
Popularity 56%

Question 1

Using majority voting, predict whether the conditions will be up or down.

Question 2

Using the nearest neighbours, predict the probability of up.


NEAREST NEIGHBOUR 7

Time Storage Wine Profit


15.37 1.61 66.34
8.87 1.21 43.68
16.97 1.88 73.32
14.43 1.47 58.87
7.66 0.84 39.69
9.39 0.87 46.54
12.28 0.96 37.3
11.11 1.13 48.31
6.03 0.54 29.97
10.98 0.77 52.56

The prediction will be made using five (5) nearest neighbours.

Given data point:

Time 11.86
Storage 1.09

Question 1

Using uniform weights, predict the Wine Profit

Question 2

Using weights inverse to the distance, predict the Wine Profit


NEAREST NEIGHBOUR 8

Grass Coverage
Lake Coverage Grade
87.50% 50.28% 84
93.11% 70.14% 92
66.69% 30.44% 75
81.61% 20.61% 74
75.84% 30.03% 76
75.22% 10.72% 69
86.64% 40.07% 78
89.54% 60.06% 90
77.87% 40.82% 77
89.39% 50.37% 87

The prediction will be made using five (5) nearest neighbours.

Given data point:

Grass Coverage 88.2%


Lake Coverage 64.9%

Question 1

Using uniform weights, predict the Grade

Question 2

Using weights inverse to the distance, predict the Grade


NEAREST NEIGHBOUR 9

Humidity
Sunshine Coverage
Length
37.50% 52.80% 21.7
33.11% 41.42% 25.9
26.69% 34.46% 34.8
31.61% 16.11% 17.7
35.84% 30.30% 24.9
25.22% 17.27% 24.5
36.64% 60.79% 37.3
29.54% 61.63% 23.2
37.87% 48.24% 29.4
39.39% 53.77% 30.1

The prediction will be made using five (5) nearest neighbours.

Given data point:

Humidity 34.7%
Sunshine Coverage 49.4%

Question 1

Using uniform weights, predict the Length

Question 2

Using weights inverse to the distance, predict the Length


NEAREST NEIGHBOUR 10

Distance WeightDelivery Time


107 9.7 2.17
103 9.6 2.59
71 8.9 1.48
116 7.1 1.77
159 10.9 2.33
53 6.6 2.45
167 11.3 3.73
95 11.6 2.32
178 10.5 2.94
194 12.6 3.98

The prediction will be made using five (5) nearest neighbours.

Given data point:

Distance 147
Weight 10.6

Question 1

Using uniform weights, predict the Delivery Time.

Question 2

Using weights inverse to the distance, predict the Delivery Time.

You might also like