如何计算从svm.SVC获得的轮廓内的点?

问题描述

我从二元高斯生成了一个数据集来模拟信号和背景。然后,我尝试将svm.SVC与内核“ rbf”分开使用。现在,我想计算接收区域内有多少背景点,区域内有多少信号点等,以便研究分离方法的效率。

我不得不说我从一个在线示例中获得了部分代码,因为这是我第一次进行此类分析。因此我不确定我是否真的了解轮廓线是如何创建的,因此无法处理轮廓线,也无法分析轮廓线相对于点的位置。

谢谢

mu_vec1 = np.array([0,0])
cov_mat1 = np.array([[0.3**2,0.5*0.3*0.3],[0.5*0.3*0.3,0.3**2]])
x1_samples = np.random.multivariate_normal(mu_vec1,cov_mat1,1000)
#mu_vec1 = mu_vec1.reshape(1,2).T

mu_vec2 = np.array([2,1])
cov_mat2 = np.array([[1,0.4],[0.4,1]])
x2_samples = np.random.multivariate_normal(mu_vec2,cov_mat2,1000)
#mu_vec2 = mu_vec2.reshape(1,2).T

X = np.concatenate((x1_samples,x2_samples),axis = 0)
Y = np.array([0]*1000 + [1]*1000)

plt.scatter(x1_samples[:,0],x1_samples[:,1],label='Signal')
plt.scatter(x2_samples[:,x2_samples[:,label='Background')

C = 1.0  # SVM regularization parameter
clf = svm.SVC(kernel = 'rbf',C=C,probability = True )
clf.fit(X,Y)

h = .02  # step size in the mesh
# create a mesh to plot in
x_min,x_max = X[:,0].min() - 1,X[:,0].max() + 1
y_min,y_max = X[:,1].min() - 1,1].max() + 1
xx,yy = np.meshgrid(np.arange(x_min,x_max,h),np.arange(y_min,y_max,h))

print(clf.score(X,Y))

# Plot the decision boundary. For that,we will assign a color to each
# point in the mesh [x_min,m_max]x[y_min,y_max].
Z = clf.predict(np.c_[xx.ravel(),yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)

plt.contour(xx,yy,Z,cmap=plt.cm.Paired)

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)