Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pyspark:kmeans的分类变量准备_Pyspark - Fatal编程技术网

pyspark:kmeans的分类变量准备

pyspark:kmeans的分类变量准备,pyspark,Pyspark,我知道Kmeans不是一个很好的选择,不能应用于分类数据,但spark 1.4中没有太多用于分类数据聚类的选项。 不管上述问题。我下面的代码有错误。 我从hive读取表,在管道中使用onehotencoder,然后将代码发送到Kmeans。 运行此代码时,我收到一个错误。 错误是否在馈送到Kmeans的数据类型中?doen是否需要numpay阵列数据?如果是,我如何将索引数据传输到numpy数组!?!? 感谢所有评论,感谢您的帮助 我得到的错误是: 回溯最近一次呼叫上次: 文件/usr/hdp/

我知道Kmeans不是一个很好的选择,不能应用于分类数据,但spark 1.4中没有太多用于分类数据聚类的选项。 不管上述问题。我下面的代码有错误。 我从hive读取表,在管道中使用onehotencoder,然后将代码发送到Kmeans。 运行此代码时,我收到一个错误。 错误是否在馈送到Kmeans的数据类型中?doen是否需要numpay阵列数据?如果是,我如何将索引数据传输到numpy数组!?!? 感谢所有评论,感谢您的帮助

我得到的错误是: 回溯最近一次呼叫上次: 文件/usr/hdp/2.3.2.0-2950/spark/python/lib/pyspark.zip/pyspark/daemon.py,第157行,在manager中 文件/usr/hdp/2.3.2.0-2950/spark/python/lib/pyspark.zip/pyspark/daemon.py, 第61行,输入 文件/usr/hdp/2.3.2.0-2950/spark/python/lib/pyspark.zip/pyspark/worker.py, 第136行,主 如果读取\u intinfile==specialLength.END\u的\u流:File/usr/hdp/2.3.2.0-2950/spark/python/lib/pyspark.zip/pyspark/serializers.py, 第544行,以read_int表示 升起EOFError EOFError文件,第1行 回溯最近一次呼叫上次:

我的代码:


我想更正并不能解决问题。
您可以使用XXX将密集向量转换为数组。toarray

我做了一个更改,使用data=index.selectfeatures.maplambda row:row.features.maplambda row:row.features代替了LabeledPoint Im,但我仍然得到了相同的错误。首先,LabeledPointrow.features不是对LabeledPoint的有效调用。
#aline will be passed in from another rdd
aline=["xxx","yyy"]

# get data from Hive table & select the column  & convert back to Rdd
rddRes2=hCtx.sql("select XXX, YYY from table1 where xxx <> ''")
rdd3=rddRes2.rdd

#fill the NA values with "none" 
Rdd4=rdd3.map(lambda line: [x if len(x) else 'none' for x in line])

# convert it back to Df
DataDF=Rdd4.toDF(aline)  

# Indexers encode strings with doubles
string_indexers=[
StringIndexer(inputCol=x,outputCol="idx_{0}".format(x))
for x in DataDF.columns if x not in '' ]

encoders=[
OneHotEncoder(inputCol="idx_{0}".format(x),outputCol="enc_{0}".format(x))
for x in DataDF.columns if x not in ''
]

# Assemble multiple columns into a single vector
assembler=VectorAssembler(
inputCols=["enc_{0}".format(x) for x in DataDF.columns if x not in ''],
outputCol="features")


pipeline= Pipeline(stages=string_indexers+encoders+[assembler])
model=pipeline.fit(DataDF)
indexed=model.transform(DataDF)


labeled_points=indexed.select("features").map(lambda row: LabeledPoint(row.features))

# Build the model (cluster the data)
clusters = KMeans.train(labeled_points, 3, maxIterations=10,runs=10, initializationMode="random")