LogisticRegressionModel

LogisticRegressionModel

我想在Java应用程序

 LogisticRegressionModel sameModel = LogisticRegressionModel.load(sc,"/home/storm/Desktotp/LogisticRegressionModel");
        Vector meu = Vectors.dense(1.0, 26.0, 0.4872, 2.0, 3.0, 1.0, 0.4925, 0.6182, 0.2762, 0.5468, 0.12, 9.0, 1.0, 2.0, 0.12, 1.0, 2.0, 3.0, 3.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0, 1.0, 1.0, 2.0, 3.0, 0.4507, 0.0, 132.0, 2.0, 1.0, 1.0, 3.0, 2.0, 2.0, 2.0, 141.0, 3.0, 2.0, 3.0, 3.0, 1.0, 3.0, 1.0, 1.0, 2.0, 1.0, 2.0, 3.0, 2.0, 2.0, 3.0, 1.0, 1.0, 2.0, 3.0, 3.0, 3.0, 1.0, 3.0, 2.0, 1.0, 3.0, 3.0);
        Double prediction = sameModel.predict(meu);
中测试我的模型(SparkMLlib)
运行时,出现以下错误:
Exception in thread "main" java.lang.IllegalArgumentException: requirement failed
    at scala.Predef$.require(Predef.scala:221)
    at org.apache.spark.mllib.classification.LogisticRegressionModel.predictPoint(LogisticRegression.scala:117)
    at org.apache.spark.mllib.regression.GeneralizedLinearModel.predict(GeneralizedLinearAlgorithm.scala:84)

最佳答案

由于在predictPoint中检查的唯一要求是输入向量大小,因此很可能与用于训练模型的数据形状不匹配。

一种简单的检查方法是检查model.numFeatures并将其与输入向量的size进行比较。

08-20 04:08