2016-05-04 78 views
0

我試圖按照here討論的例子,我只是將代碼複製到Zeppelin段落中。AttributeError:'DataFrame'對象在VectorAssembler上沒有屬性'get'Spark ML

%pyspark 
import pandas as pd 
from pyspark.sql import SQLContext 
from pyspark.ml.feature import VectorAssembler 
from pyspark.mllib.linalg import Vectors 

dataset = sqlContext.createDataFrame(
[(0, 18, 1.0, Vectors.dense([0.0, 10.0, 0.5]), 1.0)], 
["id", "hour", "mobile", "userFeatures", "clicked"]) 
print(type(dataset)) 
assembler = VectorAssembler(
inputCols=["hour", "mobile", "userFeatures"], 
outputCol="features") 
output = assembler.transform(dataset) 

不過,我得到這個錯誤:

Traceback (most recent call last): 
    File "/tmp/zeppelin_pyspark.py", line 164, in <module> 
    intp.setStatementsFinished(output.get(), False) 
    File "/home/zeppelin/zeppelin-0.5.5-incubating-bin-all/interpreter/spark/pyspark/pyspark.zip/pyspark/sql/dataframe.py", line 749, in __getattr__ "'%s' object has no attribute '%s'" % (self.__class__.__name__, name)) 
AttributeError: 'DataFrame' object has no attribute 'get' 

有什麼建議?

回答

0

你可以嘗試改變

from pyspark.mllib.linalg import Vectors 

from pyspark.ml.linalg import Vectors