Question: For python: Construct a 2-dimensional data set (i.e. the data points and their labels), with the property that the data set is linearly separable and
For python: Construct a 2-dimensional data set (i.e. the data points and their labels), with the property that the data set is linearly separable
and then write the code to Plot the data points. This will show that your data set is linearly separable.
The code should be similar to this code below that plots the iris data set & shows it is linearly separable
### Reading-in the Iris data
s = os.path.join('https://archive.ics.uci.edu', 'ml', 'machine-learning-databases', 'iris','iris.data') s = s.replace("\\","/"); print('URL:', s) df = pd.read_csv(s,header=None,encoding='utf-8')
# select setosa and versicolor y = df.iloc[0:100, 4].values y = np.where(y == 'Iris-setosa', -1, 1)
# extract sepal length and petal length X = df.iloc[:100, [0, 2]].values
# plot data plt.scatter(X[:50, 0], X[:50, 1], color='red', marker='o', label='setosa') plt.scatter(X[50:100, 0], X[50:100, 1], color='blue', marker='x', label='versicolor')
plt.xlabel('sepal length [cm]') plt.ylabel('petal length [cm]') plt.legend(loc='upper left')
# plt.savefig('images/02_06.png', dpi=300) plt.show()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
