Here's the code for plotting dataset values ,initially just to visualize our dataset points on the graph:
- it contains two features :[Age,EstimatedSalary]
- [Purchased] is out target class,containing 0 & 1 as two labels
label1=dataset[dataset["Purchased"]==0]
label2=dataset[dataset["Purchased"]==1]
len_id_0=np.where(dataset.Purchased == 0) #indices for label 0
len_id_1=np.where(dataset.Purchased == 1)
x_1_0=label1["Age"] # 1st feature having label as 0
x_2_0=label1["EstimatedSalary"] # 2nd feature having label as 0
x_1_1=label2["Age"] # 1st features having label as 1
x_2_1=label2["EstimatedSalary"] # 2nd features having label as 1
plt.scatter(x_1_0,x_2_0)
plt.scatter(x_1_1,x_2_1)
plt.title('(Train set)')
plt.xlabel('Age')
plt.ylabel('Estimated Salary')
plt.show()
Plot Containg Descision Boundary as well,
from matplotlib.colors import ListedColormap
X_set, y_set = X_train, y_train
X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01),
np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01))
plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),
alpha = 0.75, cmap = ListedColormap(('white', 'yellow')))
plt.xlim(X1.min(), X1.max())
plt.ylim(X2.min(), X2.max())
for i, j in enumerate(np.unique(y_set)):
plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],
c = ListedColormap(('black', 'orange'))(i), label = j)
plt.title('SVM (Training set)')
plt.xlabel('Age')
plt.ylabel('Estimated Salary')
plt.legend()
plt.show()
