値のタプル (String、SparseVector)を持つRDDがあり、 RDDを使用してDataFrameを作成したいと考えています。ほとんどの ml アルゴリズムのライブラリで必要なスキーマである (label:string, features:vector) DataFrameを取得します。HashingTF ml Library は、 DataFrameの features 列が指定されたときにベクトルを出力するため、実行できることはわかってい ます。
temp_df = sqlContext.createDataFrame(temp_rdd, StructType([
StructField("label", DoubleType(), False),
StructField("tokens", ArrayType(StringType()), False)
]))
#assumming there is an RDD (double,array(strings))
hashingTF = HashingTF(numFeatures=COMBINATIONS, inputCol="tokens", outputCol="features")
ndf = hashingTF.transform(temp_df)
ndf.printSchema()
#outputs
#root
#|-- label: double (nullable = false)
#|-- tokens: array (nullable = false)
#| |-- element: string (containsNull = true)
#|-- features: vector (nullable = true)
だから私の質問は、どうにかして (String, SparseVector) のRDDを (String, vector) のDataFrameに変換できるかということです。私はいつものように試しましたが、私が持っているニーズに合ったDataTypesqlContext.createDataFrame
はありません。
df = sqlContext.createDataFrame(rdd,StructType([
StructField("label" , StringType(),True),
StructField("features" , ?Type(),True)
]))