Here is a line plot generated from the following code:
JavaScript
x
34
34
1
test_error_rates = [0.10777777777777775,
2
0.09999999999999998,
3
0.07444444444444442,
4
0.07666666666666666,
5
0.07222222222222219,
6
0.06444444444444442,
7
0.06444444444444442,
8
0.06222222222222218,
9
0.06000000000000005,
10
0.06222222222222218,
11
0.06222222222222218,
12
0.06000000000000005,
13
0.06222222222222218,
14
0.06222222222222218,
15
0.06000000000000005,
16
0.05666666666666664,
17
0.05555555555555558,
18
0.05555555555555558,
19
0.053333333333333344,
20
0.053333333333333344,
21
0.054444444444444406,
22
0.05111111111111111,
23
0.054444444444444406,
24
0.054444444444444406,
25
0.05666666666666664,
26
0.05666666666666664,
27
0.05555555555555558,
28
0.05777777777777782,
29
0.05777777777777782]
30
31
plt.plot(range(1,30),test_error_rates)
32
plt.ylabel('ERROR RATE')
33
plt.xlabel('K Neighbor')
34
Now, I want to label (maybe add a small circle in red around that point) the minimum point that falls in between K = 20 and K = 25. How should I do this?
Advertisement
Answer
here you go:
JavaScript
1
39
39
1
test_error_rates = [0.10777777777777775,
2
0.09999999999999998,
3
0.07444444444444442,
4
0.07666666666666666,
5
0.07222222222222219,
6
0.06444444444444442,
7
0.06444444444444442,
8
0.06222222222222218,
9
0.06000000000000005,
10
0.06222222222222218,
11
0.06222222222222218,
12
0.06000000000000005,
13
0.06222222222222218,
14
0.06222222222222218,
15
0.06000000000000005,
16
0.05666666666666664,
17
0.05555555555555558,
18
0.05555555555555558,
19
0.053333333333333344,
20
0.053333333333333344,
21
0.054444444444444406,
22
0.05111111111111111,
23
0.054444444444444406,
24
0.054444444444444406,
25
0.05666666666666664,
26
0.05666666666666664,
27
0.05555555555555558,
28
0.05777777777777782,
29
0.05777777777777782]
30
31
min_x = np.argmin(test_error_rates) + 1
32
min_y = np.min(test_error_rates)
33
34
plt.plot(range(1,30),test_error_rates)
35
plt.scatter(min_x, min_y,c='r', label='minimum')
36
plt.legend()
37
plt.ylabel('ERROR RATE')
38
plt.xlabel('K Neighbor')
39