如何解决如何计算从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()
解决方法
我实际上使用“预测”方法来解决它:
selected
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。