【发布时间】:2015-07-04 15:18:13
【问题描述】:
我正在尝试在 Python 中实现模糊 c 均值算法。我在 Matlab 中使用了内置函数来做同样的事情。我想知道 Python 中是否也有这样简单的方法。我试过了
http://peach.googlecode.com/hg/doc/build/html/tutorial/fuzzy-c-means.html
我已经试过了:
from numpy import *
import peach as p
x = array( [
[ 0., 0. ], [ 0., 1. ], [ 0., 2. ], [ 1., 0. ], [ 1., 1. ], [ 1., 2. ],
[ 2., 0. ], [ 2., 1. ], [ 2., 2. ], [ 5., 5. ], [ 5., 6. ], [ 5., 7. ],
[ 6., 5. ], [ 6., 6. ], [ 6., 7. ], [ 7., 5. ], [ 7., 6. ], [ 7., 7. ] ] )
mu = array( [
[ 0.7, 0.3 ], [ 0.7, 0.3 ], [ 0.7, 0.3 ], [ 0.7, 0.3 ], [ 0.7, 0.3 ],
[ 0.7, 0.3 ], [ 0.7, 0.3 ], [ 0.7, 0.3 ], [ 0.7, 0.3 ], [ 0.3, 0.7 ],
[ 0.3, 0.7 ], [ 0.3, 0.7 ], [ 0.3, 0.7 ], [ 0.3, 0.7 ], [ 0.3, 0.7 ],
[ 0.3, 0.7 ], [ 0.3, 0.7 ], [ 0.3, 0.7 ] ] )
m = 2.0
fcm = p.FuzzyCMeans(x, mu, m)
print "After 20 iterations, the algorithm converged to the centers:"
print fcm(emax=0)
print "The membership values for the examples are given below:"
print fcm.mu
但得到 * ImportError: No module named bitarray *
谁能帮忙?
【问题讨论】:
-
请发布您的代码。
-
您尝试安装了吗?
-
@Kishore 我已经编辑了我的帖子。请通过
-
@IgnacioVazquez-Abrams 是的,我尝试安装 bitarray-0.8.1,但似乎安装不正确..我使用的是 windows 8 32 位。
-
启动一个 python 控制台并检查这是否 -
from bitarray import bitarray有效。如果您收到importError,请检查 python dist-packages 目录是否存在该模块。