1

Here is a line plot generated from the following code:

test_error_rates = [0.10777777777777775,
 0.09999999999999998,
 0.07444444444444442,
 0.07666666666666666,
 0.07222222222222219,
 0.06444444444444442,
 0.06444444444444442,
 0.06222222222222218,
 0.06000000000000005,
 0.06222222222222218,
 0.06222222222222218,
 0.06000000000000005,
 0.06222222222222218,
 0.06222222222222218,
 0.06000000000000005,
 0.05666666666666664,
 0.05555555555555558,
 0.05555555555555558,
 0.053333333333333344,
 0.053333333333333344,
 0.054444444444444406,
 0.05111111111111111,
 0.054444444444444406,
 0.054444444444444406,
 0.05666666666666664,
 0.05666666666666664,
 0.05555555555555558,
 0.05777777777777782,
 0.05777777777777782]

plt.plot(range(1,30),test_error_rates)
plt.ylabel('ERROR RATE')
plt.xlabel('K Neighbor')

enter image description here

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?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • 1
    Does this answer your question? [How to automatically annotate maximum value in pyplot](https://stackoverflow.com/questions/43374920/how-to-automatically-annotate-maximum-value-in-pyplot) – Trenton McKinney Jul 31 '21 at 14:54
  • Does this answer your question? [Label python data points on plot](https://stackoverflow.com/q/22272081/7758804) – Trenton McKinney Jul 31 '21 at 14:57
  • Does this answer your question? [How to mark specific data points in matplotlib graph](https://stackoverflow.com/q/47211866/7758804) – Trenton McKinney Jul 31 '21 at 15:00
  • Does this answer your question? [How to plot a single point in matplotlib](https://stackoverflow.com/q/28504737/7758804) – Trenton McKinney Jul 31 '21 at 15:23

1 Answers1

1

here you go:

test_error_rates = [0.10777777777777775,
 0.09999999999999998,
 0.07444444444444442,
 0.07666666666666666,
 0.07222222222222219,
 0.06444444444444442,
 0.06444444444444442,
 0.06222222222222218,
 0.06000000000000005,
 0.06222222222222218,
 0.06222222222222218,
 0.06000000000000005,
 0.06222222222222218,
 0.06222222222222218,
 0.06000000000000005,
 0.05666666666666664,
 0.05555555555555558,
 0.05555555555555558,
 0.053333333333333344,
 0.053333333333333344,
 0.054444444444444406,
 0.05111111111111111,
 0.054444444444444406,
 0.054444444444444406,
 0.05666666666666664,
 0.05666666666666664,
 0.05555555555555558,
 0.05777777777777782,
 0.05777777777777782]

min_x = np.argmin(test_error_rates) + 1
min_y = np.min(test_error_rates)

plt.plot(range(1,30),test_error_rates)
plt.scatter(min_x, min_y,c='r', label='minimum')
plt.legend()
plt.ylabel('ERROR RATE')
plt.xlabel('K Neighbor')

enter image description here

sehan2
  • 1,700
  • 1
  • 10
  • 23