gpt4 book ai didi

java - Spark 告诉我功能列是错误的

转载 作者:行者123 更新时间:2023-12-01 14:31:52 25 4
gpt4 key购买 nike

可能导致此错误的原因。我有点迷路了。我发现的一切都对我没有帮助。

堆栈跟踪:

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Column features must be of type struct<type:tinyint,size:int,indices:array<int>,values:array<double>> but was actually struct<type:tinyint,size:int,indices:array<int>,values:array<double>>.
at scala.Predef$.require(Predef.scala:224)
at org.apache.spark.ml.util.SchemaUtils$.checkColumnType(SchemaUtils.scala:43)
at org.apache.spark.ml.PredictorParams$class.validateAndTransformSchema(Predictor.scala:51)
at org.apache.spark.ml.classification.Classifier.org$apache$spark$ml$classification$ClassifierParams$$super$validateAndTransformSchema(Classifier.scala:58)
at org.apache.spark.ml.classification.ClassifierParams$class.validateAndTransformSchema(Classifier.scala:42)
at org.apache.spark.ml.classification.ProbabilisticClassifier.org$apache$spark$ml$classification$ProbabilisticClassifierParams$$super$validateAndTransformSchema(ProbabilisticClassifier.scala:53)
at org.apache.spark.ml.classification.ProbabilisticClassifierParams$class.validateAndTransformSchema(ProbabilisticClassifier.scala:37)
at org.apache.spark.ml.classification.ProbabilisticClassifier.validateAndTransformSchema(ProbabilisticClassifier.scala:53)
at org.apache.spark.ml.Predictor.transformSchema(Predictor.scala:144)
at org.apache.spark.ml.PipelineStage.transformSchema(Pipeline.scala:74)
at org.apache.spark.ml.Predictor.fit(Predictor.scala:100)
at classifier.Clasafie.trainModel_MPC(Clasafie.java:46)
at classifier.Clasafie.MPC_Classifier(Clasafie.java:75)
at classifier.Clasafie.main(Clasafie.java:30)

代码部分:

public static MultilayerPerceptronClassificationModel trainModel_MPC(SparkSession session,JavaRDD<LabeledPoint> data)
{

int[] layers = {784,800};
MultilayerPerceptronClassifier model = new MultilayerPerceptronClassifier().setLayers(layers)
.setSeed((long) 42).setBlockSize(128).setMaxIter(1000);

Dataset<Row> dataset = session.createDataFrame(data.rdd(), LabeledPoint.class);

return model.fit(dataset);

}

最佳答案

我认为问题在于使用正确包中的 LabelPoint 类。

检查完整包并使用来自 ml 包而不是来自 mllib 的 on。

我想,你正在使用 -

org.apache.spark.mllib.regression.LabeledPoint

请使用(spark v2.0.0中引入)-

org.apache.spark.ml.feature.LabeledPoint

关于java - Spark 告诉我功能列是错误的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62476206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com