I want to draw a graph using mglearn, but there are three arguments in discrete_scatter in the following code. What role does it play? Is discrete_scatter a method in the first place?

I also don't know the role of legend method loc = 4.

X, y = mglearn.datasets.make_forge ()
mglearn.discrete_scatter (X [:, 0], X [:, 1], y)
plt.legend (["Class 0", "Class 1"], loc = 4)
plt.xlabel ("First feature")
plt.ylabel ("Second feature")
print ("X.shape: {}". format (X.shape))
# X.shape: (26, 2)
  • Answer # 1

    discrete_scatter ()is a utility formatplotlib.pyplot.scatter ()and specifies alabelfor each data in the third argument This is a method that draws a scatter plot (callspyplot.scatter ()) by changing the Marker type and color according to the label.


    discrete_scatter has three arguments, what role do you play?

    First argument: X value of each data drawn in scatter chart
    Second argument: Y value of each data drawn in the scatter chart
    Third argument: LABEL of each data to be drawn in the scatter plot


    I also don't know the role of legend method loc = 4.

    legend ()is a method that displays a legend, whilelocspecifies itslocation.

    I think it's better to look at the documentation for details, butloc = 4specifies that the legend should be displayed in thelower right.

  • Answer # 2

    legenddisplays a legend.locspecifies the display position of the legend.loc = 4meanslower right.
    See matplotlib.pyplot.legend for details.


    mglearnthe introduction_to_ml_with_python/mglearn/library provided for machine learning starting with Python?
    It seems that up to the second argument is the feature value (x, y axis), and the third argument is the class classification value (0 or 1).

    Introduction to machine learning_Chapter 2 halfway