简体   繁体   中英

Plotting a graph for datasets to develop SVM on Python

I have written the below code that generates two different datasets. I want to plot the graphs X and y but I couldn't find how to draw it.

import numpy as np
import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split
from sklearn.svm import SVC

std = [[0.5, 0], [0, 0.5]]
X1 = np.vstack((
np.random.multivariate_normal([2, -2], std, size=200),
np.random.multivariate_normal([-2, 2], std, size=200)
))
y1 = np.zeros(X1.shape[0])

X2 = np.vstack((
np.random.multivariate_normal([2, 2], std, size=200),
np.random.multivariate_normal([-2, -2], std, size=200)
))
y2 = np.ones(X2.shape[0])

X = np.vstack((X1, X2))
y = np.hstack((y1, y2))

I tried;

plt.scatter(X, y) 
plt.show

But as you can guess they have given me errors. Any help would be appreciated.

The following two lines will create a scatter plot that visualizes your data

plt.scatter(X[:, 0], X[:,1], c=y)
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM