What does mglearn.discrete_scatter(X_train[:, 0], X_train[:, 1], y_train) mean?

Asked 2 years ago, Updated 2 years ago, 30 views


of the following mglearn.discrete_scatter(X_train[:,0],X_train[:,1],y_train) What does X_train[:,0],X_train[:,1] mean?
When I typed this code, the dots appeared on the graph.

 from sklearn.neural_network import MLPCclassifier
from sklearn.datasets import make_moons

X,y=make_moons(n_samples=100, noise=0.25, random_state=3)

X_train, X_test, y_train, y_test=train_test_split(X,y,stratify=y,
                                                random_state=42)

mlp=MLPCclassifier(solver='lbfgs', random_state=0).fit(X_train,y_train)
mglearn.plots.plot_2d_separator (mlp, X_train, fill=True, alpha=.3)
mglearn.discrete_scatter(X_train[:,0], X_train[:,1], y_train)
plt.xlabel ("Feature 0")
plt.ylabel("Feature1")

See: Machine Learning Starting with Python

python

2022-09-30 19:45

1 Answers

NumPy slice for array.

Array has the ability to crop elements of indexes above a and below b by writing [a:b], while [:] is designated for all elements.

In this case, I am using it for multi-dimensional array.For example, [:,0] specifies that the first dimension is all elements, the second dimension is only the 0th element, that is, only the beginning of all elements.

#Python 3.6.0, NumPy 1.13.1
>>import numpy as np
>> sample=np.array ([1, 2, 3], [4, 5, 6], [7, 8, 9])
>> sample [0:2]
array([1,2,3],
       [4, 5, 6]])
>>> sample [:, 0]
array([1,4,7])
>>>sample [:,1]
array([2,5,8])
>>

Reference


2022-09-30 19:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.