Skip to main content
2 of 4
Corrected a spelling error in 2nd to the last tine of code from "idx_1" to "idx_0". Also added labels

Let's assume that the name of your dependent variable column is "target", and you have stored the data in "dataset" variable. You can segregate the dataset based on value of target in following way:

import numpy as np    
idx_1 = np.where(dataset.target == 1)
idx_0 = np.where(dataset.target == 0)

The above code with return indices of dataset with target values 0 and 1.

Now, to display the data, use:

ax1.scatter(dataset.iloc[idx_1].x, dataset.iloc[idx_1].y, s=10, c='b', marker="o", label='first')
ax1.scatter(dataset.iloc[idx_0].x, dataset.iloc[idx_0].y, s=10, c='r', marker="o", label='second')

plt.ylabel('y') plt.xlabel('x') plt.show()