Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requirement failed in LogisticRegressionModel.predict

I want test my model (SparkMLlib) in JavaApplication

 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);

When run, i have this error:

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)
like image 343
SirGustave Avatar asked Apr 16 '26 12:04

SirGustave


1 Answers

Since the only requirement checked in predictPoint is an input vector size it most likely doesn't match a shape of the data used to train model.

An easy way to check if this is the case is to check model.numFeatures and compare it with a size of the input vector.

like image 84
3 revszero323 Avatar answered Apr 19 '26 02:04

3 revszero323



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!