2015-04-06 70 views
0

我試圖訪問的pyspark 1.2.0版的Spark的getVectors()方法訪問getVectors方法,但pyspark州 -PySpark不具有Word2VecModel

input.cache() 
word2vec = Word2Vec() 
model = word2vec.fit(input) 
vector = model.getVectors() 

AttributeError: 'Word2VecModel' object has no attribute 'getVectors' 

所以我必須只訪問此使用Scala的方式/ Java或有我能做的事情。

+0

同樣的問題在這裏。 – 2016-08-26 22:50:41

回答

0

我想在星火創建一個玩具文件運行一個可再現的代碼現在1.2

# cat data.txt 
crazy crazy fox jumped 
crazy fox jumped 
fox is fast 
fox is smart 
dog is smart 

>> lines = sc.textFile('data.txt', 1); 
>> lines.collect() 
[ 
u'crazy crazy fox jumped', 
u'crazy fox jumped', 
u'fox is fast', 
u'fox is smart', 
u'dog is smart' 
] 

from pyspark.mllib.feature import Word2Vec  
model = Word2Vec().fit(lines) 

,如果我跑dir(model)輸出

['__class__', 
'__del__', 
'__delattr__', 
'__dict__', 
'__doc__', 
'__format__', 
'__getattribute__', 
'__hash__', 
'__init__', 
'__module__', 
'__new__', 
'__reduce__', 
'__reduce_ex__', 
'__repr__', 
'__setattr__', 
'__sizeof__', 
'__str__', 
'__subclasshook__', 
'__weakref__', 
'_java_model', 
'_sc', 
'call', 
'findSynonyms', 
'transform'] 

其中最後3的成員方法和getvectors()不是這個的一部分。