2016-06-23 38 views
0
from weka.clusterers import Clusterer 
import weka.core.converters as converters 

data = converters.load_any_file("/home/ubuntu/test.csv") 
data.class_is_last() 

clusterer = Clusterer(classname="weka.clusterers.SimpleKMeans", options=["-N", "3"]) 
clusterer.build_clusterer(data) 

print(clusterer) 

# cluster the data 
for inst in data: 
    cl = clusterer.cluster_instance(inst) # 0-based cluster index 
    dist = clusterer.distribution_for_instance(inst) # cluster membership distribution 

    print("cluster=" + str(cl) + ", distribution=" + str(dist)) 

我用上面的代碼做K均值custering我不能夠執行程序K均值聚類使用秧雞蟒蛇

的錯誤,我得到

Traceback (most recent call last): 
    File "clus.py", line 6, in <module> 
    data = converters.load_any_file("/home/ubuntu/hello.csv") 
    File "/usr/local/lib/python2.7/dist-packages/weka/core/converters.py", line 255, in load_any_file 
    loader = loader_for_file(filename) 
    File "/usr/local/lib/python2.7/dist-packages/weka/core/converters.py", line 239, in loader_for_file 
    "(Ljava/lang/String;)Lweka/core/converters/AbstractFileLoader;", filename) 
    File "/usr/local/lib/python2.7/dist-packages/javabridge/jutil.py", line 932, in static_call 
    fn = make_static_call(class_name, method_name, sig) 
    File "/usr/local/lib/python2.7/dist-packages/javabridge/jutil.py", line 903, in make_static_call 
    klass = env.find_class(class_name) 
AttributeError: 'NoneType' object has no attribute 'find_class' 

我不以下不知道爲什麼我會得到這些錯誤。有人可以幫我弄這個嗎?

回答

1

正如你必須導入並啓動Java虛擬機的python-weka-wrapper API描述:

import weka.core.jvm as jvm 
jvm.start() 

應該解決您的問題。