scala – 为什么我不能显示Spark MultilayerPerceptronClassifie
发布时间:2020-12-16 19:12:54 所属栏目:安全 来源:网络整理
导读:我正在使用Spark的MultilayerPerceptronClassifier.这会在“预测”中生成“预测”列.当我尝试显示它时,我收到错误: SparkException: Failed to execute user defined function($anonfun$1: (vector) = double) ...Caused by: java.lang.IllegalArgumentExce
我正在使用Spark的MultilayerPerceptronClassifier.这会在“预测”中生成“预测”列.当我尝试显示它时,我收到错误:
SparkException: Failed to execute user defined function($anonfun$1: (vector) => double) ... Caused by: java.lang.IllegalArgumentException: requirement failed: A & B Dimension mismatch! 其他列,例如,矢量显示OK. |-- vector: vector (nullable = true) |-- prediction: double (nullable = true) 我的代码是: //racist is boolean,needs to be string: val train2 = train.withColumn("racist",'racist.cast("String")) val test2 = test.withColumn("racist",'racist.cast("String")) val indexer = new StringIndexer().setInputCol("racist").setOutputCol("indexracist") val word2Vec = new Word2Vec().setInputCol("lemma").setOutputCol("vector") //.setVectorSize(3).setMinCount(0) val layers = Array[Int](4,5,2) val mpc = new MultilayerPerceptronClassifier().setLayers(layers).setBlockSize(128).setSeed(1234L).setMaxIter(100).setFeaturesCol("vector").setLabelCol("indexracist") val pipeline = new Pipeline().setStages(Array(indexer,word2Vec,mpc)) val model = pipeline.fit(train2) val predictions = model.transform(test2) predictions.select("prediction").show() 编辑提出的类似问题的问题是 val layers = Array[Int](0,0) 这不是这种情况,也不是同样的错误. 再次编辑:列车和测试的第0部分以PARQUET格式here保存. 解决方法
添加.setVectorSize(3).setMinCount(0)和更改val layers = Array [Int](3,2)使其工作:
val word2Vec = new Word2Vec().setInputCol("lemma").setOutputCol("vector").setVectorSize(3).setMinCount(0) // specify layers for the neural network: // input layer of size 4 (features),two intermediate of size 5 and 4 // and output of size 3 (classes) val layers = Array[Int](3,2) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |