Python 给定概率函数绘制贝叶斯决策边界的内置函数
python中是否有一个函数,如果我们向它输入一个函数,它会绘制bayes决策边界?我知道matlab中有一个函数,但我正在python中搜索一些函数。我知道实现这一点的一种方法是迭代这些点,但我正在搜索一个内置函数。Python 给定概率函数绘制贝叶斯决策边界的内置函数,python,matlab,numpy,matplotlib,scipy,Python,Matlab,Numpy,Matplotlib,Scipy,python中是否有一个函数,如果我们向它输入一个函数,它会绘制bayes决策边界?我知道matlab中有一个函数,但我正在python中搜索一些函数。我知道实现这一点的一种方法是迭代这些点,但我正在搜索一个内置函数。 我在轴上有两个变量样本点,我想绘制决策边界,以便对它们进行分类。与Chris在上述评论中的猜测不同,我假设你想根据高斯混合模型对点进行聚类,这是一种合理的方法,假设基础分布是高斯分布样本的线性组合。下面我展示了一个使用numpy创建样本数据集的示例,sklearn用于GM建模,并
我在轴上有两个变量样本点,我想绘制决策边界,以便对它们进行分类。与Chris在上述评论中的猜测不同,我假设你想根据高斯混合模型对点进行聚类,这是一种合理的方法,假设基础分布是高斯分布样本的线性组合。下面我展示了一个使用
numpy
创建样本数据集的示例,sklearn
用于GM建模,并使用pylab
显示结果
import numpy as np
from pylab import *
from sklearn import mixture
# Create some sample data
def G(mu, cov, pts):
return np.random.multivariate_normal(mu,cov,500)
# Three multivariate Gaussians with means and cov listed below
MU = [[5,3], [0,0], [-2,3]]
COV = [[[4,2],[0,1]], [[1,0],[0,1]], [[1,2],[2,1]]]
A = [G(mu,cov,500) for mu,cov in zip(MU,COV)]
PTS = np.concatenate(A) # Join them together
# Use a Gaussian Mixture model to fit
g = mixture.GMM(n_components=len(A))
g.fit(PTS)
# Returns an index list of which cluster they belong to
C = g.predict(PTS)
# Plot the original points
X,Y = map(array, zip(*PTS))
subplot(211)
scatter(X,Y)
# Plot the points and color according to the cluster
subplot(212)
color_mask = ['k','b','g']
for n in xrange(len(A)):
idx = (C==n)
scatter(X[idx],Y[idx],color=color_mask[n])
show()
有关分类方法的更多详细信息,请参见页面。以便我们可以找到您要查找的内容,等效的
matlab
函数是什么?我不记得函数的名称。但几年前我曾使用过它。还感谢您尝试使用以下matlab函数: