私はWikipedia XMLダンプでLDAを実行しようとしています。生のテキストのRDDを取得した後、私はデータフレームを作成し、それをTokenizer、StopWordsおよびCountVectorizerのパイプラインを通して変換しています。私はCountVectorizerのベクトルのRDDをMLLibのOnlineLDAに渡すつもりです。 は、ここに私のコードです:私はので、ラインのJavaRDD <Row>をJavaRDDに変換する<Vector>
Object[] arr = row.getList(0).toArray();
Caused by: java.lang.ClassCastException: org.apache.spark.mllib.linalg.SparseVector cannot be cast to scala.collection.Seq
at org.apache.spark.sql.Row$class.getSeq(Row.scala:278)
at org.apache.spark.sql.catalyst.expressions.GenericRow.getSeq(rows.scala:192)
at org.apache.spark.sql.Row$class.getList(Row.scala:286)
at org.apache.spark.sql.catalyst.expressions.GenericRow.getList(rows.scala:192)
at xmlProcess.ParseXML$2.call(ParseXML.java:142)
at xmlProcess.ParseXML$2.call(ParseXML.java:1)
クラスキャスト例外を取得しています
// Configure an ML pipeline
RegexTokenizer tokenizer = new RegexTokenizer()
.setInputCol("text")
.setOutputCol("words");
StopWordsRemover remover = new StopWordsRemover()
.setInputCol("words")
.setOutputCol("filtered");
CountVectorizer cv = new CountVectorizer()
.setVocabSize(vocabSize)
.setInputCol("filtered")
.setOutputCol("features");
Pipeline pipeline = new Pipeline()
.setStages(new PipelineStage[] {tokenizer, remover, cv});
// Fit the pipeline to train documents.
PipelineModel model = pipeline.fit(fileDF);
JavaRDD<Vector> countVectors = model.transform(fileDF)
.select("features").toJavaRDD()
.map(new Function<Row, Vector>() {
public Vector call(Row row) throws Exception {
Object[] arr = row.getList(0).toArray();
double[] features = new double[arr.length];
int i = 0;
for(Object obj : arr){
features[i++] = (double)obj;
}
return Vectors.dense(features);
}
});
私はこのhereを行うにはScalaの構文が見つかりましたが、それを行うための任意の例を見つけることができませんでしたJavaで。私はrow.getAs[Vector](0)
を試しましたが、これはScalaの構文です。どのようにJavaでそれを行うには?