2
如果我们输入一个函数给python绘制贝叶斯决策边界,是否有函数?我知道有一个在matlab中,但我在python中寻找一些函数。我知道实现这一点的一种方法是迭代点,但我正在寻找一个内置函数。 我在轴上有双变量采样点,我想绘制决策边界以对它们进行分类。建立在给定概率函数的情况下绘制贝氏决策边界的函数
如果我们输入一个函数给python绘制贝叶斯决策边界,是否有函数?我知道有一个在matlab中,但我在python中寻找一些函数。我知道实现这一点的一种方法是迭代点,但我正在寻找一个内置函数。 我在轴上有双变量采样点,我想绘制决策边界以对它们进行分类。建立在给定概率函数的情况下绘制贝氏决策边界的函数
在上面的评论中,假设您想要根据高斯混合模型对点进行聚类 - 假设底层分布是高斯分布样本的线性组合,则是一个合理的方法。下面我用一个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()
有关分类方法的更详细信息,请参阅sklearn.mixture example页。
为了能找到你要找的东西,什么是等效的'matlab'函数? – Hooked 2012-02-28 14:33:10
我不记得功能的名称..但我过去几年前使用它。也感谢您试用 – 2012-02-28 14:37:51
这里是matlab函数:http://www.mathworks.co.uk/help/toolbox/stats/bq_679x-24.html – 2012-02-28 18:19:52